I have a list of numbers:
Data = [0,2,0,1,2,1,0,2,0,2,0,1,2,0,2,1,1,...]
And I have a list of tuples of two, which is all possible combinations of the individual numbers above:
Combinations = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]
I want to try to find where each item in Combinations appears in Data and add the value after each occurrence to another list.
For example, for (0,2) I want to make a list [0,0,0,1] because those are the the values that fall immediately after (0,2) occurs in Data.
So far, I have:
any(Data[i:i+len(CurrentTuple)] == CurrentTuple for i in xrange(len(Data)-len(CurrentTuple)+1))
Where CurrentTuple
is Combinations.pop()
.
The problem is that this only gives me a Boolean of whether the CurrentTuple
occurs in Data. What I really need is the value after each occurrence in Data.
Does anyone have any ideas as to how this can be solved? Thanks!