我有一组字符串set1,并且所有字符串set1都有两个特定的子字符串,我不需要并且想要删除它们.
示例输入:
set1={'Apple.good','Orange.good','Pear.bad','Pear.good','Banana.bad','Potato.bad'}
基本上我希望从所有字符串中删除.good和.bad子串.
我尝试了什么:
for x in set1:
x.replace('.good','')
x.replace('.bad','')
Run Code Online (Sandbox Code Playgroud)
但这似乎根本不起作用.输出绝对没有变化,它与输入相同.我尝试使用for x in list(set1)而不是原来的,但这并没有改变任何东西.