比较两个列表并获得数字差异 [英] Comparing two lists and getting the difference in numbers

查看:169
本文介绍了比较两个列表并获得数字差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解什么是最有效的方式来获取两个列表,例如

I'm trying to understand what the most efficient way to take two lists e.g.

[u'25.78',u'13.39' ,u'11.93',u'14.97',u'14.34',u'21.08',u'13.24',u'13.11',u'',u'19.45',u'17.56',u'20.57' u'28.50',u'24.38',u'31.13',u'17.20',u'18.52',u'6.42',u'17.31']

[u'20.77',u'24.08',u'17.66',u'14.63' u'24.40',u'42.14',u'21.93',u'30.37',u'15.20',u'21.94',u'34.20',u'18.47',u'19.05',u'24.31' u'13.55',u'14.44',u'32.53',u'18.00',u'19.95']

包含以下内容的新列表:

And get a new list with the following:

[u'5.01',u'-10.69',u'-5.73'] 等等。

我的大脑只是不理解如何做这个逻辑。我想要引用 for 循环,但我试图为循环里面的另一个<$ c

My brain just isn't comprehending how to do this logically. I keep wanting to refer to a for loop but I am trying to for a for loop inside of another for loop and it's messing me up.

推荐答案

关键是它迭代两个同时列出 zip

The key is it iterate over both lists at the same time. zip will pair items from each list.

给出 listA listB

[u'%0.2f' % (float(x) - float(y)) for x, y in zip(listA, listB)]

这篇关于比较两个列表并获得数字差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆