pythonnew at gmail.com
Tue Nov 15 06:42:10 CET 2005
> Hijacking Brian's response since my newsserver never god Ben's original
> I would program this at a reasonably high abstraction level, based on
> sets -- since you say order doesn't matter, sets are more appropriate
> than lists anyway. For example:
> def two_cont_in_common(x, y):
> common = set(x).intersection(y)
> return bool(common.intersection(z+1 for z in common))
> i.e., given two lists or whatever, first build the set of all elements
> they have in common, then check if that set contains two continuous
> elements. Then, as Brian suggests, you can use this dyadic function on
> a reference list and as many others as you wish:
> def bens_task(reference, others):
> return [two_cont_in_common(alist, reference) for alist in others]
> The call bens_task(lisA, lisB, lisC, lisD) will give you essentially
> what you require, except it uses True and False rather than 1 and 0; if
> you need to fix this last issue, you can add an int(...) call around
> these booleans in either of the functions in question.
I got invalid syntax error when i run Alex's code. do not know why.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list