I am trying to add data in a list. I used a temp list , swaping its data to another list b and then clearing its data in each iteration When using temp.clear() , my final output is empty.But when using temp = [] i get right output.
Kindly tell why different output is there when using temp.clear() and temp = [].
a=['apple','pizza','veg','chicken','cheese','salad','chips','veg']
b=[]
temp=[]
for i in range(len(a)):
temp.append(a[i])
b.append(temp)
temp.clear()
#temp = []
print(b)
Output
#temp.clear()
[[], [], [], [], [], [], [], []]
#temp = []
[['apple'], ['pizza'], ['veg'], ['chicken'], ['cheese'], ['salad'], ['chips'], ['veg']]