[Tutor] Using dictionary to find the mode of a list

Conor Leister conorleister at gmail.com
Fri Oct 26 00:36:03 CEST 2007


I'm just trying to get the mode of a list.
Here's the code I have that gathers the data and sorts it.  i just need to
be able to get the mode of a using a dictionary and i can't seem to figure
out anything. i'm completely lost. this code works fine, i just need to add
to it and i'm not great with dictionaries.

#gather data
a=[]
prompt='Enter numbers, blank line to finish:'
inVal=raw_input(prompt)
while inVal:
    a.append(int(inVal))
    inVal=raw_input(prompt)
print 'The values you entered:'
print a

#Bubble Sort
i=0
while i<len(a):
    j=1
    while j<len(a)-i:
        if a[j-1]>a[j]:
            temp=a[j]
            a[j]=a[j-1]
            a[j-1]=temp
        j=j+1
    i=i+1
print 'Values sorted: ' ,a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071025/dea93b69/attachment.htm 


More information about the Tutor mailing list