Skip to content

Instantly share code, notes, and snippets.

/.py Secret

Created March 28, 2017 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f3d1a03dd3bfcad5cbb0ad6b0dabe611 to your computer and use it in GitHub Desktop.
Save anonymous/f3d1a03dd3bfcad5cbb0ad6b0dabe611 to your computer and use it in GitHub Desktop.
# test cases;
# extract_unique_elements([2])
# extract_unique_elements([[[[5, 5]]]])
# extract_unique_elements([2, 2, 3, [[[3]]]]) FAILED
# extract_unique_elements([[3, [3, [[3]]]]])
# extract_unique_elements([2, [[2, 4, 5]], 'c', [[['c', 'd']]]]) FAILED
def extract_unique_elements(a_list):
if isinstance(a_list, list) == False:
return {a_list}
uniq = {}
for element in a_list:
if isinstance(a_list,list):
return extract_unique_elements(element)
else:
uniq.add(element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment