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.
Best practice for pythonist.
Elegant solution for 'if/else 0'. Every time forget about if, however met it several times before.
I dont C/P. I am printed, dude...
this is probably the fastest solution, possibly because it does not use the
**
(square) operator. I compared these top two solutions usingtimeit
Ok, this is genius!
i am ashamed of my solution now....
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This is the py2 habit. Py3 code would be more readable by simply using '/' (without the casting).
Some nasty mistakes I have made though when I forgot to use casting in C++ division.
Copy/paste from Details )
Correct– .sort() works inplace. While that reduces memory overhead, that is bad practice for most functions because of Python's implicit pass-by-assignment mechanic. The function would have the side-effect of sorting the original list, which might or might not cause a very difficult to find bug later.
AFAIK .sort() is method for lists and it doesnt return anything.
Ha! Seeing this it's suddenly so simple, I went on a bit of a diversion, oops!
that doesn't change anything.
Going once through the array or twice saying one is best than the other is like saying that
N*2
is worse/better than2*N
. Both are just the same, about time complexity. And for instance, this solution is more efficient beacuse of python's interpreter when it comes to compare actual perfs.Loading more items...