Skip to content

Latest commit

 

History

History
55 lines (29 loc) · 682 Bytes

Filling_an_array_part_1.md

File metadata and controls

55 lines (29 loc) · 682 Bytes

CodeWars Python Solutions


Filling an array (part 1)

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]

Given Code

def arr(n):
    # [ the numbers 0 to N-1 ]

Solution 1

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

Solution 2

def arr(n=0):
    return list(range(n))

See on CodeWars.com