Answer the question
In order to leave comments, you need to log in
Can anyone explain the behavior of a list and the list.remove(x) method in a loop?
Hello! I solved the problem on checkiO, according to the conditions of the problem, a list of numbers (data) is given, you need to return a list of non-unique numbers. It would seem that everything is simple:
def checkio(data: list) -> list:
for d in data:
if data.count(d) < 2: #или == 1, поведение не меняется
data.remove(d)
return data
result = data.copy()
for n in data:
if(data.count(n) == 1):
result.remove(n)
return result
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question