[Tutor] List index usage: is there a more pythonesque way?

Wayne Werner waynejwerner at gmail.com
Mon Apr 19 16:58:24 CEST 2010


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

>
> "C M Caine" <cmcaine at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100419/9c1a55c0/attachment.html>


More information about the Tutor mailing list