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.
how does this one peform the multiply by 9 on odds?
This comment is hidden because it contains spoiler information about the solution
Thank you so much, you put it so clearly to understand, I learned something new today! Greatly appreciated!
Hi yellowboyvn,
When you set your parameter (n) to something, you are saying you want that "something" to be your default value in case the funcion is called without a value. It prevents errors.
So, if we call our function empty, it will assume the input is 0 in our case (or any value you have assigned to it).
Hope that helps!
Hello I saw the comments for the problem but I do not quite understand what n=0 means in the parameter. I know that not setting n=0 will raise an error, would you (or somebody) mind explaining that to me please? Thank you kind person!
Hi Hugolarzabal,
Thank you very much!
I get it now. A quick follow up. The answer above doesn't have the f.
Is that f necessary?
Thank you again!
Josh
This comment is hidden because it contains spoiler information about the solution
Hi Josh,
Yeah, it can be a little hard in the beginning.
"i for i" (or "x for x", etc.) starts a loop that checks every element in the array in order.
For example, if you array is ['A', 'C', 'X', 'D'], it will first do ['A'] then ['C'] then ['X'] and finally ['D']. It puts them all together and returns that.
Maybe it's better you write it as "element for element" because the output will be the same.
And if you change it to "1 for element" it will do 1 for each element so the output will be [1, 1, 1, 1] in the same example.
Hope that clears it a little bit,
S
Can you please explain to me what the [i for i] part of the list comprehension means in plain English?
I still have trouble understanding that.
Thank you very much!
Josh
Sometime, it may be so tempting to take it the easy way: a O(1) brain even for a O(n²) computer… :)
It's all about brain/computer ratio! Looks like I didn't have the O(n) brain that time.
No need to be sorry! I just post this kind of comment on highly upvoted answers so that beginners can see it and look for a more efficient solution.
But having seen some of your other solutions, I know very well that you can do it in O(n).
Yes sir. Sorry about that. There was no pretension, anyway :)
This recalculates the sum everytime so this is O(n²).
I had the same problem like yours...no clue
This comment is old but the problem is still there.
The description should state if boolean should be considered as numbers or return None.
At the monent random tests expect None if there is a boolean in the area but very rarely test this kind of array (usually there would also be a letter in the array)
Loading more items...