Last active
December 22, 2015 14:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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