Python Forum
Why is one duplicate not removed?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is one duplicate not removed?
#5
Another way is to use list comprehension:

>>> lst_1 = [1, 2, 3, 4, 5, 6]
>>> lst_2 = [1, 2, 5, 6]
>>> lst_1 = [item for item in lst_1 if item not in lst_2]
>>> lst_1
[3, 4]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Why is one duplicate not removed? - by Emekadavid - Jun-09-2020, 02:11 PM
RE: Why is one duplicate not removed? - by Yoriz - Jun-09-2020, 02:30 PM
RE: Why is one duplicate not removed? - by divyansh - Jun-09-2020, 05:56 PM
RE: Why is one duplicate not removed? - by perfringo - Jun-09-2020, 06:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl: Excel formula & condition formatting removed JaneTan 0 3,679 Sep-25-2020, 07:02 AM
Last Post: JaneTan
  How to check if video has been deleted or removed in youtube using python Prince_Bhatia 14 11,940 Feb-21-2020, 04:33 AM
Last Post: jehoshua
  how to detect \x in string so it can be removed azimmermann 5 5,903 Jul-05-2017, 10:46 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020