0

How can I remove several same items in a LIST for ex:

a = [1,1,1,1,1,1,2,2,2,2,2,2]

I want to remove all 1 values, such that output is:

a = [2,2,2,2,2,2]

I tried a.remove(1) but it only remove one '1' at the first encounter. i try looking for comprehension method

  • @Aran-Fey thanks for a reference, kinda what i looking for, but still looking for the lesser complex, (kinda like '.remove()' thing), but thanks anyway. – Muhammad Iqbal Tawakkal Jun 04 '18 at 07:05
  • I don't see how your question is different from the one I linked. You'll find all the conceivable solutions there. You just have to pick the one you dislike the least. – Aran-Fey Jun 04 '18 at 07:14

1 Answers1

0

Try it with a list comprehension:

a = [1,1,1,1,1,1,2,2,2,2,2,2]
cleaned_a = [el for el in a if el != 1]
Igl3
  • 4,900
  • 5
  • 35
  • 69