[Python-porting] Control of hash randomization

Aaron Meurer asmeurer at gmail.com
Sun May 27 23:40:27 CEST 2012


On Sun, May 27, 2012 at 3:03 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Aaron Meurer <asmeurer at ...> writes:
>>
>> It doesn't help that quite a few Python programmers don't understand
>> just what is and is not guaranteed by hash dependent objects.  For
>> example, I've seen this mistake made several times:
>>
>> a = set(whatever) # or dict
>> b = list(a)
>> c = list(a)
>> assert b == c
>>
>> The assertion does NOT have to hold, and I've seen situations where it
>> doesn't.
>
> Actually, it should hold, since the iteration order of a given set or dict
> doesn't change (similarly, dict.keys(), dict.values() and dict.items() should
> all iterate in the same order). However, constructing the set in different ways
> may lead to different iteration orders.
>
> Regards
>
> Antoine.

Yes, that was a simplification of the problem.  I think when I saw it
some very subtle thing was happening to the set.  I can look it up if
anyone's interested.

Aaron Meurer


More information about the Python-porting mailing list