nums = [1,1,1,2,2,0,3]
lst1 = [[]] * (len(nums) + 1)
lst2 = [[] for i in range(len(nums) + 1)]
print(lst1) #[[], [], [], [], [], [], [], []]
print(lst2) #[[], [], [], [], [], [], [], []]
lst1[3].append(2)
lst2[3].append(2)
print(lst1) #[[2], [2], [2], [2], [2], [2], [2], [2]]
print(lst2) #[[], [], [], [2], [], [], [], []]
Why does lst1 append the element everywhere? Is it because only one empty list is created and is shared by reference? Why would that even be useful?