How to do this code in oneliner ?
1/10/2020 9:33:17 PM
print(list(i for i in 'q1w2e3r4t5y' if i.isalpha()))
This is the one-liner:
print([i for i in txt if i.isalpha()])
Here is short tutorial, how to turn a for loop to a one-liner:
There is also an other way to do it by using print() inside the squared brackets: ( it does not need to have ''.join() , it's like using print in a for loop)
[print(i, end='') for i in txt if i.isalpha()]
It's actually list comprehension not oneliner yet.
print([i for i in "q1w2e3r4t5y" if i.isalpha()])
Nice concept Lothar, I will try that
Thank you !😊
Send us a message