Re: Test if list contains another list

2008-11-20 Thread str1442
Ali wrote: Its funny, I just visited this problem last week. ./Ali -- http://mail.python.org/mailman/listinfo/python-list That use of reduce is nice, but you better use all() / any(). -- http://mail.pytho

Re: Test if list contains another list

2008-11-16 Thread Ali
Its funny, I just visited this problem last week. ./Ali -- http://mail.python.org/mailman/listinfo/python-list

Re: Test if list contains another list

2008-09-29 Thread bearophileHUGS
Derek Martin: > code that implements non-obvious algorithms ought to explain what it's > doing in comments, I am sorry, you are right, of course. In my libs/code there are always docstrings and doctests/tests, and most times comments too, like you say. When I post code here I often strip away par

Re: Test if list contains another list

2008-09-29 Thread Derek Martin
On Mon, Sep 29, 2008 at 04:12:13AM -0700, [EMAIL PROTECTED] wrote: > Derek Martin: > >Unless you're doing lots and lots of these in your application,< > > I don't agree. That's library code, so it has to be efficient and > flexible, because it's designed to be used in many different > situations

Re: Test if list contains another list

2008-09-29 Thread bearophileHUGS
Derek Martin: >Quite a lot faster than mine... even without using psyco.< It's designed for Psyco. >However they don't appear to buy you much, given that the cases they optimize >would probably be rare, and the difference in execution time gained by the >optimization is not noticable to the us

Re: Test if list contains another list

2008-09-28 Thread Derek Martin
On Fri, Sep 26, 2008 at 01:39:16PM -0700, [EMAIL PROTECTED] wrote: > # building prefix-function > m = 0 > for i in xrange(1, len_sub): > while m > 0 and sub[m] != sub[i]: > m = table[m - 1] > if sub[m] == sub[i]: > m += 1 > table[i] = m >

Re: Test if list contains another list

2008-09-26 Thread bearophileHUGS
bearophile: > # searching > m, i = 0, 0 ... > i += 1 The name 'i' can be removed, sorry. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Test if list contains another list

2008-09-26 Thread bearophileHUGS
I suggest Python programmers to fill the holes in the Python std lib with some debugged & tuned implementations, their "bag of tricks", so they don't have to re-invent and debug things all the time. This works well with Psyco: def issubseq(sub, items): """issubseq(sub, items): return true if

Re: Test if list contains another list

2008-09-26 Thread Derek Martin
On Thu, Sep 18, 2008 at 03:24:16AM -0700, [EMAIL PROTECTED] wrote: > I looked inside this thread for my query which brought me the > following google search result > "Test if list contains another list - comp.lang.python | Google > Groups" > > But then I was disappoint

Re: Test if list contains another list

2008-09-18 Thread gauravatnet
all inputs are known to be numbers between 0 and > > 15, you can just do: > > > if ''.join(map(hex, a)) in ''.join(map(hex, b)): > >     return True > > > Hmm... actually, with the '0x' prefix that hex() puts on numbers, I > > think

Re: Test if list contains another list

2008-09-18 Thread gauravatnet
ble > way to convert to a string.  The problem is easier if you know something > about the inputs.  If all inputs are known to be numbers between 0 and > 15, you can just do: > > if ''.join(map(hex, a)) in ''.join(map(hex, b)): >     return True > > Hmm.

Re: Test if list contains another list

2008-09-09 Thread J. Cliff Dyer
On Tue, 2008-09-09 at 10:49 +0200, Bruno Desthuilliers wrote: > Matimus a écrit : > > On Sep 8, 12:32 am, Bruno Desthuilliers > > <[EMAIL PROTECTED]> wrote: > (snip) > >> >>> set(a).issubset(set(b)) > >> True > >> >>> > >> > > Just to clarify, doing it using sets is not going to preserve order

Re: Test if list contains another list

2008-09-09 Thread Bruno Desthuilliers
Matimus a écrit : On Sep 8, 12:32 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: (snip) >>> set(a).issubset(set(b)) True >>> Just to clarify, doing it using sets is not going to preserve order OR number of elements that are the same. That is: a = [1,1,2,3,4] b = [4,5,3,7,2,6,1] set(a

Re: Test if list contains another list

2008-09-08 Thread Matimus
On Sep 8, 12:32 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > mathieu a écrit : > > > Hi there, > > >   I am trying to write something very simple to test if a list > > contains another one: > > > a = [1,2,3] > > > b = [3,2,1,4] > > > but 'a in b' returns False. > > Indeed. Lists are not set

Re: Test if list contains another list

2008-09-08 Thread mathieu
On Sep 8, 9:32 am, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > mathieu a écrit : > > > Hi there, > > > I am trying to write something very simple to test if a list > > contains another one: > > > a = [1,2,3] > > > b = [3,2,1,4] > > > but 'a in b' returns False. > > Indeed. Lists are not sets

Re: Test if list contains another list

2008-09-08 Thread Bruno Desthuilliers
mathieu a écrit : Hi there, I am trying to write something very simple to test if a list contains another one: a = [1,2,3] b = [3,2,1,4] but 'a in b' returns False. Indeed. Lists are not sets, and the fact that all elements of list a happens to also be part of list b doesn't make the lis

Re: Test if list contains another list

2008-09-08 Thread James Mills
Hi, >>> a = [1,2,3] >>> b = [3,2,1,4] >>> a = set(a) >>> b = set(b) >>> a.intersection(b) set([1, 2, 3]) Is this what you want ? cheers James On 9/8/08, mathieu <[EMAIL PROTECTED]> wrote: > Hi there, > > I am trying to write something very simple to test if a list > contains another one: > >

Re: Test if list contains another list

2008-09-08 Thread Christian Heimes
mathieu wrote: Hi there, I am trying to write something very simple to test if a list contains another one: a = [1,2,3] b = [3,2,1,4] but 'a in b' returns False. How do I check that a is indeed contained in b ? Use sets: >>> a = [1,2,3] >>> b = [3,2,1,4] >>> set(a).issubset(set(b)) True

Test if list contains another list

2008-09-08 Thread mathieu
Hi there, I am trying to write something very simple to test if a list contains another one: a = [1,2,3] b = [3,2,1,4] but 'a in b' returns False. How do I check that a is indeed contained in b ? thanks -- http://mail.python.org/mailman/listinfo/python-list