I am sorry if the title is little confusing but its not really that complicated either. I am trying to implement a logic where I will be just printing out list items which have correct order as per another list. For example let's say I have following lists:
a = [(299,70), (323,70), (448,70), (548,70), (613,70), (745,70)]
b = [(613,70), (448,70), (548,70), (323,70), (299,70)]
What I want
I want to print output of such elements in list b which are in same order as in list a. In above case it can be seen that only two elements are following the order in b and they are:
c= [(448,70), (548,70)]
P.S. I am comparing b with a and intending to keep the order of b same as it was generated in my program. I DON'T want to use any sorting method that can alter the order of existing b list.
The reason for not using sorting is the task I am working on has a list as a reference and b list is my implementation. so after b is generated I simply want to print such elements which have matching order without altering(changing order) any element during comparison.
What I tried
I tried comparing indexes of numbers inside the list instead of values, but it yields no satisfactory results. Additionally this method fails terribly when two lists are of different size as in above case.
EDIT:
Sorry for all the confusions. As asked here is one more example of same kind and more clear description of what I want.
I have two lists of tuples as given below:
list1 = [(1,2),(3,4),(5,6),(7,8),(9,10)]
list2 = [(1,2),(5,6),(3,4),(7,8),(9,10)]
I want to print out consecutive pairs of tuples in list2 which are in same order as given in list1. So in this example the output should be
list3 = [(7,8),(9,10)]
No matter what is the size of both the lists, what I want is only the common consecutive tuples to be printed which are present in both.
bwhich follow the order froma? the longest string of consecutive elements frombwhich follow the order froma? the longest string of consecutive elements frombwhich appear consecutively and in the same order ina? to take the first element frombwhich appears ina, then the next element frombwhich appears later ina, and so on? all pairs of elements frombwhich appear in the same order ina? things which appear in the same position inb, after some reordering, as they do ina? More examples would helpaandb.c = [t1 for t1, t2 in itertools.product(a, b) if t1 == t2]? Or do you mean something more complicated? Your example is not terribly enlightening.