{"id":18853,"date":"2021-08-26T10:37:51","date_gmt":"2021-08-26T05:07:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=18853"},"modified":"2021-11-22T18:37:19","modified_gmt":"2021-11-22T13:07:19","slug":"python-program-to-check-if-all-characters-have-even-frequency","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-if-all-characters-have-even-frequency\/","title":{"rendered":"Python Program to Check if All Characters have Even Frequency"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find Two Odd Occurring Elements in an Array\/List<\/a>
\nThe task is to check whether all characters in the given string made up entirely of lowercase letters have an even frequency.<\/p>\n

Counter function in Python:<\/strong><\/p>\n

The counter is a set and dict subset. Counter() takes an iterable entity as an argument and stores the elements as keys and the frequency of the elements as a value. So, in collections, if we transfer a string. When you call Counter(), you\u2019ll get a Counter class object with characters as keys and their frequency in a string as values.<\/p>\n

Counter() returns a Counter type object (a subclass of dict) with all characters in the string as keys and their occurrence count as values. We\u2019ll use the [] operator to get the occurrence count of the characters from it.<\/p>\n

For example:<\/p>\n

let given string = “pqrspqrspp”.<\/p>\n

In this p<\/strong> occurred 4 times, q,r,s<\/strong> occurred 2 times.<\/p>\n

Therefore the frequency of all the characters in a given string is Even.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"pqrspqrstutu\"<\/pre>\n

Output:<\/strong><\/p>\n

Yes,the given string { pqrspqrstutu } contains all characters at even intervals<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

No,the given string { btechgeeks } does not contains all characters at even intervals<\/pre>\n

Program to Check if All Characters have Even Frequency in Python<\/h2>\n

Below are the ways to check whether all characters in the given string made up entirely of lowercase letters have an even frequency:<\/p>\n