Testing if a list contains another list with Python
Posted
by
None
on Stack Overflow
See other posts from Stack Overflow
or by None
Published on 2010-10-02T20:20:32Z
Indexed on
2012/04/05
23:28 UTC
Read the original article
Hit count: 464
How can I test if a list contains another list. Say there was a function called contains:
contains([1,2], [-1, 0, 1, 2]) # Returns [2, 3] (contains returns [start, end])
contains([1,3], [-1, 0, 1, 2]) # Returns False
contains([1, 2], [[1, 2], 3) # Returns False
contains([[1, 2]], [[1, 2], 3]) # Returns [0, 0]
Edit:
contains([2, 1], [-1, 0, 1, 2]) # Returns False
contains([-1, 1, 2], [-1, 0, 1, 2]) # Returns False
contains([0, 1, 2], [-1, 0, 1, 2]) # Returns [1, 3]
© Stack Overflow or respective owner