0
def generate(numRows):
    pascal = [[1]*(i+1) for i in range(numRows)]
    for i in range(numRows):
        for j in range(1,i):
            pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j]
    return pascal

for the second line of the code, there is a for loop statement inside the list initialization, what's the difference between that and

for i in range(numRows):
    pascal = [[1]*(i+1)]

I know for the second one, pascal will be overwriting every loop, but if I'd like to have the same result as the original one, how should I change the code?

SuperGuy10
  • 471
  • 5
  • 5
  • 1
    The term you're looking for is "list comprehension". Once you start searching on that, you'll find explanations that should clarify things, such as the answers to the question suggested as duplicate. –  Mar 21 '18 at 03:06
  • Thank you so much for help! – SuperGuy10 Mar 22 '18 at 02:40

0 Answers0