0

I was using list comprehension in Python. But my program behaves differently based on the way how I initialize the variable

  1. Works as expected if am using below piece of code temp = [[-1 for y in range(k + 1)] for x in range(n + 1)]

  2. It behaves strange if am using below code temp = [[-1]*(k+1)]*(n + 1)

what is the difference between both the ways of initializing the variable

0 Answers0