Created
April 1, 2016 02:38
-
-
Save xuefeng-huang/fe21f83e9addbd8ad89abf2c82660f44 to your computer and use it in GitHub Desktop.
find the outlier(odd from even or vice versa) from group of integers
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
def find_outlier(integers): | |
"""return the outlier from integer list""" | |
parity = [n % 2 for n in integers] | |
return integers[parity.index(1)] if sum(parity) == 1 else integers[parity.index(0)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment