an ingrate newbie complains

James Henderson james at logicalprogression.net
Wed Feb 4 13:42:51 EST 2004


On Wednesday 04 February 2004 6:13 pm, Gerrit wrote:
> Batista, Facundo wrote:
> > Elaine Jackson wrote:
> >
> > #- 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
> >
> > >>> Y
> >
> > {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
> >
> > >>> Z
> >
> > [1, 2, 3, 4, 5]
> >
> > I should expect that Z is not equal to Y.
>
> Well, the complain here is dat list(D) == D.keys(), not D.values().
> I share that complain.

The result of constructing a list from a dictionary - or any other type - 
depends entirely on what its default iterator is.  If you want list(D) to 
return D.values() then you'll also have to be happy to loop through values 
when you write "for o in D".  Personally I'm happy with keys being what you 
loop through.  Items would be my second choice (like in C++) with values a 
distant third.

James
-- 
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/





More information about the Python-list mailing list