[Tutor] comparing seqs by successive intervals

Karl Pflästerer sigurd at 12move.de
Mon Jan 19 15:13:20 EST 2004


On 19 Jan 2004, kevin parks <- kp8 at mac.com wrote:

> Karl's code is really cool and works well, but as Daniel points out,
> it doesn't accommodate sequences
> of different length as Don's does. Don's function will traverse both
> lists as long as the shortest
> one, ignoring the remainder of the longer list by using:

>      numPlaces = min(len(int1),len(int2))
>      if int1[:numPlaces] == int2[:numPlaces]:

> That's actually the behavior that i want. But really like this idea of
> traversing the sequences
> in parallel. I wonder if the benefits of both can be merged....

I'm not sure if I understand you right.  My code with the while loop
will also find matching sequences if one is longer than the other.
Daniel wrote the sequences should have equal length so I wrote another
version (in <m3oeszdci4.fsf at hamster.pflaesterer.de> ) which only
compares sequences of equal length.

Here's an example:

>>> a = [1,2,3,4,5,6,7,8,9,10] 
>>> b = [11,12]
>>> def same_intervp(seq1, seq2):
...     i = 0
...     res = []
...     while True:
...         try:
         [Code]

>>> same_intervp(a,b)
[1]


Upps I saw something in the code which is not clear to me.  If you have
a sequence [10,11,4] 4-11 => -7; -7%12 =>5.  Should that be the same
as eg. [1,2,7]?  Than you would first have to compute the modulo before
comparing the values.



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list