📜  python替换所有列表 - Python代码示例

📅  最后修改于: 2022-03-11 14:46:42.809000             🧑  作者: Mango

代码示例1
def ReplaceAllInList(list, lookupvalue, replacewith):
    return [(replacewith if v == lookupvalue else v) for v in list]

a = ['aaa', 'bb', 'bb']
a = ReplaceAllInList(list= a, lookupvalue= 'bb', replacewith= 'cc')
print(a)  # output --> ['aaa', 'cc', 'cc']