In this article, we will create a function which will take in a string and then change the word within that string to either all uppercases if most of the words within that string are uppercase or all lowercases if most of those words are either lowercase or the word counts for the uppercase word and lowercase word are equal.
def solve(s): list_string = list(s) upper = 0 lower = 0 for word in list_string: if word.isupper(): upper += 1 else: lower += 1 if upper > lower : return s.upper() elif upper < lower: return s.lower() else: return s.lower()
Very simple solution, if you have better idea leave your comment below.