generate functionTue, 21 Mar 2023

the program finds the number of all repeated characters, case insensitive, in the string and forms a list of the number of repeated and single characters in ascending order

def count_characters(string): # Write your code here count = {} for char in string: if char.lower() in count: count[char.lower()] += 1 else: count[char.lower()] = 1 new_list = [] for key in sorted(count): new_list.append((count[key], key)) return new_list

Questions about programming?Chat with your personal AI assistant