A =['name','age','sex']
B =['张三',18,'女']
新字典:{'name':'张三','age':18,'sex':'女'}from functools importreduce
A =['name','age','sex']
B =['张三',18,'女']
result =map(lambda element1, element2:(element1, element2), A, B)
message =['你好',20,'30',5,6.89,'hello']
结果:31.89# 方法一
message =['你好',20,'30',5,6.89,'hello']
result =reduce(lambda x, y: x +(y iftype(y)in[int,float]else0), message,0)print(result)# 方法二deffun1(list1:list):
sum1 =0for element in list1:iftype(element)in[int,float]:
sum1 += element
return sum1
message =['你好',20,'30',5,6.89,'hello']print(fun1(message))# 方法三
message =['你好',20,'30',5,6.89,'hello']deffun2(list1:list):
new_string =[]for x in list1:iftype(x)in[int,float]:
new_string.append(x)return new_string
result =reduce(lambda x, y: x + y, fun2(message),0)print(result)