0

I have a list of elements lets say

images = ['fcs-apple-5.5.4','gcs-banana-0.6.4','tf-2', 'mvc-grape-3.4.2'] 

basically I want to delete the item that has a sub-string grape, so I will pass grape as input and look for the item matching grape. so I want to do a for loop and match and find the element and delete it. I know how to match the element, but I do not know how to find the index and delete it because I still have to get the whole list item name.

End results I'm looking for

images = ['fcs-apple-5.5.4','gcs-banana-0.6.4','tf-2'] 
mac
  • 863
  • 3
  • 21
  • 42

2 Answers2

0
images = ['fcs-apple-5.5.4','gcs-banana-0.6.4','tf-2', 'mvc-grape-3.4.2'] 

inp = input() # you can choose your input here e.g. 'grape'

[x for x in images if inp not in x ]

#output
['fcs-apple-5.5.4', 'gcs-banana-0.6.4', 'tf-2']
Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
0
images = ['fcs-apple-5.5.4', 'gcs-banana-0.6.4', 'tf-2', 'mvc-grape-3.4.2']
substring = "grape"

images = [image for image in images if substring not in image]
print(images)
Sakib Rahman
  • 333
  • 2
  • 13