Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1540  / 1 Year ago, mon, march 27, 2023, 3:15:42

I have function which consists of 1 line. It is something like:



return [item for item in list if something_very_long and something_else_very_long] == []


How is it most appropriate to separate this statement to adhere to PEP-8 guidelines of keeping a maximum of 79 characters per line? I couldn't find an example like this in PEP-8 documentation.


More From » python

 Answers
5

The other answers say you should rewrite your list comprehension to a normal loop. It's much easier than that, and you can keep your list comprehension.



You can split wherever you want, it's the same as a statement with parentheses.



# Splitting too much just for the sake of example
return [item for item in list if
something_very_long and
something_else_very_long] == []

[#26522] Tuesday, March 28, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
asketbridiculou

Total Points: 168
Total Questions: 116
Total Answers: 115

Location: Antigua and Barbuda
Member since Sat, Jan 28, 2023
1 Year ago
;