Nikita Gupta Nikita Gupta - 7 months ago 28
Python Question

One line python code to remove all the strings that doesn't start with T or t and if they contain number greater then 6



Output should be:

I tried :

content = [item for item in List if terminal.lower().startswith('t')]

My doubt if I can append one more condition with the if I used in my code?

If yes, how?

I tried writing but it gives error.


Matching your required output requires using all and not in to check that none of the '789' characters are contained in your input string while also checking for the starting characters:

res = [s for s in List if s[0] in ('tT') and all(j not in s for j in '789')]

Now res contains:

['tata1', 'tata2', 'Tata3', 't2']