I am trying to solve the following problem:
Make a function that accepts a list of individual digits (entered on the command line when the program starts) and find the most frequently used digit.
For example, the following command:
$ python frequency.py 4 6 7 7 0 5 9 9 4 9 8 3 3 3 3
As a result, you should return 3
I decided that I could solve this problem using a recursive function and a for loop, but my attempt does not give the correct result.
def frequency2(a):
a[0:1] = []
b = a
if a == []:
return []
else:
return [[a[0]] + [b.count(a[0])]] + frequency2(a[1:])
aa = sys.argv
print frequency2(aa)
What am I doing wrong?
source
share