[Solved] Coding a function in python wihch count the number of occurances [closed]
Use the collections module to use the Counter function. Such as: import collections def carCompt(*args): return collections.Counter(“”.join(map(str.upper, args))) This will return {‘A’:5, ‘D’:1, ‘E’:3, ‘H’:2, ‘L’:1, ‘N’:1, ‘O’:1, ‘P’:2, ‘R’:2, ‘S’:1, ‘X’:1} If you want it to be case sensitive then leave it like: import collections def carCompt(*args): return collections.Counter(“”.join(args)) which will return {‘a’: 4, … Read more