Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Last active December 22, 2015 14:19
Show Gist options
  • Save avalanchy/6485159 to your computer and use it in GitHub Desktop.
Save avalanchy/6485159 to your computer and use it in GitHub Desktop.
Indexes of most common value in array of integers. Without importing any library
"""
Indexes of most common value in array of integers.
Without importing any library.
@author: avalanchy
Python 2.7
"""
# random 1 million
from random import randint
array = [randint(1, 100) for _ in xrange(1, 10**6)]
most_common = max(set(array), key=array.count)
indexes = [n for n, val in enumerate(array) if val == most_common]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment