Merge pull request #126 from Natgho/123-unique-function-fixing

123 unique function fixing
This commit is contained in:
Angelos Chalaris
2019-10-08 09:39:45 +03:00
committed by GitHub

17
snippets/filter_unique.md Normal file
View File

@ -0,0 +1,17 @@
---
title: filter_unique
tags: list,beginner
---
Filters out the unique values in a list.
Use list comprehension and `list.count()` to create a list containing only the non-unique values.
```py
def filter_unique(lst):
return [x for x in set(item for item in lst if lst.count(item) > 1)]
```
```py
filter_unique([1, 2, 2, 3, 4, 4, 5]) # [2, 4]
```