One liners aren't common practice in production. Hard to read, prone to bugs. You really don't need a for loop here as you mainly need to specify the larger of the two numbers (math is weird I know) and run the SUM for the numbers in the RANGE.
Almost the same solution as me. But I wonder why this doesn't get an error "list index out of range", when i+5 are > len(digits). Can someone explain please?
Well since we are talking about words/sentences, they can be only so long, so I don't see why performance would play a huge part in this code. At least for the test cases both solutions are almost equal (sorted even being a bit faster).
If you split for example "a__b" (double space instead of underscores) into a list, it will result in ["a", "", "b"].
When you join it later, there will be one space between "a" and the empty string "" - and another space between the empty string and "b". Therefore you end up keeping the double space like in the original string.
It's easy with regex. Plus, I don't think this is Kyu 8. The author thought of what?
17 if else statements? lol
He/She should've put it as a dict...
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
One liners aren't common practice in production. Hard to read, prone to bugs. You really don't need a for loop here as you mainly need to specify the larger of the two numbers (math is weird I know) and run the SUM for the numbers in the RANGE.
This comment is hidden because it contains spoiler information about the solution
Almost the same solution as me. But I wonder why this doesn't get an error "list index out of range", when i+5 are > len(digits). Can someone explain please?
highly inefficient
cheater ;-)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Well since we are talking about words/sentences, they can be only so long, so I don't see why performance would play a huge part in this code. At least for the test cases both solutions are almost equal (sorted even being a bit faster).
True but you have to use floor division in that case, otherwise you will get an error for range doesn't work with floats
This comment is hidden because it contains spoiler information about the solution
If you split for example "a__b" (double space instead of underscores) into a list, it will result in ["a", "", "b"].
When you join it later, there will be one space between "a" and the empty string "" - and another space between the empty string and "b". Therefore you end up keeping the double space like in the original string.
This comment is hidden because it contains spoiler information about the solution
Loading more items...