Created
August 17, 2019 17:53
-
-
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:
This file contains hidden or 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
| 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