[docs] Python Tutorial,Release 3.6.0 / glitch

M. E. Holzé m.holze at kabelmail.de
Mon Feb 27 09:50:20 EST 2017


Hugh,


when first defined as dict at page 35, assuming that it is not an
independant example, the content is:

>>> dict(sape=4139, guido=4127, jack=4098)
{'sape': 4139, 'jack': 4098, 'guido': 4127}

so I'd guess the result at page 49 wouldn't be correct neither, when
keeping the order as you describe.

So I conclude the example is meant to be independant. (Or I missed where
'sape' was dropped and 'Sjoerd' was added and the dict rearranged, and
the first char of the name set to caps...)

Here at page 49 we have a new table:

>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}

You point out, that dict keeps the insertion order. Fine, stack reading
from left to right in input order, that is  FIFO, delivers

Sjoerd ==> 4127
Jack ==> 4098
Dcab ==> 7678

agreed. ;-)

LIFO (stack order) would yield:

Dcab ==> 7678
Jack ==> 4098
Sjoerd ==> 4127

o.k., that's what I'm used to, working with FORTH. And the way 3.5 does
work at least on my system.

But how does Jack come first?  Combined number of characters and
numerical value of telephon-number?

Jack ==> 4098
Dcab ==> 7678
Sjoerd ==> 4127

Sorry, 

wonder how to work with an unpredictable order...


The Forth be with you




On 27.02.2017 14:09, INADA Naoki wrote:
> dict iteration order is not defined.  So both are correct.
>
> (internal)
> >From CPython 3.6, dict keeps insertion order. So output is stable and
> it should be:
>
> Sjoerd ==> 4127
> Jack ==> 4098
> Dcab ==> 7678
>
> But this is CPython implementation detail.  When other Python
> implemantation (e.g. Micropython)
> catch Python 3.6 up, the order may be different.
>
> On Mon, Feb 27, 2017 at 7:03 AM, M. E. Holzé <m.holze at kabelmail.de> wrote:
>> Hello,
>>
>>
>> just a glitch I guess,
>>
>>
>> page 49, example :
>>
>>
>>>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
>>>>> for name, phone in table.items():
>> ....
>> print('{0:10} ==> {1:10d}'.format(name, phone))
>> ....
>> Jack ==> 4098
>> Dcab ==> 7678
>> Sjoerd ==> 4127
>>
>> should read:
>>
>> Dcab ==> 7678
>>
>> Jack ==> 4098
>>
>> Sjoerd ==> 4127
>>
>>
>> shouldn't it ?
>>
>> (Youvn't used  FORTH  swap   before to manipulate the stack, have you?)
>>
>>
>>
>> jm2¢
>>
>>
>> Matthias E. Holzé
>>
>>
>>
>> _______________________________________________
>> docs mailing list
>> docs at python.org
>> https://mail.python.org/mailman/listinfo/docs
> .
>




More information about the docs mailing list