← Back to challenges

Find Unique Number in List

PythonMediumarraysnumberslanguage_fundamentals

Instructions

Create a function that takes a list of integers as an argument and returns a unique number from that list. All numbers except unique ones have the same number of occurrences in the list.

Examples

find_single_number([2, 2, 2, 3, 4, 4, 4]) ➞ 3

find_single_number([2]) ➞ 2

find_single_number([]) ➞ None

find_single_number([7, 13, 3, 6, 5, 4, 4, 13, 5, 3, 6, 7, 6, 5, 3, 13, 4, 7, 13, 5, 7, 4, 3, 6, 8, 4, 3, 7, 5, 6, 13]) ➞ 8

find_single_number([1, 2, 3, 6, 5, 4, 4, 2, 5, 3, 6, 1, 6, 5, 3, 2, 4, 1, 2, 5, 1, 4, 3, 6, 101, 4, 3, 1, 5, 6, 2]) ➞ 101

Notes

  • Be aware this challenge includes two validations:
    1. Empty input should return None (example #3).
    2. Single item lists should return that item (example #2).
  • There are always 1 or 0 unique numbers in the input. No two or three+ uniques.
  • Hint: Try using Python's set()
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Automorphic Number