wrong definition updated, code developed correctly according to definition

This commit is contained in:
natgho
2019-10-02 20:06:04 +03:00
parent 9768c5d510
commit 389429ff16

View File

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