Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yeah but... This is just a simple one-liner. So it's still pretty readable, for me at least
Python noob here, I gotta say Python one-liners like list comprehension are starting to look pretty understandable (at this level of complexity, at least...)
But cramming logic that repeats on each 'x' doesn't look good for Big O, for sure.
You are absolutely right! However, in codewars I view 1-line solutions more like a mini-achievement of making a code in one line, rather than the practical solution and I think there can't be good argument against writing your code in a more coherent way, naming almost every variable in an understandable way so others didn't have the hard time reading your code
Nitpicks: 1. you could use list comprehension which I believe is not necessarily unreadable (i.e. it doesn't violate "just because you can doesn't mean you should") 2. no need to calculate len(string) every time.
But overall, +100 for "just becuase you can doesn't mean you should". Production code is generally not a place for showing off, it's also a tool to communicate with other people.
Less code does not mean less instructions unless you are writing assembly.
Even then each instruction can run a varied amount of cycles.
Understanding time & space complexity ie. big O and applying that wisely is more important than less lines.
Isn't it for efficency? I assume that in a large project with mutiple one liners helps reduce the runtime of the program significantly and speed is key in any project. and its not like this is a very advance code, its very logical. I dont know the industry standard but this just my thoughts from a aspiring data scientist
This solution is more concise and efficient, while at the same time still very readable.
yeah i dont know if it sends the right message for beginners.
Thanks. Exactly my thoughts when I started learning doing these unreadable one-liners. Is it cool to utilize the features of Python to achieve this? Yes. Would I do it in my professional work? Hell no.
On the other hand, should I code in the C-like program structure? This is a lot one tends to do when coming from C/C++ background, but that would be a great underutilization of Python features, so why work with Python in the first place...
As with many things in life - the truth lies somewhere in between. :)
I never thought about it this way before. Thank you, your text was an eye opener for a beginner like me.
long text
assembly fan
You are welcome, glad you learn something through it ;-)
You were right about documentation so here is a fork of this solution, explaining it step-by-step.
This comment is hidden because it contains spoiler information about the solution
If you do this (I don't know if this cheat is still working), you will just get banned :) There are filters to detect this kind of code and the moderators are not happy with it...