How shall I convert a string as given below into a dictionary in the given way?
sentence = "python is a programming language"
Output:
{'p' : ['python', 'programming'], 'i' : ['is'], 'a' : ['a'], 'l' : ['language']}
How shall I convert a string as given below into a dictionary in the given way?
sentence = "python is a programming language"
Output:
{'p' : ['python', 'programming'], 'i' : ['is'], 'a' : ['a'], 'l' : ['language']}
sentence = "python is a programming language"
d = {}
for s in sentence.split():
if s[0] not in d.keys():
d[s[0]] = [s]
else:
d[s[0]].append(s)