Skip to content

Instantly share code, notes, and snippets.

@onsmribah
Created October 2, 2016 16:43
Show Gist options
  • Save onsmribah/43f93ce9581beb293118057b49d357b7 to your computer and use it in GitHub Desktop.
Save onsmribah/43f93ce9581beb293118057b49d357b7 to your computer and use it in GitHub Desktop.
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