iterating through humongously large key lists!!
Alex Martelli
aleaxit at yahoo.com
Wed Apr 25 18:11:26 EDT 2001
"Mark blobby Robinson" <m.1.robinson at herts.ac.uk> wrote in message
news:3AE706FE.719B091F at herts.ac.uk...
> I needed a non-destructive method so popitem was not a viable option, but
I
In many cases it should not be a problem to 'restore' into _another_
dictionary. Or do you have many references to the starting dict
which it would be a problem to update...? Then you can do the
same trick again -- sure, it's gonna be slower, but...
The general idea would be:
newdic = {}
while len(oldict):
key, value = oldict.popitem()
process(key, value)
newdic[key] = value
and now in newdic you have all you earlier had in oldict, and may
pour it back if need be. Of course, not thread-safe, not fastest, &c,
but still it may be useful.
Alex
More information about the Python-list
mailing list