On Mon, Apr 19, 2010 at 9:23 AM, Alan Gauld <alan.ga...@btinternet.com>wrote:

>
> "C M Caine" <cmca...@googlemail.com> wrote
>
>> That's the first I've read of iterating through dictionaries, I'd
>>
>> assumed it was impossible because they're unordered.
>>
>
> Iteration doesn't require order, only to get each item once.
> Even in very old Python versions you could iterate a dictionary via the
> keys() method. More recently you can do it directly - although the effect is
> the same. There is no guarantee of order only that you process every item
> once.


And of course if you want to get the items sorted you can iterate over
sorted(mydict.keys()).

-Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to