Haven't followed the entire thread, so I could be making a silly, out-of-place remark, and apologies in advance for the same.<div>However, to me it looks like Slaunger wants to find 2 of the longest repeating patterns, and not just 2 specific patterns (though from the introductory test, it appears to be on the contrary. If so, i.e. looking for longest repeating patters, this is largely a problem of choosing the right algorithm, and not so much Python. Something like KMP (Knuth Morris Pratt) algo may help.<br>
<br><div class="gmail_quote">On Fri, Nov 21, 2008 at 10:40 PM, Gerard flanagan <span dir="ltr"><<a href="mailto:grflanagan@gmail.com">grflanagan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Slaunger wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
I am a Python novice, and I have run into a problem in a project I am<br>
working on, which boils down to identifying the patterns in a sequence<br>
of integers, for example<br>
<br>
.... 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 ...<br>
<br>
I want to process this such that I get out two patterns, like:<br>
(9, 3, 3, 0, 3, 3, 0, 3, 3, 0, 3, 3, 0)<br>
and<br>
(10, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1)<br>
<br>
</blockquote>
<br>
Maybe:<br>
<br>
#-----------------------------------------------------------------<br>
data = '''<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 9 3 3 0 3 3 0 3 3 0 3 3 0 10 6 6<br>
1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1'''<br>
<br>
data = [int(x) for x in data.split()]<br>
<br>
from itertools import groupby<br>
<br>
S1 = [0, 3, 9]<br>
<br>
s = set()<br>
for k, g in groupby(data, lambda x: x in S1):<br>
    seq = tuple(g)<br>
    # maybe the next line should be 'if 9 in seq or 10 in seq'?<br>
    if seq[0] in [9, 10]:<br>
        s.add(seq)<br>
<br>
print s<br>
#------------------------------------------------------------------<br>
set(<br>
[(9, 3, 3, 0, 3, 3, 0, 3, 3, 0, 3, 3, 0),<br>
(10, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1)])<br>
<br>
hth<br>
<br>
G.<br><font color="#888888">
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>regards,<br>Banibrata<br><a href="http://www.linkedin.com/in/bdutta">http://www.linkedin.com/in/bdutta</a><br><a href="http://octapod.wordpress.com">http://octapod.wordpress.com</a><br>

</div>