Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If item in list contains a keyword remove it

I have a list of items

['InvalidAddressBecauseDestinationIsAlsoSource', 
'NotEnoughBalanceBecauseDestinationNotCreated', 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', 
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 
'BPFLoader1111111111111111111111111111111111',  
'gatbGF9DvLAw3kWyn1EmH5Nh1Sqp8sTukF7yaQpSc71', 
'ni1jXzPTq1yTqo67tUmVgnp22b1qGAAZCtPmHtskqYG', 
'mos1x4hXqmmmWz5s8btUsM1aHxdY3tUvNHf7sfK37Y6', 
'yukonJRbdjiiSMqXmMq3mVHsVTLg7FSzEpVwZU3fzzr', 
'tgaxdij8CgAbfDDkhtkvZgEtwLPrVEXTQe3L4zkA7gE', 
'tniC2HX5yg2yDjMQEcUo1bHa44x9YdZVSqyKox21SDz', 
'tmo7YXBjHgJ74StE7inz5XkyJQ5dq9CEy5YERZfx6iZ', 
'tyukPUmtWLzTx7YqJus93gBQ1u3tYispTJDXnQXp7Hp', 
'gatem74V238djXdzWnJf94Wo1DcnuGkfijbf3AuBhfs', 
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', 
'gatem74V238djXdzWnJf94Wo1DcnuGkfijbf3AuBhfs', 
'cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ', 
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', 
'EfLbqXBzgbXURKsjE5UTbf9khGW9Ck9UvzFr5Uyh53pw']

and I have a list of keywords
['meta', 'cndy', '11111111', 'Token', 'gate', 'Invalid', 'NotEnough']

and I want to remove items from the first list if they match any item in the second list

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried

LIST2 = ['meta', 'cndy', '11111111', 'Token', 'gate', 'Invalid', 'NotEnough']
finalResult = newlist = [m for m in LIST1if not any(k for k in LIST2 if k in ' '.join(m))]

but it doesnt work

>Solution :

You’ve got your membership testing wrong, you want:

finalResult = [m for m in LIST1 if not any(k in m for k in LIST2)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading