From the course: Go for Python Developers

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Challenge: Character frequency

Challenge: Character frequency - Go Tutorial

From the course: Go for Python Developers

Challenge: Character frequency

(intriguing music) - In this challenge, I'd like you to print a character and its frequency in percent. You should print them in descending order and assume ASCII text and ignore white space. So here's the Python solution. We start with the counts dictionary and then the count which is a global count, which is zero. Then for every character in the poem, if it's a space, we ignore it, otherwise we increment the counts and increment the global counter. Then we use the built in sort it which sorts the items by the count in reverse order, so we get a descending order. We convert the frequency to percent and print out the character and the frequency in percent. Let's run this. So run without debugging. And once we have that and we scroll up, you can see that E is the most common character.

Contents