Ad
  • 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