I have listA = [2,0,0,5,6,0] and listB = [4,5,7,3,2,1]. I want to merge these two list and get listC = [2,5,7,5,6,1]. So basically just copy listA but if an element in listA is zero, replace that element with element from listB
I tried using for and if loop but had no luck:
listC = []
for i in listA and listB:
if listA[i] == 0:
listC.append(listB[i])
else:
listC.append(listA[i])
I am new to python, so some explanation with solutions will be appreciated.