Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何用一个所需的输出替换字典列表中的字符串_Python_List - Fatal编程技术网

Python 如何用一个所需的输出替换字典列表中的字符串

Python 如何用一个所需的输出替换字典列表中的字符串,python,list,Python,List,我想用名为gRep1Map的字典替换lst中列出的名为test1的字符串。它需要使用gRep1Map中的字符返回原始字符串和单词变体。似乎真的找不到实现这一目标的方法 这是我的密码 gReplMap = { 'a': '@', 'e': '3', 'i': '1', 'o': '0', 't': '+', 'A': '@', 'E': '3', 'I': '1', 'O': '0', 'T': '+' } m = str.maketrans(gReplMap) lst =

我想用名为
gRep1Map
的字典替换
lst
中列出的名为
test1
的字符串。它需要使用
gRep1Map
中的字符返回原始字符串和单词变体。似乎真的找不到实现这一目标的方法

这是我的密码

gReplMap = { 'a': '@', 'e': '3', 'i': '1', 'o': '0', 't': '+',
         'A': '@', 'E': '3', 'I': '1', 'O': '0', 'T': '+' } 

m = str.maketrans(gReplMap)

lst = ['test1']
# ??
lst = [ pswd.translate(m) ]
if pswd not in lst: lst.append(pswd):
# ??
print(lst)
期望的输出应该是这样的

 ['test1', '+3s+1']

有谁能帮忙吗?

你可以这样做:

lst = ['test1', 'test1'.translate(m)]
print(lst)
输出为:

['test1', '+3s+1']

很有魅力,谢谢。