an ingrate newbie complains

Christopher A. Craig list-python at ccraig.org
Wed Feb 4 13:32:06 EST 2004


"Elaine Jackson" <elainejackson7355 at home.com> writes:

> 1) I find the following behavior puzzling and disappointing:
> 
> >>> X=[(1,1),(2,4),(3,9),(4,16),(5,25)]
> >>> Y=dict(X)
> >>> Z=list(Y)
> >>> Z==X
> False
> >>> Z==Y.keys()
> True

the list() constructor treats its argument as an iterator.  Because
the overwhelmingly most common use case for an iterator on a dict is
to iterate over the keys, this creates a list of keys when given a
dict.


-- 
Christopher A. Craig <list-python at ccraig.org>
Love does no wrong to a neighbor; therefore love is
the fulfillment of the law - Romans 13:10





More information about the Python-list mailing list