Advertisement
Guest User

Untitled

a guest
Dec 16th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def majority(A):
  2.     min = len(A)/2.0
  3.     counts = {}
  4.     for x in A:
  5.         if x in counts:
  6.             counts[x] += 1
  7.         else:
  8.             counts[x] = 1
  9.     a = max(counts.iteritems(), key = lambda x: x[1])
  10.     if a[1] > min:
  11.         print "The winner is:", a[0]
  12.     else:
  13.         print "There is no winner"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement