1

I have a quite large list with lots of not needed information and only a certain word string that I want. So if I had a list of:

my_list = ["cookies are good", "cookies are bad", "cookies are very good"]

And I wanted to cut everything out except all instances of good in a segment so it would look like this:

my_list = ["cookies are good", "cookies are very good"]

How could I do this? Thank you so much :)

Sam
  • 35
  • 4
  • Possible duplicate of [Removing elements from a list containing specific characters](https://stackoverflow.com/questions/3416401/removing-elements-from-a-list-containing-specific-characters) – smac89 Feb 05 '18 at 02:56
  • 2
    `[i for i in my_list if "good" in i]` – Sohaib Farooqi Feb 05 '18 at 02:57

1 Answers1

1

A simple list comprehension solves this problem:

new_list = [x for x in my_list if 'good' in x]
Lost
  • 998
  • 10
  • 17