I have a set of strings set1, and all the strings in set1 have a two specific substrings which I don\'t need and want to remove.
Sample Input
Strings are immutable. string.replace (python 2.x) or str.replace (python 3.x) creates a new string. This is stated in the documentation:
Return a copy of string s with all occurrences of substring old replaced by new. ...
This means you have to re-allocate the set or re-populate it (re-allocating is easier with set comprehension):
new_set = {x.replace('.good', '').replace('.bad', '') for x in set1}