0

Hi my friend i have problem i dont know how to make this thing :

Given a string as input, you need to output how many times each letter appears in the string. You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values. 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}

18th Feb 2022, 10:15 AM
Amir H.R.N
Amir H.R.N - avatar
3 odpowiedzi
+ 3
Complete dictionary lesson before attempting... You can find there how to make a dictionary dict1 = {} #empty dictionary declared dict[key] = value #this way you can assign value at the key as index. if value already present in dictionary, then increment it's value instead of adding a new value.. dict[key] returns value.. Add to it and store back.. Try and post your attempt.. Hope it helps..
18th Feb 2022, 10:33 AM
Jayakrishna 🇮🇳
0
string = "hello" my_dict = {k: string.count(k) for k in string} print(my_dict)
19th Feb 2022, 8:20 AM
US Department Of State
US Department Of State - avatar