I have two lists:
listA = ['market', 'fraud', 'crime', 'security', 'public',
'state']
listB = ['security','fraud', 'state']
the elements present in listB needs to be in the same position of the elements of listA. If listA contains any element that listB does not contain, then I need to fill this empty position with the number 0. So far, I only added the zeros to listB (see below). How can I achieve this goal?
difference = len(listA) - len(listB)
c= 0
while c < b:
c+=1
listB.append(0)
my final output should look like:
listC = [0, 'fraud', 0, 'security', 0, 'state']
listC should contain 0 replacing the element that is not in listB. Strings that are present in listB should be in the listC in the same order (index position) they are in listA.