I want to replace the item in a list that contains a certain substring. In this case the item the contains "NSW" (capitals are important) in any form should be replaced by "NSW = 0". It doesn´t matter if the original entry reads "NSW = 500" or "NSW = 501". I can find the list item but somehow i can not find the postion in the list so i could replace it? This is what i came up with, but i replaces all items:
from __future__ import division, print_function, with_statement
my_list =["abc 123","acd 234","NSW = 500", "stuff","morestuff"]
for index, i in enumerate(my_list):
if any("NSW" in s for s in my_list):
print ("found")
my_list[index]= "NSW = 0"
print (my_list)