'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%')]
and
b=['Shs PIMCO Income Accum.Shs Class -E- USD (20152466)', '48,433.,074', '655,783.82', '54,814.53', '+9.12%']
how to compare these two lists?
for list1 in list2:
return True
if I above thing by passing any other element in b that is not there in list then also it passes True.
Solution 1:[1]
If your objective is to check that one list of a
is the list b
, you should test b in a
.
However, this will return False
since a
is a list of tuples and b
is a list. Then, you have three solutions:
- Change
a
into a list of list (change the(.)
by[.]
) - Change
b
into a tupleb=('Shs PIMCO Income Accum.Shs Class -E- USD (20152466)', '48,433.,074', '655,783.82', '54,814.53', '+9.12%')
- Do not change the input data and use
tuple(b) in a
(this will castb
into a tuple before the test)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Raida |