My OrderedDict contains 5 key value pairs which result in the word, "Belle". Every letter its own key with values starting from 1 through 5, from left to right, B = 1, e = 2, etc. Printing this OrderedDict returns only 3 letters, B, l and e. Notice, it doesn't print the repeated e and ls.
In the code below, I use a for statement to print "Belle" so it can print vertically. My goal is to print the complete word "Belle" vertically, with each letter as a key with its value pair.
text6 = OrderedDict({'B':1, 'e':2, 'l':3, 'l':4, 'e':5})
for key, value in text6.items():
print(key, value)
Code above returns:
B 1
e 5
l 4
Desried output:
B 1
e 2
l 3
l 4
e 5
Asking a
dict(includingOrderedDict) to do what you are asking it to do is impossible. Adictof any type can only contain unique keys. All subsequently added pre-existing keys will overwrite the key and reset it's value.In order to get the output you want to see, we can use a different data structure. In this implementation, we utilize a
listwhich will contain atuplefor each (value, index) pair we will get by iterating through "Belle" usingenumerate