bob gailer wrote:
j mercedes wrote:
Hi, I have problem here...I am writing a program but I am getting
stucked at how to solve the mode of a series of numbers...any ideas???
The customary approach is to collect counts of each value in a
dictionary. Untested code follows:
from collections import defaultdict
def mode(data):
numdict = defaultdict(int)
for num in data: # correction
numdict[num] += 1 # correction
numlist = [(count, num) for num, count in nums.items()]
numlist.sort()
print 'The mode is: ', numlist[-1][1]
--
Bob Gailer
Chapel Hill NC
919-636-4239
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor