counts = [0] * 11 # for testing use following user_data = 'hjhjhu755399952210887340123456789' # user_data = user_data=input('Enter string of numbers and characters: ') for x in user_data: if x.isdigit(): idx = int(x) counts[idx] += 1 else: counts[10] += 1 print(counts)result:
Output:[2, 2, 3, 3, 2, 4, 1, 3, 3, 4, 6]
create comment on current user_data and remove on input to input data.you can simplify more with list comprehension