+ 3
Rules to Python one-liners
I have been trying to get into one-liners. I am opposed to them from a readability stand point, but they are cool and fun and make me feel like something else ;) But, I get stuck more often than not. So, my question: Are there rules to one-liners? Is there specific one-liner syntax, in such that there are rules in Python (perhaps non standard rules) that are catered towards one-liners? Also, tips and tricks are welcome
2 Answers
0
Look up list comprehensions, generator expressions, lambda functions, ternary syntax and built-in functions. Those r the techniques used most often for writing one-liners. You should also get yourself acquainted with the star operator and double star operator (for dics). That's about it I think.
But honestly, it is usually not worth it.
0
i very rarly use them. Mostly I will use them if I am trying to generate something on the fly in a code âlike a Lambda situationâ but nothing else. I agree with the guys. Hard to read, maintain and I hate seeing them in a source code that is not mine, means hours of tail chasing.