Skip to content

Instantly share code, notes, and snippets.

@marskar
Created August 17, 2019 17:53
Show Gist options
  • Select an option

  • Save marskar/b9d9f823c8704c121d4e7b91b69a0dc0 to your computer and use it in GitHub Desktop.

Select an option

Save marskar/b9d9f823c8704c121d4e7b91b69a0dc0 to your computer and use it in GitHub Desktop.
Use Python🐍to get items that only show up once in a list & preserve order:
def get_singles(a_list):
while a_list:
x = a_list.pop(0)
if x in a_list:
a_list.remove(x)
else:
yield x
list(get_singles([0, 1, 1, 2, 3]))
# [0, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment