xxxxxxxxxx
my_dict = {"name": "John", "age": 30, "city": "New York"}
# Iterate over keys
for key in my_dict:
print(key)
xxxxxxxxxx
dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
for key, value in dictionary.items():
print(key)
print(value)
xxxxxxxxxx
a_dict = {'apple':'red', 'grass':'green', 'sky':'blue'}
for key in a_dict:
print key # for the keys
print a_dict[key] # for the values
xxxxxxxxxx
a_dict = {"color": "blue", "fruit": "apple", "pet": "dog"}
# Will loop through the dict's elements (key, value) WITHOUT ORDER
for key, value in a_dict.items():
print(key, '->', value)
xxxxxxxxxx
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print key, 'corresponds to', d[key]
xxxxxxxxxx
students = {
'John': 85,
'Emily': 92,
'Michael': 78,
'Sarah': 89
}
for student in students:
print(student, students[student])
xxxxxxxxxx
dd = {'john':3, 'mary':4, 'joe':5, 'vicky':7}
for kk in dd:
print(kk)
# john
# mary
# joe
# vicky
xxxxxxxxxx
my_dict = {'a': 1, 'b': 2, 'c': 3}
for key, value in my_dict.items():
print(key, value)
xxxxxxxxxx
dictionary_name={"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"}
for key in dictionary_name.keys():
print(key)