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.
Python doesn't have arrays and the code above isn't creating a list either. It's creating a generator and the creation specifically takes almost no resource, since the values are generated lazily.
AFAIK the difference comes from the code above calling isdigit function a lot of times, whereas replace is only called 10 times. Keep in mind, that both of the functions are highly optimized and written in C, so that's why the the code with more function calls and more python is slower. That also for example causes some O(n^2) algorithms to run faster in python, than an O(n log n) alternative.
Sorted is O(n log n) complexity, both sorted and sort use the same algorithm behind the scenes. Creating a list is O(1).
This comment is hidden because it contains spoiler information about the solution
i did same thing but i just said arr != None its acccepted too here >1
really nice
yeah I used .isnumeric lol
Bc creatin new array is more time and resource consuming. Using regex is BP for this case. My advise for everyone: learn what is regix (import re) and how to use it
This is wrong. When we do
min
andmax
, there is no sorting happening under the hood, for a total of zero times.Why is it so? I solved with 'min' and 'max' too, but now I think that 'sort' could be more efficient.
When we do 'max' and 'min' - there is some kind of sorting happening under the hood for two times.
But using 'sort' - sorting happens just once.
According to tests from 'pprunesquallor' - 'sort' is more efficient. As you said - only for short lists.
What lists are long? What is the len value after which 'sort' becomes less efficient?
And why?
But didn't it takes more time for slicing, if there is long list? And what if we check "len(arr) > 2" instead of "len(arr) > 1". Wouldn't it be faster?
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
An empty list is false(y), so it tests if the list (
arr
) is empty or notWhy 'arr' is used as condition?
drodger, Thx.
PavlovNikita,
This is only a 'clever' way to solve it and not either the only way to solve it or the most readable way to solve it. I personally prefer longer code when it is more easily readable. However, sometimes, it is efficient to do it in a single-line/shorter-code.
After joining codewars, I have tried to be terse with code to learn terseness. So, now, I try to balance both as ultimately code needs to be read and re-read and maintained.
Thx
Loading more items...