[英]How to compare list of lists with another list in Python?
a=[('3.25% GLN State Bank of India, London Br 2013-18.4.18 Global Sr Reg S (21163588)', '100,000.00', '100,040.00', '-1,755.00', '-1.72%'), ('Uts Muz ShortDur Acc.Units Class -R- Hedged USD (11851008)', '3,750.00', '463,500.00', '14,252.14', '+3.17%'), ('Shs PIMCO Income Accum.Shs Class -E- USD (20152466)', '48,433.,074', '655,783.82', '54,814.53', '+9.12%'), ('7.625% NTS Trafigura Group Pte Ltd 2013-WFM C red. 19.4.18 at 100% (21144967)', '200,000.00', '204,574.31', '28,310.00', '+16.44%'), ('2.5% NTS Glencore Funding LLC 2013-15.1.19 Reg-S Senior (21488623)', '160,000.00', '159,432.00', '26,376.00', '+19.82%'), ('6.25% NTS Deutsche Bank AG 2014-Without Fixed Mat Variable Rate Reg-S (24513566)', '400,000.00', '401,846.01', '15,420.00', '+4.05%')]
和
b=['Shs PIMCO Income Accum.Shs Class -E- USD (20152466)', '48,433.,074', '655,783.82', '54,814.53', '+9.12%']
如何比较这两个列表?
for list1 in list2:
return True
如果我通过传递 b 中不存在于列表中的任何其他元素来超越事物,那么它也会传递 True。
如果您的目标是检查a
的一个列表是否是列表b
,您应该b in a
。
但是,这将返回False
,因为a
是一个元组列表,而b
是一个列表。 然后,你有三个解决方案:
a
更改为列表列表(将(.)
更改为[.]
)b
变为元组b=('Shs PIMCO Income Accum.Shs Class -E- USD (20152466)', '48,433.,074', '655,783.82', '54,814.53', '+9.12%')
tuple(b) in a
(这会在测试前将b
转换为元组)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.