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()]
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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()]