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}
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..
0
string = "hello"
my_dict = {k: string.count(k) for k in string}
print(my_dict)