[Tutor] single key ordered sequence

Jervis Whitley jervisau at gmail.com
Fri Jan 16 00:52:52 CET 2009


On Fri, Jan 16, 2009 at 10:39 AM, bob gailer <bgailer at gmail.com> wrote:

> Jervis Whitley wrote:
>
>>
>>
>> On Fri, Jan 16, 2009 at 9:15 AM, Kent Johnson <kent37 at tds.net <mailto:
>> kent37 at tds.net>> wrote:
>>
>>    On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley
>>    <jervisau at gmail.com <mailto: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
>>
>> I realise that what you have said is true, however can you show me a case
>> where
>> > items = dict(items).items()
>>
>> will not preserve order? Thanks.
>>
>>
> On my computer:
>
> >>> dict((('z', 1), ('y', 2))).items()
> [('y', 2), ('z', 1)]
>
> --
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
>
Same on mine, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090116/4139e943/attachment.htm>


More information about the Tutor mailing list