import collections def longest_palindrome(s): char_count = collections.Counter(s) length = 0 for count in char_count.values(): length += count // 2 * 2 if length < len(s): length += 1 return length # driver code def main(): input_string = ["abccccdd", "abcdefg", "BbBbBbBb", "REaccaR", "AbcDeFGhAachDeFG"] for i in range(len(input_string)): print(i + 1, ".\tInput string: '", input_string[i], "'", sep="") print("\tLength of longest palindrome is: ", longest_palindrome(input_string[i]), sep="") print("-" * 100) if __name__ == "__main__": main()