I have a string called sentence: \'the sly fox jumped over the brown dog\'
I need to create a dictionary called Positions.
The key
since the character might be repeated in string, i am storing them as a list
str = "the sly fox jumped over the brown dog"
char_items = list(str)
dictionary = {}
for index,character in enumerate(char_items):
if character not in dictionary.keys():
dictionary[character] = [] # because same character might be repeated in different positions
dictionary[character].append(index)
for character,positions in dictionary.items():
print(character, positions)