Given a list filled with arbitrary integers.

Get a new list, the elements of which will be:

  1. non-duplicate elements of the source list: for example, lst = [1, 2, 4, 5, 6, 2, 5, 2] , you need to get lst2 = [1, 2, 4, 5, 6]

  2. elements of the original list that do not have repetitions: for example, lst = [1 , 2, 4, 5, 6, 2, 5, 2] , you need to get lst2 = [1, 4, 6] .

Closed due to the fact that off-topic participants Kromster , insolor , Suvitruf , freim , vmchar 1 Jun at 16:00 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- insolor, suvitruf, freim, vmchar
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • five
    And what is your problem? - Vladimir Martyanov
  • one
    Is this a task for you or for us? - MarianD

1 answer 1

https://ideone.com/jSMiI2

 lst = [1, 2, 4, 5, 6, 2, 5, 2] used = set() unique = [x for x in lst if x not in used and (used.add(x) or True)] print(unique) from collections import Counter counter = Counter(lst) unique = list(counter) print(unique) single = [x for x,n in counter.items() if n==1] print(single) 

Sources: