Oh, that's good to know, thanks!
That's not true anymore (at least in some cases). CPython now includes an optimization where building up a string like this doesn't create any intermediate copies.
String concatenation in Python always results in a new object, meaning reconstructing s with repeated concatenation (+=) is an O(len(s)^2) operation.
From the docs:
"Concatenating immutable sequences always results in a new object. This means that building up a sequence by repeated concatenation will have a quadratic runtime cost in the total sequence length."
It's better to construct a list and join it after the fact, as appending to a list (a mutable object) is constant, regardless of the length of the list or s.
The description could be more condensed instead of pasting the whole rulebook into it.
500 random tests is too much, 100 is enough.
I know for this kata it is difficult to change it; but returning different data types is bad practice.
Ah ok, I understand. I was not sure how acceptable it was to use rounding in this kind of kata (which is supposed to emulate some kind of 'real world' requirement), where rounding issues could be considered a part of the task. But if it's bad CW practice I guess its bad CW practice.
You really do not need to import math, integer division with 1 should've done the job.
@mjaydenkim To reiterate, you should import math at the top of the tests, since you use math.floor within the tests. This will solve the error FArekkusu was getting.
round(2.675, 2) gives 2.67 instead of 2.68 because of floating point inaccuracies.
In any case, there are some specific values where this will happen, which is why doing decimal rounding over floating point range is a bad idea.
Not disagreeing with the proper method, but isn't that example correct? I don't understand the point you are making with it.
Current input method and rounding requirement is flawed anyway; try this:
test.assert_equals(ao5([2.675, 2.675, 2.675, 2.675, 2.675]), 2.68)
The proper method to it is to use Decimal object to parse time strings as decimals directly; see https://www.codewars.com/kata/round-and-round
The implementation of real_round provided by the kata is flawed: it doesn't accepts the ndigits optional parameter.
Also calling it real_round is disgustingly misleading; Banker's rounding is the real round since it's recommended by IEEE standard. The function should be called something faithful and accurate like round_half_up.
some info on setup of modules: https://docs.codewars.com/languages/python/authoring#imports
You shouldn't need to import math, I don't believe--I think you can just use real_round() without importing (since it's in the preloaded file) and without importing math (because math is imported in the preloaded file), at least when it's preloaded. import math has been moved to the initial solution, though. I'm sorry if I'm misunderstanding