Best strategy for finding a pattern in a sequence of integers

Arnaud Delobelle arnodel at googlemail.com
Fri Nov 21 12:43:09 EST 2008


Slaunger <Slaunger at gmail.com> writes:

> I am a Python novice, and I have run into a problem in a project I am
> working on, which boils down to identifying the patterns in a sequence
> of integers, for example
>
> .... 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
> 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
> 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
> 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
> 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 6 6 1 ...
>
> I want to process this such that I get out two patterns, like:
> (9, 3, 3, 0, 3, 3, 0, 3, 3, 0, 3, 3, 0)
> and
> (10, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1, 6, 6, 1)
>
> I am pretty sure I can figure out how to do that, but I would like to
> have some guidance on the most pythonic approach to this.

Then it would be a good starting point to write some code. Then you
could post it and ask how it can be made more 'pythonic'.

HTH

-- 
Arnaud



More information about the Python-list mailing list