Is there a way to print both key and value of a anonymous dict in python.
for key in {'one':1, 'two':2, 'three':3}:
print key, ":", #value
for key, value in {'one':1, 'two':2, 'three':3}.iteritems():
print key, ":", value
By default, iterating over it returns its keys. .iteritems() returns 2-tuples of (key, value).
You could do:
for (key, value) in {'one':1, 'two':2, 'three':3}.items():
print key, value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With