[Tutor] single key ordered sequence

Kent Johnson kent37 at tds.net
Thu Jan 15 23:15:12 CET 2009


On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley <jervisau at gmail.com> wrote:
> how about this:
> items = [(1,'a'),(1,'b'),(2,'a'),(3,'a'),
>             (3,'b'),(4,'a'),(5,'a'),(5,'b'),(5,'c')]
> mydict = dict(items)
> items = [item for item in mydict.iteritems()]

That only coincidentally preserves order; the order of items in a
dictionary is, for practical purposes, unpredictable.

BTW [item for item in mydict.iteritems()] can be written as just mydict.items().

Kent


More information about the Tutor mailing list