Isaac A Isaac A - 1 year ago 62
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

Answer Source
result = [x if x.find("SOME-STRING")>=0 else x+"some string" for x in list]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download