fork(1) download
  1. def get_major_element(my_list):
  2. available_items = set(my_list)
  3. max_count, max_item = max((my_list.count(item), item) for item in available_items)
  4. return max_item if max_count > len(my_list)/2 else None
  5.  
  6. l = [1, 2, 3, 2, 2, 4, 1, 2, 2, 2]
  7. print(get_major_element(l))
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
2