I am completely new in Python and have a purpose. The professor asked us to look at examples of users coding the Pascal Triangle in Python, for something that would be "similar."
I managed to find several ways to encode it, but I found that several people are using some kind of code that I do not understand.
Essentially, I'm looking to find out what this means (or does) when you see a list or variable that has two square brackets side by side. Code example:
pascalsTriangle = [[1]] rows = int(input("Number of rows:")) print(pascalsTriangle[0]) for i in range(1,rows+1): pascalsTriangle.append([1]) for j in range(len(pascalsTriangle[i-1])-1): pascalsTriangle[i].append(pascalsTriangle[i-1][j]+ pascalsTriangle[i-1][j+1]) pascalsTriangle[i].append(1) print(pascalsTriangle[i])
You will see that line 7 has the following:
pascalsTriangle[i].append(pascalsTriangle[i-1][j]+pascalsTriangle[i-1][j+1])
I know that square brackets are lists. I know that square brackets in square brackets are lists inside / lists. Can someone describe what the square bracket does next to the square bracket?
source share