Re: are elements of a list in sequence in list b

2008-02-09 Thread bearophileHUGS
Steven D'Aprano: > I believe that it is considered an abuse of doctest to write a function > with 28 lines of code and 19 tests I agree with you. Most of my functions/methods have more compact doctests (putting things on many lines has the advantage of letting you locate the failing tests in a sim

Re: are elements of a list in sequence in list b

2008-02-09 Thread Paddy
On 9 Feb, 15:20, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 09 Feb 2008 05:44:27 -0800, bearophileHUGS wrote: > > def issubseq(sub, items): > > """issubseq(sub, items): return true if the sequence 'sub' is a > > contiguous subsequence of the 'items' sequence. > > [s

Re: are elements of a list in sequence in list b

2008-02-09 Thread Steven D'Aprano
On Sat, 09 Feb 2008 05:44:27 -0800, bearophileHUGS wrote: > def issubseq(sub, items): > """issubseq(sub, items): return true if the sequence 'sub' is a > contiguous subsequence of the 'items' sequence. [snip] A stylistic note for you... I believe that it is considered an abuse of doctest to

Re: are elements of a list in sequence in list b

2008-02-09 Thread bearophileHUGS
Steven D'Aprano: > What you're trying to do is the equivalent of substring searching. There > are simple algorithms that do this, and there are fast algorithms, but > the simple ones aren't fast and the fast ones aren't simple. > However, for your use case, the simple algorithm is probably fast eno

Re: are elements of a list in sequence in list b

2008-02-08 Thread Steven D'Aprano
On Fri, 08 Feb 2008 16:39:55 +, Matthew_WARREN wrote: > Hallo, > > > I need to search list a for the sequence of list b > > First I went a=[1,2,34,4,5,6] b=[2,3,4] a in b > False You have the order of a and b mixed up there. As you have it, you are searching b for a. >

Re: are elements of a list in sequence in list b

2008-02-08 Thread Tomek Paczkowski
[EMAIL PROTECTED] wrote: > Hallo, > > > I need to search list a for the sequence of list b > I guess most pythonic would be sth like this: [code] def naive_seq_match(sequence, pattern): """Serches for pattern in sequence. If pattern is found returns match start index, else returns No

Re: are elements of a list in sequence in list b

2008-02-08 Thread Arnaud Delobelle
On Feb 8, 5:06 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I need to search list a for the sequence of list b > > def list_contains(a, b): >     return any(a[i:i+len(b)] == b for i in range(len(a) - len(b) + 1)) > > list_contains(range(1, 7), [2, 3, 4]) > > -- > Paul H

Re: are elements of a list in sequence in list b

2008-02-08 Thread Paul Hankin
[EMAIL PROTECTED] wrote: > I need to search list a for the sequence of list b def list_contains(a, b): return any(a[i:i+len(b)] == b for i in range(len(a) - len(b) + 1)) list_contains(range(1, 7), [2, 3, 4]) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

are elements of a list in sequence in list b

2008-02-08 Thread Matthew_WARREN
Hallo, I need to search list a for the sequence of list b First I went >>> a=[1,2,34,4,5,6] >>> b=[2,3,4] >>> a in b False So ''.join([ v.__str__() for v in b ]) in ''.join([ v.__str__() for v in a ]) >>> s=SomeObject() >>> a=[1,2,3,[s,3,[4,s,9]],s,4] >>> b=[3,[s,3,[4,s,9]],s,4] >>> ''.join([