I'm not sure many of these one-liners make your code more fun to read.

The list comprehension example was good. But the map and filter examples would also have been far better as list comprehensions too. There are good uses for map and filter, but converting one list into another list isn't one of them. The filter example took 6 lines but could have easily been done as a simple one line list comprehension.

Why use reduce to sum a list of numbers, when you could just use sum()? Why use a lambda to create a function to add two number when you could just use add()? Why use list slicing to reverse a list when the reverse function is clearer and (you yourself claim) more efficient?

I don't mean to be negative, but these are presumably meant to be tips to help beginners improve their coding style, and I think some of them are actually not good practice. It might be worth modifying some of the examples a little.

Written by

I am a software developer with over 30 years experience in Java, Python and C++. I write for pythoninformer.com.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store