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

How to remove a list item from another list based on an element's string

I have a list like this:

watchlist = [['NSE:SHIL',1],['NSE:SOLARA',1],['NSE:LINCOLN',1],['NSE:KITEX',1],['NSE:PPL',1],['NSE:PHILIPCARB',1],['NSE:SARLAPOLY',1],['NSE:PANAMAPET',1],['NSE:RPSGVENT',1]]

I want to remove the element list which contains the string ‘SOLARA’. New watchlist should be like this:

watchlist = [['NSE:SHIL',1],['NSE:LINCOLN',1],['NSE:KITEX',1],['NSE:PPL',1],['NSE:PHILIPCARB',1],['NSE:SARLAPOLY',1],['NSE:PANAMAPET',1],['NSE:RPSGVENT',1]]

How do I do that?

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

thanks in advance

>Solution :

Here’s one way you could do it:

watchlist = [['NSE:SHIL',1],['NSE:SOLARA',1],['NSE:LINCOLN',1],['NSE:KITEX',1],['NSE:PPL',1],['NSE:PHILIPCARB',1],['NSE:SARLAPOLY',1],['NSE:PANAMAPET',1],['NSE:RPSGVENT',1]]

watchlist = [e for e in watchlist if not 'SOLARA' in e[0]]

print(watchlist)
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