0

Help please, how to add in dictionary???

Can you help me please Create a program to take a string as input and output a dictionary, which represents the letter count. Sample Input hello Sample Output {'h': 1, 'e': 1, 'l': 2, 'o': 1} Ok i take string, I count But how to add in dictionary????? https://code.sololearn.com/cT4nuNAPfeNC/?ref=app

8th Mar 2022, 10:49 PM
hanan nassar
hanan nassar - avatar
3 Respuestas
+ 1
A small snippet using yours code: o=dict() for i in x: o[i]=x.count(i) First line inits "o" variable with empty dictionary. "i" on for loop is reference to each element of x. "i" is also the key. x.count() is a value. Inserting new key-value element to dictionary in python is made using syntax dictionary[key] = value. Hope it helps a little. :)
8th Mar 2022, 11:17 PM
LetTheSunDie
LetTheSunDie - avatar
+ 1
It’s work 🤝 thank you it helped me a lot
8th Mar 2022, 11:34 PM
hanan nassar
hanan nassar - avatar