python - 简单的嵌套 for 循环
问题描述
我是 Python 新手,需要以下代码方面的帮助。任务是用空字符串“”替换所有“坏”符号和字符。
test_data = [“1913-1923”,“(1951)”,“1994”,“1934”,“c. 1915”,“1995”,“(1988)”,“2002”,“1957-1959”, c. 1955.”、“c. 1970 年代”、“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
该函数未对列表进行任何更改。有人可以向我解释发生了什么问题吗?非常感谢!
解决方案
推荐阅读
- javascript - 使用 lodash 查找对象数组上的所有重复项
- git - Bazel 测试返回私有 GitHub 存储库的校验和不匹配错误
- dart - 如何转换流
流式传输 在飞镖 - python - 每当任务(patternstart.finditer 中的匹配)返回 None 时,我如何创建操作?
- php - 在所有索引中为每个循环在数组中添加新的键值对
- perl - Perl:如何使用严格的 perl 文件中其他 pl 文件中定义的常量?
- sql-server - SQLCMD 还原未还原所有存储过程
- java - Spring 依赖注入 - 私有字段 - 反模式?为什么它甚至可以工作?
- ruby-on-rails - 如何在 Rails 中仅显示一个带有嵌套表单的项目?
- sql - 即使某些列可能为 NULL,也从数据库中删除多个重复行