my_str = 'wednesday'
Output should be
d = {'w':1,'e':2,'d':2,'n':1,'s':1,'y':1,'a':1}
Is there any direct inbuilt function?
my_str = 'wednesday'
Output should be
d = {'w':1,'e':2,'d':2,'n':1,'s':1,'y':1,'a':1}
Is there any direct inbuilt function?
You can use the dictionary comprehension, as explained in this answer : Python Dictionary Comprehension
my_str = 'wednesday'
d = { ch:(my_str.count(ch)) for ch in my_str }
print(d)
.count in a loop