Python Iterate Słownik Wartość kluczowa
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
for key, value in a_dict.items():
print(key, '->', value)
Zealous Zebra
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
for key, value in a_dict.items():
print(key, '->', value)
dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
for key, value in dictionary.items():
print(key)
print(value)
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
new_list = [something(key, value) for key, value in a_dict.items()]
# iterating through dictionary keys fast
dictKeys = list(nameOfDict.keys())
for i in range(len(dictKeys)):
print(dictKeys[i])
# iterating through dictionary values fast
dictValues = list(nameOfDict.values())
for i in range(len(dictKeys)):
print(dictKeys[i])
thisdict = {
"1": "C language",
"2": "Java Language",
"4": "Python Language",
"3": "C++",
}
print('\n\n')
#print 2nd record from dictionary
n=2
for index, (key, value) in enumerate(thisdict.items()):
if index == n:
print(key, '::', value)
break