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.
I guess the Kata description changed. N won't be negative.
"You are given an array with positive numbers and a non-negative number N."
Same
I tried that and the system asked me something to the effect of "Where is the code?" and wouldn't let me submit it.
I think a lot of folk use single letters that imply a data type. I know I do.
e.g. c => characters, i => integer, l => list, e => generic element
probably bc I copied it ahah
I'm guessing they used c instead of d because it was returning a string, thus c for character?
Ya, I gradually worked my way to this little one-liner =)
It appears that Python is not as smart at optimizing things as you think. I never duplicate function calls if I can help it. The difference in performance is very small, admittedly, but nonetheless, repeatedly calling len generates LOAD_GLOBAL, LOAD_FAST, and CALL_FUNCTION opcodes in that order, each time you call len, as opposed to doing it only once to find the length and then generating a LOAD_FAST to call the locally stored value back up. Benchmarking with timeit, I find a slight but reproducible benefit to calling len only once. In functions where you use the value more than twice, the benefit is obviously even greater.
No additional cost overhead for calling len twice?
BTW, a cool variation is
from scipy.misc import comb
def find_dup(arr):
return sum(arr) - comb(len(arr),2)
There are a lot of problems with extremely simple solutions - I've missed a lot of them but practice is certainly helping :D definitely need more practice with lambda and when to use recursion though.
@MusicalCoder
,I also misspelled
string -> strng
on purpose. Since there is a module namedstring
in Python, I've found using it as a variable name can cause minor issues like this:Also, your solution does not need the square brackets inside of
''.join(...)
.