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.
why's it bad when it's contained in it's own method?
to me that seems cleaner and more understandable than just making a new variable for each step that only gets used once.
i read it and i more quickly understand "we're turning this data into this other type of data to do this thing." but with mutliple variables set up i see it and think "we're using this data to set up multiple variables to use later" but they don't really get used except for once and we've told the comp to remember stuff we only needed once, immediately after we told it to remember the information.
i get not wanting to just make a sort of catch all variable to be used wherever for whatever but if, like in this example, the purpose is to rearrange the digits of an integer and you have to convert that information to other types of variables to do so before turning it back to an integer then it seems more like using a feature of a language rather than abusing a feature of a language.
Oh yeah, I didn't even notice that he was assigning it to the same variable... that's not great lol.
I find the second option bad because, even though Python has dynamic typing, you shouldn't abuse that. Assigning every type under the sun to the same variable is, to me, a code smell
thanks for the reply!
so it's all just so fast anyway that no one would realistically notice any sort of difference unless it was with an absolutely stupid amount of things with no user input happening in between.
It doesn't really matter. If this kind of optimization is important to you, you should be writing ASM, and not python. Both solutions are very fast. Out of curiosity, I timed each solution. I tested each one on 200_000 random numbers between 100_000 and 1_000_000, reran each test 100 times and averaged their times together for each algorithm. The exact times aren't really important, but on average, the first solution you've listed is 6% faster than the second solution, at least on my machine and for the inputs that I've tested. This kind of "improvement" is totally useless. A lot of people on CW just like to write their solutions in as few lines as possible, especially when the exercise is so simple. You should really not worry about these kinds of "optimizations", in the real world, your boss would much rather you write code like in the second example than the first.
This comment is hidden because it contains spoiler information about the solution
what if we input 100001, would it return the value as 11 or 110000?
This comment is hidden because it contains spoiler information about the solution
Nice :)
this is actually difficult -_-
I thought that the goal was to reverse it
Not a kata issue
numis given as a number, solist(num)will just put that number as sole element into a list. It does not provide you with the digits of that number.Your solution does not work. The logic of your solution is incorrect. You are giving the variable the name of the built-in function str().
Set the spoiler flag when writing code or solutions. Comments are visible on the main page.
If you write code in comments, use markdown formatting. Here is the link. MarkDown
Loading more items...