def majority_vote(labels):
 vote_counts = Counter(labels)
 (winner, winner_count) = vote_counts.most_common(1)[0]
 num_winners = len([count for count in vote_counts.values() if (count == winner_count)])
 if (num_winners == 1):
  return winner
 else:
  return majority_vote(labels[:(-1)])

def majority_vote ( labels ) : vote_counts = Counter ( labels ) ( winner , winner_count ) = vote_counts . most_common ( 1 ) [ 0 ] num_winners = len ( [ count for count in vote_counts . values ( ) if ( count == winner_count ) ] ) if ( num_winners == 1 ) : return winner else : return majority_vote ( labels [ : ( - 1 ) ] )
assumes that labels are ordered from nearest to farthest .