+ 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}
7 Réponses
+ 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)
+ 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
+ 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.
+ 1
Aqsam Husnain Worked perfectly. Thx a lot, I didn't think it could be written in such a simple way
0
Any attempt
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)
0
Ok I'm gonna try tomorrow and let you know, thx a lot