Created
October 2, 2016 16:43
-
-
Save onsmribah/43f93ce9581beb293118057b49d357b7 to your computer and use it in GitHub Desktop.
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
from collections import Counter | |
def odd_occurences(elements): | |
"""returns the value of the unpaired element in odd number of elements. | |
:param elements: a list of integers. | |
:rtype: int | |
""" | |
odd_values = [value for value, count in Counter(A).iteritems() if count % 2 != 0] | |
# The task description assumes there should be one and only one odd value in the given list | |
# solution returns zero for an empty list | |
return odd_values[0] if odd_values else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment