+ 1
Letter Counter Python
Can anyone help me with this code? Why doesn't it work? text = input() dict = {} #your code goes here for letters in text: letters = letters.split() for x in letters: dict[x] = dict.get(x, 0) + 1 print(dict)
5 Answers
0
MartiiOliwa blocks are the problem
Try to use print statement outside loops
+ 5
(1) it is not necessary to convert the input text to a list. string can be iterated directly.
(2)if we want to count all characters except spaces, we can remove them directly with input().replace(...)
# (1)
text = input()
dic = {}
for x in text:
dic[x] = dic.get(x, 0) + 1
print(dic)
# (2)
text = input().replace(" ","")
dic = {}
for x in text:
dic[x] = dic.get(x, 0) + 1
print(dic)
+ 1
Thank you HrCoder ! đ
+ 1
thanks bro
0
can you please tell me what this means
dict[x]