I'm trying to solve the following problem:
Compose a function that takes a list of single digits (entered at the command-line when running the program) and find the digit entered most frequently.
For example, the following command:
$ python frequency.py 4 6 7 7 0 5 9 9 4 9 8 3 3 3 3
Should return 3 as the result
I figured I could solve this problem using a recursive function and a for loop, but my attempt is not providing 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?