define 'in' operator on lists
Aaron Bingham
bingham at cenix-bioscience.com
Mon Oct 11 07:56:59 EDT 2004
Phil Frost wrote:
>On Mon, Oct 11, 2004 at 11:53:36AM +0200, ..:: sjf ::.. wrote:
>
>
>>Hi all,
>>
>>I want to define 'in' operator (or any "magic" function) on list which
>>returns True value if all of list (i.e. _list) elements appears in other
>>list (i.e. L) in the same order and False otherwise. By way of example:
>>
>>L = [1, 2, 3, 4, 5, 6, 7]
>>_list = [3, 4, 5]
>>
>>if L2 in L0:
>> return True
>>else:
>> return False
>>
>>How to do that?
>>
>>
>
>You might find that the 'sets' module does what you need.
>
>
The OP said he cares about order, so sets will certainly *not* do what
he wants. I suggest looking up string matching algorithms. This is
effectively what has been asked for but for strings of numbers instead
of strings of characters.
Aaron
More information about the Python-list
mailing list