Skip to content

Instantly share code, notes, and snippets.

/recursion.py Secret

Created March 28, 2017 22:05
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/9579e13940aa172dc2013e3cf337f95c to your computer and use it in GitHub Desktop.
Save anonymous/9579e13940aa172dc2013e3cf337f95c to your computer and use it in GitHub Desktop.
recursively extracting unique elements in nested lists.
def extract_unique_elements(a_list):
if isinstance(a_list, list) == False:
return {a_list}
uniq = []
for elt in range(len(a_list)):
if a_list[elt] not in uniq:
uniq.append(a_list[elt])
return extract_unique_elements(uniq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment