Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -------------------- tasks/non_unique.py ---------------
- def checkio(data: list) -> list:
- res = []
- for i in data:
- if data.count(i) > 1:
- res.append(i)
- return res
- def checkio_gen(data: list) -> list:
- return list(i for i in data if data.count(i) > 1)
- def checkio_list_comp(data: list) -> list:
- return [i for i in data if data.count(i) > 1]
- def checkio_filter(data: list) -> list:
- not_unique = lambda item: data.count(item) > 1
- return list(filter(not_unique, data))
- # -------------- tests/test_non_unique.py ------------------------
- import pytest
- from tasks.non_unique import checkio, checkio_gen, checkio_list_comp, checkio_filter
- @pytest.mark.parametrize("func", [
- checkio, checkio_gen, checkio_list_comp, checkio_filter
- ])
- @pytest.mark.parametrize(["collection", "res"], [
- [[1, 2, 3, 1, 3], [1, 3, 1, 3]],
- [[1, 2, 3, 4, 5], []],
- [[5, 5, 5, 5, 5], [5, 5, 5, 5, 5]],
- [[10, 9, 10, 10, 9, 8], [10, 9, 10, 10, 9]],
- ])
- def test_non_unique(func, collection, res):
- assert func(collection) == res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement