1
height = 5
empty_pyramid = [['*'] * (height * 2)] * height



empty_pyramid2 = [['*','*','*','*','*','*','*','*','*','*'], ['*','*','*','*','*','*','*','*','*','*'],
                ['*','*','*','*','*','*','*','*','*','*'], ['*','*','*','*','*','*','*','*','*','*'],
                ['*','*','*','*','*','*','*','*','*','*']]

if empty_pyramid == empty_pyramid2:
    print(True)

Both print True, but when put through a for loop the operations done on each iteration through empty_pyramid2 will only affect the current element (ie: ['*','*','*','*','*','*','*','*','*','*'])

while each operation done on empty_pyramid's current element is applied to the other elements as well.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
David Ip
  • 11
  • 1
  • What operation are you doing and what are the results in question? – DaveStSomeWhere May 09 '20 at 00:13
  • i'm looping through each element and replacing some '*' with numbers, building a triangle essentially. For example, the first layer replacing the first and last asterisk. The second layer replacing the first 2 and last 2 asterisk. But the for loop is applying changes to every element in empty_pyramid each time, so the end result is a pyramid consisting of all layers identical to what should be only the last layer (all numbers). – David Ip May 09 '20 at 00:30
  • Got it - the linked answer in the closed message explains the behavior. – DaveStSomeWhere May 09 '20 at 00:33

0 Answers0