我有一些字符串的列表my_list
:
['Dog Austin', 'Cat Piter', 'Tiger John', 'Lion Albert']
我有一本字典,上面有我的单词:我需要将它们替换为:
my_dict = {"Cat" : "Catty", "Dog" : "Doggy"}
我不需要寄存器大小写,这意味着算法应该是搜索偶数cAt
或DOg
。我知道我需要使用re.IGNORECASE
但是在哪里
我怎样才能做到这一点呢
这是一个很好的方法,但这里的输入只是一个字符串
s='hello, this is me'
replacements=[("hello", "hi"), ("this", "it's")]
for pat,repl in replacements:
s = re.sub(pat, repl, s)
我有一个字符串列表的输入
我的输出需要
['Doggy Austin', 'Catty Piter', 'Tiger John', 'Lion Albert']
您可以使用嵌套列表理解,并在
my_dict
中查找每个字符串中的单个单词:相关问题 更多 >
编程相关推荐