see the comments below. this solution was written in Pyrthon 2. Python 3 changed the round() function for halfway cases: it used to be half away from zero (0.5 --> 1, 1.5 --> 2), now it's half towards the nearest even integer (the so-called "banker's rounding"): (0.5 --> 0, 1.5 --> 2)
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.
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
see the comments below. this solution was written in Pyrthon 2. Python 3 changed the
round()
function for halfway cases: it used to be half away from zero (0.5 --> 1
,1.5 --> 2
), now it's half towards the nearest even integer (the so-called "banker's rounding"): (0.5 --> 0
,1.5 --> 2
)How come when I did it it was incorrect????
Which verion did you do?
Me too.
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.
Nice mathy kata, perfect.
Approved
python new test framework is required. updated in this fork
This should not pass.
atleast python: no random tests
python new test framework is required. updated in this fork
yeah I used .isnumeric lol
Thank you so much @stok
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
Yes!!!
This comment is hidden because it contains spoiler information about the solution
Loading more items...