3 ms·
Sorry, yes, I was hasty. Ordered dicts supports such a thing with intervening modifications: oldkeys = list(D.keys()) D[z] = foo(z) now if you take zi
by klyrs 7y ago
Sorry, yes, I was hasty. Ordered dicts supports such a thing with intervening modifications:
oldkeys = list(D.keys())
D[z] = foo(z)
now if you take
zip(oldkeys, D.values())
then you're guaranteed to iterate over oldkeys, with the proper values associated with those keys -- if z was an oldkey, its value got updated; otherwise, it comes after oldkeys and gets dropped out of zip.
The subtlety of this is what I, and perhaps others, find the most jarring.