Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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
在lambda表达式python中插入变量值_Python_Python 3.x_Python 2.7 - Fatal编程技术网

在lambda表达式python中插入变量值

在lambda表达式python中插入变量值,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我有一个场景,我试图将变量值放入lambda函数中,但它似乎不起作用,并且忽略了值,没有错误 a_name = ['APP-1 extension check', 'APP-1 b2b check', 'APP-1 no checks'] ape_t = content['data'] # ape_t contains result APP-1 ape_d = str(ape_t) # this becomes 'APP-1' ape_f = ape_d + ' ' # this becomes

我有一个场景,我试图将变量值放入lambda函数中,但它似乎不起作用,并且忽略了值,没有错误

a_name = ['APP-1 extension check', 'APP-1 b2b check', 'APP-1 no checks']
ape_t = content['data'] # ape_t contains result APP-1
ape_d = str(ape_t) # this becomes 'APP-1'
ape_f = ape_d + ' ' # this becomes 'APP-1 '

tempda=list(map(lambda x: x.replace(ape_f,''),a_name)) # here I want to get the variable value of ape_d 
which is 'APP-1 '
当我运行这个时,我希望我的输出是
[“扩展检查”、“b2b检查”、“无检查”]

但是相反,它给出了电流输出
['APP-1扩展检查','APP-1 b2b检查','APP-1无检查']


如果这里缺少任何东西,请提供帮助。

您的代码似乎很好。首先验证
ape\u f
是否包含所需的字符串。然后,如果要查看要修改的原始列表
a_名称
,请将修改分配回
a_名称

更改
tempda=list(映射(lambda x:x.replace(ape_f.),一个名称))


a_name=list(映射(lambda x:x.replace(ape_f.),a_name))



希望这有帮助

您需要提供一个获取预期输出的示例。您不能只对名称中的项目执行
[item.split(“”,1)[-1]
?您可以显示一个内容示例吗?您可以澄清您的问题吗?如果我运行你的代码,它会产生你期望的输出,所以我不理解你的问题。。。