Sequences in list

temp at mclift.fsnet.co.uk temp at mclift.fsnet.co.uk
Mon May 2 15:52:04 EDT 2005


Hi All,

I wonder could someone help me with this?

What I want to do is search through a list of letters and look for
adjacent groups of letters that form sequences, not in the usual way of
matching say abc to another appearance later on in the list but to look
for transposed patterns.

The groups of letters can be made up of between 2 to 4 letters.
It is not know beforehand how the groups are formed, so I can't say
here is a group, look for a sequence formed from this.
There must be at least three appearances of the groups for the sequence
to be pass.
More than one sequence may show in a list, i.e. first abc, bcd and cde
followed by bd, df, fa, ac at some later point.
Ideally I would like to know the start and end position of the
sequence/sequences.

I'm looking for patterns such as these:

['a', 'b', 'c', 'b', 'c', 'd', 'c', 'd', 'e']
['a', 'c', 'f', 'c', 'e', 'h', 'e', 'g', 'c']
['c', 'a', 'a', 'f', 'f', 'd', 'd', 'b']

But these would be wrong:

['a', 'b', 'c', 'b', 'c', 'd', 'c', 'd', 'e', 'f', 'a', 'd'] - This one
fails because of the 'jump' of the last group of three letters in
relation to the others. To pass the last group would need to have been
def. However, the previous three groups are ok and would be passed as a
sequence.

['a', 'c', 'f', 'a', 'f', 'e', 'e', 'g', 'c'] - Here, although the
first and last groups have a similar sequence this would fail because
of the intervening group (afe) not following the pattern.



Thanks for any help,

Malcolm




More information about the Python-list mailing list