FWIW, I pasted those solutions into an online benchmarking tool: https://perfpy.com/50

The last example doesn't seem to run as-is. I'm low on energy and not a Pythonista; I did the bare minimum to get it to work.

The last, tersest*, one seems to be ~3000x worse in terms of speed. The others are much of a muchness, almost identical. I ran the benchmark a few times and 1, 2, and 3 switched places almost every time; none was so much more performant that it took the number one spot every time.

So, even more of a reason to avoid code-golf!

The first rule of optimisation club is "profile your code!"

* To be fair, terseness often seems to be the primary goal of golfing solutions, over performance.

--

I’m a Senior Software Developer at Flick Electric where I write mostly Ruby on Rails. I also dabble in any language that takes my fancy.

Love podcasts or audiobooks? Learn on the go with our new app.

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
Adam Henley (He/Him)

Adam Henley (He/Him)

97 Followers

I’m a Senior Software Developer at Flick Electric where I write mostly Ruby on Rails. I also dabble in any language that takes my fancy.