Isaac A Isaac A - 2 months ago 5
Python Question

If item in list does not contain "string", add a "string2" to the item?

In Python I have a list of this sort:

list = ["item.1", "sdfhkjdsffs/THIS-STRING", "fsdhfjsdhfsdf/THIS-STRING",
item4/THIS-STRING, item5]


How do I go about adding
"some string"
for each item in list that does not contain
"THIS-STRING"
?

Answer
result = [x if x.find("SOME-STRING")>=0 else x+"some string" for x in list]
Comments