re: for in dict (user expectation poll)
On Mon, 5 Feb 2001, Greg Wilson wrote: Based on my very-informal survey, if: for i in someList: works, then many people will assume that: for i in someDict: will also work, and yield values.
Ka-Ping Yee: ...the latter is ambiguous (keys or values?)...
Greg Wilson
The latter is exactly as ambiguous as the former... I think this is a case where your (intimate) familiarity with the way Python works now is preventing you from getting into newbie headspace...
Ka-Ping Yee: No, i don't think so. It seems quite possible to argue from first principles that if you ask to iterate over things "in" a sequence, you clearly want the items in the sequence, not their integer indices.
Greg Wilson: Well, arguing from first principles, Aristotle was able to demonstrate that heavy objects fall faster than light ones :-). I'm basing my claim on the kind of errors students in my course make. Even after being shown half-a-dozen examples of Python for loops, many of them write: for i in someSequence: print someSequence[i] in their first exercise. Thanks, Greg
participants (4)
-
Greg Wilson
-
Ka-Ping Yee
-
Skip Montanaro
-
Thomas Wouters