Re:Why I Still Use Python for High Performance Scientific Co...
by andreasvc on Wednesday December 02, 2015 @07:27AM
(#10662516)
The easiest is to never use .keys() or .iterkeys(), and always iterate over the bare dict:
for k in dict:
...
if k in dict:
...
If you do need a list of keys, list(dict) has the advantage of working in both Python 2 and 3.
Re:Why I Still Use Python for High Performance Scientific Co...
by sergiosgc on Wednesday December 02, 2015 @08:07AM
(#10662685)
Just to clarify your python 2 note: In python 3 keys() returns an iterator, so there is no penalty (i.e. iterkeys was dropped, keys assumed iterkeys interface).
The equivalent python2 behaviour can be obtained using list(somedict.keys())
This has been 'fixed' in python3 and .keys() now returns an iterable view of the keys, and if you actually want a list of the keys you have to explicit and write list(dict.keys())