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.
timeit is the best way to check execution time of code
I like your comment. Thanks!
you god damn right
sum() accepts any iterable so it's not necessary (and actually slower) to materialise the list before passing it to sum. You can leave out the square brackets in which case this will work like a generator expression and pass individual values to sum as sum requests them.
Another thing learnt today! :D
This comment is hidden because it contains spoiler information about the solution
Looks like the timings were not gathered with a tool like Timeit. For small snippets of code, which are affected most by even smallest stuff your CPU can be doing in the background, you should use modules like timeit (or the %timeit in ipython) which will run your snippet multiple times, millions of loops each, to average the result. Timeit can also set up the environment for you (like imports) and not count time for it. For me, in a timeit test of 7 runs, 10 million loops each the results are 30.3ns/27ns/26.3ns confirming the common sense that the sign flip on the int - being a single-bit operation - is the fastest (obviously there is Python layer on top of this but it applies to all three approaches). Hopefully I'm not coming through as a smartass, I "discovered" timeit just recently myself!
Not really, with enough number of executions the differences in individual runs should diminish and you will see true performance difference between the solutions. That's why for small snippets of code, which are affected most by even smallest stuff your CPU can be doing in the background, you should use modules like timeit which will run your snippet 10-100 thousand times to average the result. Timeit can also set up the environment for you (like imports) and not count time for it.
Hi, I wonder if this would pass the current test set where there's "0" at the index position 0 (which you skip), which should appear in the resultset.
This comment is hidden because it contains spoiler information about the solution
It's good to be aware of performance considerations, but in this case it would almost certainly be premature optimisation (a mistake) to consider it. The actual runtime difference is less than a microsecond.
The most performant of the top approaches here, Best Practices from me!
Clever use of max() there! That said, in this arrangement the interpreter will evaluate all the operations so not the most performant of options.
Hi, I don't think it needs to - range of inputs is provided in the instructions.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Loading more items...