When I run this
import itertools
bar = itertools.count(1).next
print {'a': bar(), 'b': bar(), 'c': bar()}
on CPython, I get {'a': 0, 'b': 1, 'c': 2}. Is this consistent across implementations and/or documented anywhere? Will a, b and c ever be assigned values out of order?
The answer to your question can be found here (I do not have enough reputation to add this as a comment).
In sum, "Dictionary evaluation order should be the same as written, but there is a outstanding bug where values are evaluated before the keys.'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With