I am trying to check the elements of two lists in python to see if they contain the same values in the same position (indexes) of them. If an element let's say in position 0 of list A is not the same with the element in position 0 of list B I want to extract that value from list A and start again the comparison.
My program is below:
listA = ["book","2","stage","me","you"]
listB = ["stage","me","you"]
listB is always a sublist of listA!!
diff_list = []
for n in range(0, len(listA)):
for k in range(0, len(listB)):
if n == k:
if listA[n] != listB[k]:
rm_item = listA.pop(n)
diff_list.append(rm_item)
k==0
print(k)
In my terminal first k = 0 then k = 1. Is there a way to remove the item from listA and then start the comparison again?
Thanks for the help guys! To be honest....What I wish to do is to get the difference between two strings. I have two texts where text B is always subtext of text A. So I used splitlines() to split the two texts and then I want compare the two lists to get what I want! Sorry but I am new to python and still can't figure out how a lot of things are done!
So I have
textA='The first paragraph of the book is written well'
and
textB = 'the book is written well'
the result should be
text_diff ='the first paragraph of'