I have written the following code that works and the output is what it is expected :
myList1=[[1,2],[3,4],[5,6]]
myList2=["abc","def","ghi"]
myList3=[]
for i in range(3):
temp=myList1[i]
temp.insert(0,myList2[i])
myList3.append(temp)
print(myList3)
But when I try to write the same code without the temp variable, it does not work.
myList1=[[1,2],[3,4],[5,6]]
myList2=["abc","def","ghi"]
myList3=[]
for i in range(3):
myList3.append(myList1[i].insert(0,myList2[i]))
print(myList3)
And this code, also, does not work.
myList1=[[1,2],[3,4],[5,6]]
myList2=["abc","def","ghi"]
myList3=[]
for i in range(3):
temp=myList1[i].insert(0,myList2[i])
myList3.append(temp)
print(myList3)
I think there are some python fundamentals that I have not understood.
Any comments and help will be appreciated.
Thanks for answer
.insertreturnsNoneso you getNone,None,NoneNone.