Ad
  • Custom User Avatar

    how does this one peform the multiply by 9 on odds?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Thank you so much, you put it so clearly to understand, I learned something new today! Greatly appreciated!

  • Custom User Avatar

    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!

  • Custom User Avatar

    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!

  • Default User Avatar

    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

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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

  • Default User Avatar

    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

  • Default User Avatar

    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.

  • Custom User Avatar

    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).

  • Default User Avatar

    Yes sir. Sorry about that. There was no pretension, anyway :)

  • Custom User Avatar

    This recalculates the sum everytime so this is O(n²).

  • Default User Avatar

    I had the same problem like yours...no clue

  • Default User Avatar

    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...