0

String values in a dictionary in python?

How do I iterate through string values in a dictionary created in Python?

17th Jul 2017, 6:43 PM
Erik Breede
Erik Breede - avatar
1 Resposta
+ 7
If you have a dictionary named d, it goes likes this: d = {"key1": "string1", "key2": "string2", "key3": "string3"} # key iteration for k in d.keys(): print(k) >>> key3 key2 key1 # value iteration for v in d.values(): print(v) >>> string3 string2 string1 # key-value pair iteration for k, v in d.items(): print(k, v) >>> key3 string3 key2 string2 key1 string1
17th Jul 2017, 6:52 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar