Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 16th, 2011  |  syntax: Python  |  size: 0.32 KB  |  views: 53  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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"
clone this paste RAW Paste Data