-
-
Save anonymous/f3d1a03dd3bfcad5cbb0ad6b0dabe611 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
# 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