+ 1

Pls help! Stuck on an exercise

Hi, I'm stuck on an letter counter developing exercis of Intermediate Python course. This is what is requested: 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 Dec 2021, 8:40 PM
Manuel Molinaro
7 odpowiedzi
+ 2
#Try this text = input() dict = {} #your code goes here for i in text: if i not in dict: dict[i]=1 else: dict[i]+=1 print(dict)
19th Dec 2021, 5:02 AM
Aqsam Husnain
Aqsam Husnain - avatar
+ 6
Here is an hint You need to store the output in a dictionary 2. You need to iterate through a string 3. You need to check if the String iterated through is an alphabet. 4. You will need a counter variable that will count how many letters are there
18th Dec 2021, 8:45 PM
MATOVU CALEB
MATOVU CALEB - avatar
+ 1
You are very close to a solution. It remains only to add a counter of letters to: {i: ... for i in word}. And yet, list() is not needed here.
18th Dec 2021, 11:21 PM
Solo
Solo - avatar
+ 1
Aqsam Husnain Worked perfectly. Thx a lot, I didn't think it could be written in such a simple way
23rd Dec 2021, 8:12 PM
Manuel Molinaro
0
Any attempt
18th Dec 2021, 8:41 PM
MATOVU CALEB
MATOVU CALEB - avatar
0
I'm blocked on creating this list, don't know how to count the letters and putting the values in the dictionary word=list(input()) output={i for i in word} print(output)
18th Dec 2021, 8:46 PM
Manuel Molinaro
0
Ok I'm gonna try tomorrow and let you know, thx a lot
18th Dec 2021, 8:48 PM
Manuel Molinaro