+ 1
How to remove paired items in a list?
How to remove paired items in a list? Let's say I have a list List = [1,3,1,3,2, 1] You need to remove 2 paired elements from the list That is, first remove 1, 1. Then 3, 3. The output should be [1,2] The number 1 remains because she does not have a pair
5 Antworten
+ 3
There is a contradiction in your statement according which elements should be in the output. Can you check this please?
+ 1
Sorry. I changed my question
0
for i in list:
if list.count(i)%2==0:
for j in range(list.count(i)):
list.remove(i)
for i in list:
if list.count(i)%2>=1:
for j in range(list.count(i)-1):
list.remove(i)
you convert it to a function.
print('good luck')
- 1
If you just want to remove duplications:
print(sorted(list(set(List))))
If you want to remove them completely:
print([i for i in List if List.count(i) == 1])