re: Python for JavaScript Developers VIEW POST

TOP OF THREAD FULL DISCUSSION
re: You're right. for .. in iterates over key, i.e. it's comparable to something like: for (let i = 0, o = Object.keys(X); i < o.length; i++, x=o[...

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