Nathan Clegg writes: > If d is a dict, am I guaranteed that d.keys() and d.values() will line up, > in proper order, if called successively with no modification in between? > That is, is the following safe? > > k,v = d.keys(), d.values() As someone pointed out, the implementation makes this happen modulo thread interference. I asked Guido about this a couple of years ago, and he said he was willing to make that guarantee. Others have pointed out the .items() method; if that makes more sense for your application, it is better because it avoids the potentional for thread interference. However, sometimes using the individual methods is easier for the surrounding code if you really want to separate lists, or if you want to end up with (value, key) pairs (I think that's why I'd been interested in the question when I asked Guido). -Fred -- Fred L. Drake, Jr. <fdrake at acm.org> Corporation for National Research Initiatives
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4