a = input('Enter a string ')
dict = {}
words = a.split()
for word in words:
keys = dict.keys()
if word in keys:
dict[word] += 1 # insert value in dict and add count
else:
dict[word] = 1
print(dict)
dict = {}
words = a.split()
for word in words:
keys = dict.keys()
if word in keys:
dict[word] += 1 # insert value in dict and add count
else:
dict[word] = 1
print(dict)
No comments:
Post a Comment