Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Non-unique Elements by Pavellver
from collections.abc import Iterable
def checkio(data: list[int]) -> Iterable[int]:
return [i for i in data if data.count(i) > 1]
print("Example:")
print(list(checkio([1, 2, 3, 1, 3])))
# These "asserts" are used for self-checking
assert list(checkio([1, 2, 3, 1, 3])) == [1, 3, 1, 3]
assert list(checkio([1, 2, 3, 4, 5])) == []
assert list(checkio([5, 5, 5, 5, 5])) == [5, 5, 5, 5, 5]
assert list(checkio([10, 9, 10, 10, 9, 8])) == [10, 9, 10, 10, 9]
assert list(checkio([2, 2, 3, 2, 2])) == [2, 2, 2, 2]
assert list(checkio([10, 20, 30, 10])) == [10, 10]
assert list(checkio([7])) == []
assert list(checkio([0, 1, 2, 3, 4, 0, 1, 2, 4])) == [0, 1, 2, 4, 0, 1, 2, 4]
assert list(checkio([99, 98, 99])) == [99, 99]
assert list(checkio([0, 0, 0, 1, 1, 100])) == [0, 0, 0, 1, 1]
assert list(checkio([0, 0, 0, -1, -1, 100])) == [0, 0, 0, -1, -1]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 27, 2023
Comments: