Are one liners always pythonic?

MiguelMJ - Dec 16 '20 - - Dev Community

First of all, if you don't know what pythonic means, see this question.

I love clean code as much as anyone, but I think we all agree that there should be a limit on how much you put on a single line of code.

For example, looking at some examples on the Python wiki I came across elegant one liners like:

# Palindrome Python One-Liner
phrase.find(phrase[::-1])

# Find indices of x in a list lst
indices = [i for i in range(len(lst)) if lst[i]==x]
Enter fullscreen mode Exit fullscreen mode

but also some others that I don't find that much clean:

# Quicksort Python One-liner
lambda L: [] if L==[] else qsort([x for x in L[1:] if x< L[0]]) + L[0:1] + qsort([x for x in L[1:] if x>=L[0]])
Enter fullscreen mode Exit fullscreen mode

Do you have any criteria to limit your one-liners? Or don't you mind about the length of a line as long as it does the work?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player