[Tutor] Enumerate vs DictReader object manipulation:

Alex Kleider akleider at sonic.net
Wed Feb 3 21:47:05 EST 2016


On 2016-02-03 13:24, Ben Finney wrote:


> You have discovered the difference between an iterable (an object you
> can iterate over with ‘for’), versus a sequence (an object whose items
> remain in place and can be iterated many times).
> 
> Every sequence is an iterable, but not vice versa.
> 
> File objects are iterables, but not sequences. Each time you ask for 
> the
> next item, you can't ask the file object for that item again; it is
> “consumed” by the act of iteration.

How does a dict fit into this scheme?
Is it a sequence?  It is an iterable (in that for key in d: works 
although not in a predictable manner and for this reason I tend NOT to 
think of it as a sequence.)


More information about the Tutor mailing list