re: Python for JavaScript Developers VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION

But note that in python for key in {1: 10, 2: 20}: iterates over dictionary's keys.

You can use for value in d.keys():, for (key, value) in d.items(): and (redundant) for k in d.keys():.
These methods exist in both Python 2 and 3, though with some differences (see python.org/dev/peps/pep-3106/).

You can drop the parenthesis i.e. for k, v in thing.items(). You only need parenthesis for comprehension i.e. {k: v for (k,v) in thing.items()} or [(k,v) for (k,v) in thing.items()]

code of conduct - report abuse