Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Write a function, countChar(STRING), that takes a string as an argument and returns a dictionary containing the frequency of each character in the string. 

For example, if the string is "Hello world", the output will be 

{'H': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}

Answer:

Answer by student

Python function that takes a string as an argument and returns a dictionary containing the frequency of each character in the string - Teachoo.png

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.