python对两个list中的所有对应元素进行数学运算

公式是 Rd =(Ub-Ua)/Ua 结果需要用百分比输出 python3.5
#!/user/bin/env python3
# -*- coding: utf-8 -*-
Ua = [25185,8041,60212,12825,80808,32736,18515]
Ub = [27655,2163,42554,35335,47601,34418,11615]
def fn()
return (y-x)/x*100 for x,y in zip<Ua,Ub>
print('Rd:%s',%%%fn)

求指导怎么修改一下比较好
主要是主函数的语法有错误 希望大神能够帮助我

可以对第二个list的元素进行遍历,检查是否出现在第二个list当中,如果使用表理解,可以使用一行代码完成任务。 list1 = [1,2,3,4,5]list2 = [4,5,6,7,8]print [l for l in list1 if l in list2]# [4,5]如果每一个列表中均没有重复的元素追问

诶 其实我是想问如何完成这个两个list对应元素进行数学运算再输出一个新的list的程序,因为原始的两个list实际上是手动输入的 所以并不用检查重复元素这样子。。。

温馨提示:内容为网友见解,仅供参考
第1个回答  2021-03-12
for index, i in enumerate(baiban):
avg.append((i+wanban[index])/2)
print(baiban, wanban, avg)
----------------------------
[0.82, 0.68, 0.82, 0.81, 0.62, 0.84, 0.69, 0.84] [0.83, 0.77, 0.81, 0.83, 0.81, 0.84, 0.82, 0.81] [0.825, 0.7250000000000001, 0.815, 0.8200000000000001, 0.7150000000000001, 0.84, 0.7549999999999999, 0.825]
第2个回答  2021-03-15
return [(b-a)/a*100 for a in Ua for b in Ub]