On Mon, Aug 15, 2011 at 4:26 PM, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is
Johannes wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
[...]
For anyone interested, here's a pair of functions that implement
sub-sequence testing similar to str.find and str.rfind:
On Tue, 16 Aug 2011 09:57:57 -0400, John Posner wrote:
How about using Python's core support for == on list objects:
for i in range(alist_sz - slist_sz + 1):
if slist == alist[i:i+slist_sz]:
return True
This is bound to be asymptotically O(alist_sz * slist_sz), even
On Se shanbe 25 Mordad 1390 01:26:54 Johannes wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained
On Aug 15, 4:26 pm, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained
On Aug 15, 4:26 pm, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained
On Aug 15, 4:26 pm, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
l1 = [1,2,3], l2 = [1,3,5,7] - l1 is not
Laszlo Nagy gand...@shopzeus.com wrote:
Fastest, error-free and simplest solution is to use sets:
l1 = [1,2]
l2 = [1,2,3,4,5]
set(l1)-set(l2)
set([])
set(l2)-set(l1)
set([3, 4, 5])
Error-free? Not given the stated requirements:
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not
On Aug 16, 4:51 pm, Laszlo Nagy gand...@shopzeus.com wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is
On Aug 15, 11:51 pm, Laszlo Nagy gand...@shopzeus.com wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is
Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
l1 = [1,2,3], l2 = [1,3,5,7] - l1 is
Error free? Consider this stated requirement:
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
If you look it the strict way, containment relation for lists is meant
this way:
l1 = []
l2 = [1,l1,2] # l2 CONTAINS l1
But you are right, I was wrong. So let's clarify what the OP
On Tue, 16 Aug 2011 12:12 pm Steven D'Aprano wrote:
On Tue, 16 Aug 2011 09:26 am Johannes wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
This is not the most efficient algorithm, but for short lists it should be
Am 16.08.2011 09:44, schrieb Peter Otten:
Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in
On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote:
On Aug 15, 4:26 pm, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 =
Johannes wrote:
Am 16.08.2011 09:44, schrieb Peter Otten:
Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is
On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
Best is subjective. AFAIK, the theoretically-optimal algorithm is
Boyer-Moore. But that would require a fair amount of code, and
Roy Smith r...@panix.com writes:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
[...]
import re
def sublist(l1, l2):
s1 = ''.join(map(str, l1))
s2 = ''.join(map(str, l2))
return re.search(s1, s2)
This is complete
In article 8739h18rzj@dpt-info.u-strasbg.fr,
Alain Ketterlin al...@dpt-info.u-strasbg.fr wrote:
Roy Smith r...@panix.com writes:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
[...]
import re
def sublist(l1, l2):
On 2:59 PM, Nobody wrote:
On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
Best is subjective. AFAIK, the theoretically-optimal algorithm is
Boyer-Moore. But that would require a
On 2:59 PM, Nobody wrote:
On Tue, 16 Aug 2011 01:26:54 +0200, Johannes wrote:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
Best is subjective. AFAIK, the theoretically-optimal algorithm is
Boyer-Moore. But that would require a
On Aug 16, 8:23 am, Alain Ketterlin al...@dpt-info.u-strasbg.fr
wrote:
Roy Smith r...@panix.com writes:
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
[...]
import re
def sublist(l1, l2):
s1 = ''.join(map(str, l1))
That can be easily fixed:
def sublist(lst1, lst2):
s1 = ','.join(map(str, lst1))
s2 = ','.join(map(str, lst2))
return False if s2.find(s1)==-1 else True
I don't know about best, but it works for the examples given.
For numbers, it will always work. But what about
Am 16.08.2011 10:00, schrieb Laszlo Nagy:
Error free? Consider this stated requirement:
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
If you look it the strict way, containment relation for lists is meant
this way:
l1 = []
l2 = [1,l1,2] # l2 CONTAINS l1
But you are
Laszlo Nagy gand...@shopzeus.com writes:
def sublist(lst1, lst2):
s1 = ','.join(map(str, lst1))
s2 = ','.join(map(str, lst2))
return False if s2.find(s1)==-1 else True
I don't know about best, but it works for the examples given.
For numbers, it will always work.
I'm not
On 16/08/2011 00:26, Johannes wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
l1 = [1,2,3],
On 2011-08-16, nn prueba...@latinmail.com wrote:
That can be easily fixed:
def sublist(lst1, lst2):
s1 = ','.join(map(str, lst1))
s2 = ','.join(map(str, lst2))
return False if s2.find(s1)==-1 else True
sublist([1,2,3],[1,2,3,4,5])
True
sublist([1,2,2],[1,2,3,4,5])
On Aug 16, 1:37 am, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
On Tue, 16 Aug 2011 04:14 pm ChasBrown wrote:
On Aug 15, 4:26 pm, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 = [1,2,2,], l2 = [1,2,3,4,5] - l1 is not contained in l2
l1 = [1,2,3], l2 = [1,3,5,7] - l1 is not contained in
Check out collections.Counter if you have 2.7 or up.
If you don't, google for multiset or bag types.
On Mon, Aug 15, 2011 at 4:26 PM, Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for
In article mailman.27.1313450819.27778.python-l...@python.org,
Johannes dajo.m...@web.de wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
for example:
l1 = [1,2], l2 = [1,2,3,4,5] - l1 is contained in l2
l1 =
On Tue, 16 Aug 2011 09:26 am Johannes wrote:
hi list,
what is the best way to check if a given list (lets call it l1) is
totally contained in a second list (l2)?
This is not the most efficient algorithm, but for short lists it should be
plenty fast enough:
def contains(alist, sublist):
33 matches
Mail list logo