Finding multiple repetitions of smaller lists in a large cumulative list
<p>I have a large list of strings, for eg:</p>

<pre><code>full_log = ['AB21','BG54','HG89','NS72','Error','CF54','SD62','KK02','FE34']
</code></pre>

<p>and multiple small list of strings, for eg:</p>

<pre><code>tc1 = ['HG89','NS72']
tc2 = ['AB21','BG54']
tc3 = ['KK02','FE34']
tc4 = ['CF54','SD62']
</code></pre>

<p>I want to find each of this smaller lists in the larger list maintaining the sequence, so that the output would be something like:</p>

<pre><code>tc2-tc1-Er-tc4-tc3
</code></pre>

<p>I want to know if there is any straight forward, pythonic way of dealing with this situation.</p>

<p>You can use <a href="https://docs.python.org/2/library/sets.html" rel="nofollow">Set</a> for pattern matching:</p>

<pre><code>from sets import Set
full_log = ['AB21','BG54','HG89','NS72','Error','CF54','SD62','KK02','FE34']

tc1 = ['HG89','NS72']
tc2 = ['AB21','BG54']
tc3 = ['KK02','FE34']
tc4 = ['CF54','SD62']

set(full_log) &amp; set(tc1)
</code></pre>

<p>output: <code>{'HG89', 'NS72'}</code></p>

<pre><code>#Finding index of set elements:

result=set(full_log) &amp; set(tc1)



def all_indices(value, qlist):
    indices = []
    idx = -1
    while True:
        try:
            idx = qlist.index(value, idx+1)
            indices.append(idx)
        except ValueError:
            break
    return indices


r=[]
for i in range(len(result)):
   s=all_indices(list(result)[i], full_log)
   r.append(s)

r
Output: [[2], [3]]
</code></pre>

python list