我是Python的新手,需要以下代码的帮助。任务是用空字符串“”替换所有“不良”符号和字符。
test_data = [“ 1913-1923”,“(1951)”,“ 1994”,“ 1934”,“ c.1915”,“ 1995”,“(1988)”,“ 2002”,“ 1957-1959” “,” c。1955.“,” c。1970's,“ c。1990-1999”]
bad_chars = [“(”,“)”,“ c”,“ C”,“。”,“ s”,“'”,“”
这是我认为可行的方法:
def func1(list1, tobereplaced):
for x in tobereplaced:
for i in list1:
i = i.replace(x,'')
return list1
该功能未更改列表。有人可以向我解释哪里出了问题吗?非常感谢!