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?
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)