【发布时间】:2019-09-23 16:49:31
【问题描述】:
我有三个列表 - base, match, and replac ; match 和 replac 长度相同
base = ['abc', 'def', 'hjk']
match = ['abc', 'hjk']
replac = ['abcde', 'hjklm']
我想通过匹配match 中的字符串项来修改base 列表,并将它们替换为replac 中的相同索引项。
预期输出:base = ['abcde', 'def', 'hjklm']
【问题讨论】:
-
我能想到的最好的方法是用
match中的单词作为键,replac中的单词作为值,然后循环遍历base中的单词并替换它们。
标签: python list string-matching