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.
That's a twoliner though.
This comment is hidden because it contains spoiler information about the solution
wow made a functionnal oneliner that actually is pythonic... yay
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Elegant. Congrats.
A lot of people think that this kata is easy.
Maybe it is, if you have a CS bacground
. I tried solving this 3 months ago and got stuck. That's only recently that I read about the stack data structure and the solution pricked up in my mind. I think 4ku is the right level for this kata.This comment is hidden because it contains spoiler information about the solution
He's making sure that
count[a]
is a number. You can think of it as a shortcut toNumber(count[a])
.You know what, that's actually a good point. In some cases you can be reasonably confident that the method you're writing will only concatenate a small number of strings or will not be run a huge number of times, so the difference in performance is going to be insignificant.
I should probably have phrased my initial response differently, along the lines of "yo, concatenating is ok in small doses, but .join() is a lot faster if you are gonna do that with a lot of strings; it also makes you look good on job interviews". Unfortunately, don't think I can edit it.
Cheers :)
Yes, string addition is slower than joining a list. But it's only significant if you are adding a lot of strings together.
Here's a nice article about this problem when the number of strings to be added are small The Sad Tragedy of Micro-Optimization Theater
When adding 2 or 3 strings together, it has no performance overhead whatsover compared to making a list and joining it.
And since this method is much more clear and pythonic, it is best practice.
Unfortunately this is NOT a 'best practice'. String concatenation using + operator is some 30 times slower than using "separator".join(iterator_to_be_joined).
For additional reading: https://waymoot.org/home/python_string/
Thank you.
Congrats man, elegant code.