0
I'm supposed to create a program that takes a string as input and outputs a dictionary which represents the letter count.
For example Input: good Output {g:1, o:2, d:1} I've tried creating the program but i just don't get it
7 Answers
+ 1
You can use dictionary comprehension with count method to do it in 1 line.
+ 1
Gee Pebbles
a=input()
{i:a.count(i) for i in a }
+ 1
Abhay thanks đ
0
Abhay thanks
0
Abhay thanks
0
Or you can loop over the string , check if letter exists in dict , if not add it with key and value 1 otherwise increment the value for that dictionary key.
0
You can use dictionary comprehension with count method to do it in 1 line.
Abhay can you show me how