From the course: Effective Serialization with Python

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Counting strings

Solution: Counting strings - Python Tutorial

From the course: Effective Serialization with Python

Start my 1-month free trial

Solution: Counting strings

(upbeat music) - [Instructor] Let's have a look at the solution. We defined a function called Normalize. It uses the Unicode data package to normalize the word to NFKC format, and then uses casefold to fold it for case-insensitive comparison. We create a counter and then for every word, we remove the white space from the word and then count the normalized version of the word in the counter. And finally, as before we print out the words and their counts. And now, when we run python wc.py, we see that the python is counted three times ignoring case.

Contents