oneliner py | Sololearn: Learn to code for FREE!


oneliner py

Hi, How to do this code in oneliner ? Thx !

1/10/2020 9:33:17 PM


7 Answers

New Answer


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()])


Welcome 😁👍


Nice concept Lothar, I will try that


Thank you !😊