0

If one of my lists contains the same value as another list and I want to delete that. How do I do that? List q contains the value of list y. It is a list but read from a file with readlines(). And when deleting I want to delete the whole line where x is in y.

if listx in listy:
    listq.remove(listx)
54m
  • 719
  • 2
  • 7
  • 18
  • What do you mean? What does "the whole line where x is in y" mean? Do you have like a list of words and a list of lines and you want to remove the lines that contain one of the words? I suggest you post an example of the contents in those lists and clarify what output you want. – Bakuriu Sep 23 '16 at 15:40
  • You could use a `set` – Farhan.K Sep 23 '16 at 15:41
  • `list(set(a) - set(b))` – acushner Sep 23 '16 at 15:50

1 Answers1

2

Removing values from list_a if they are also in list_b

list_a = [a for a in list_a if a not in list_b]
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96