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

11th Aug 2021, 11:51 AM
Gee Pebbles
Gee Pebbles - avatar
7 Respuestas
+ 1
You can use dictionary comprehension with count method to do it in 1 line.
11th Aug 2021, 12:04 PM
Abhay
Abhay - avatar
+ 1
Gee Pebbles a=input() {i:a.count(i) for i in a }
11th Aug 2021, 12:38 PM
Abhay
Abhay - avatar
+ 1
Abhay thanks 🙂
11th Aug 2021, 12:55 PM
Gee Pebbles
Gee Pebbles - avatar
0
Abhay thanks
11th Aug 2021, 12:07 PM
Gee Pebbles
Gee Pebbles - avatar
0
Abhay thanks
11th Aug 2021, 12:09 PM
Gee Pebbles
Gee Pebbles - avatar
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.
11th Aug 2021, 12:10 PM
Abhay
Abhay - avatar
0
You can use dictionary comprehension with count method to do it in 1 line. Abhay can you show me how
11th Aug 2021, 12:18 PM
Gee Pebbles
Gee Pebbles - avatar