Skip to content

Latest commit

 

History

History
43 lines (25 loc) · 574 Bytes

Pyramid_Array.md

File metadata and controls

43 lines (25 loc) · 574 Bytes

CodeWars Python Solutions


Pyramid Array

Write a function that when given a number >= 0, returns an Array of ascending length subarrays.

pyramid(0) => [ ]
pyramid(1) => [ [1] ]
pyramid(2) => [ [1], [1, 1] ]
pyramid(3) => [ [1], [1, 1], [1, 1, 1] ]

Note: the subarrays should be filled with 1s


Given Code

def pyramid(n):
    pass

Solution

def pyramid(n):
    return [[1 for _ in range(i)] for i in range(1,n+1)]

See on CodeWars.com