define 'in' operator on lists
..:: sjf ::..
somebody at unknown.org
Mon Oct 11 06:51:57 EDT 2004
More information about the Python-list mailing list
Mon Oct 11 06:51:57 EDT 2004
- Previous message (by thread): define 'in' operator on lists
- Next message (by thread): define 'in' operator on lists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
pewnego dnia niejaki(a) Duncan Booth wstukal(a) byl(a) co nastepuje...: > ..:: sjf ::.. wrote: > > >>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. > > > How about: > > >>>>def containedinsequence(short, long): > > ilong = iter(long) > for s in short: > for l in ilong: > if s==l: > break > else: > return False # ran out of long list > return True > > >>>>L = [1, 2, 3, 4, 5, 6] >>>>containedinsequence([3, 4, 6], L) > OK, this is nearly what I am expecting, but I want if containedsequence([3, 4, 5], L) returns True, but containedsequence([3, 4, 6], L) returns False because that sequence not exist in longlist exactly -- .:: sjf ::.. "Linux is like Wigwam. No gates, no windows... Apache inside ;-)"
- Previous message (by thread): define 'in' operator on lists
- Next message (by thread): define 'in' operator on lists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list