Suppose we have a string s with lowercase, uppercase, numeric and special characters. We have to check whether frequency of any one of character is more than the half of length of string or not.
So, if the input is like s = "CC*Ca5&CC", then the output will be True as frequency of 'C' is 5 and length of string is 9. (5 > 9/2).
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
from collections import defaultdict def solve(s): freq = defaultdict(int) for ch in s: freq[ch] += 1 for ch in freq: if freq[ch] > len(s) // 2: return True return False s = "CC*Ca5&CC" print(solve(s))