나는 이렇게 학습한다/Algorithm & SQL

1027. Filling an array (part 1)

daco2020 2022. 10. 28. 02:13
반응형

We want an array, but not just any old array, an array with contents!

Write a function that produces an array with the numbers 0 to N-1 in it.

For example, the following code will result in an array containing the numbers 0 to 4:

arr(5) // => [0,1,2,3,4]

Note: The parameter is optional. So you have to give it a default value.



Solution:

def arr(n: int = 0): 
    return [i for i in range(n)]


반응형