oneliner py | Sololearn: Learn to code for FREE!

+5

oneliner py

Hi, How to do this code in oneliner ? Thx ! https://code.sololearn.com/cK4bo2N1FfMR/?ref=app

1/10/2020 9:33:17 PM

lolo

7 Answers

New Answer

+6

print(list(i for i in 'q1w2e3r4t5y' if i.isalpha()))

+7

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: https://code.sololearn.com/cqnGujvL7CXe/?ref=app

+7

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

+6

It's actually list comprehension not oneliner yet. print([i for i in "q1w2e3r4t5y" if i.isalpha()])

+4

Welcome 😁👍

+4

Nice concept Lothar, I will try that

+3

Thank you !😊