Movatterモバイル変換


[0]ホーム

URL:


iterating through humongously large key lists!!

Alex Martellialeaxit at yahoo.com
Wed Apr 25 18:11:26 EDT 2001


"Mark blobby Robinson" <m.1.robinson at herts.ac.uk> wrote in messagenews:3AE706FE.719B091F at herts.ac.uk...> I needed a non-destructive method so popitem was not a viable option, butIIn many cases it should not be a problem to 'restore' into _another_dictionary.  Or do you have many references to the starting dictwhich it would be a problem to update...?  Then you can do thesame 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] = valueand now in newdic you have all you earlier had in oldict, and maypour 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-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp