UPD: inserting
from collections import OrderedDict
into one of my code cells helped
I want to make a program which accepts a string and then outputs dictionary where each element is this string's character with an index.
Input: hello
Output {'h': 1, 'e': 2, 'l': 3, 'l': 4, 'o': 5}
I've come up with several ways to create this kind of dictionary. However, in every case I have the following output with above-mentioned input: {'e': 2, 'h': 1, 'l': 4, 'o': 5}
#solution 1
s = str(input())
dic = {}
for index, symb in enumerate(s, 1):
dic[symb]=index
dic
#soultion 2
s = input()
d4 = {}
d4 = dict(zip(s,range(1,len(s)+1)))
d4
What can be an issue here? I will appreciate any help. THanks in advance.
P.S. for coding I use Google Collab