Can anyone please explain the output i am getting. As the first time the variable lists
is blank but when data[i]
i.e 10
appended to the lists[i]
it becomes
List: [[10], [10, [10]]
I dont know how come this long list comes in. I am new to python struck to trace its behavior. Here is the code
data = [10, 20, 30]
list1 = list2 = list3 = list()
lists = [list1, list2, list3]
for i in range(len(data)):
lists[i].append(data[i])
print '-------------------'
print 'at %s' %(i)
print ' List: %s' % (lists)
print ' Data: %s' % (data[i])
And response
-------------------
at 0
List: [[10], [10], [10]]
Data: 10
-------------------
at 1
List: [[10, 20], [10, 20], [10, 20]]
Data: 20
-------------------
at 2
List: [[10, 20, 30], [10, 20, 30], [10, 20, 30]]
Data: 30