I suspect there are more pythonic ways of doing it, but at least it gets the job done:
l=list('abcdefgh')
pat=list('de')
print pat in l # Returns False
print any(l[i:i+len(pat)]==pat for i in xrange(len(l)-len(pat)+1))
More Related Contents:
- Concatenating two lists – difference between ‘+=’ and extend()
- Test if lists share any items in python
- What’s the most Pythonic way to identify consecutive duplicates in a list?
- Pythonic way to return list of every nth item in a larger list
- How to check if all of the following items are in a list?
- Extract list of attributes from list of objects in python
- Iterate over pairs in a list (circular fashion) in Python
- Pythonic way to convert a list of integers into a string of comma-separated ranges
- Slicing a list into a list of sub-lists [duplicate]
- Python – get unique and sorted values in list of lists [closed]
- Finding and replacing elements in a list
- Copying nested lists in Python
- In Python, how do I convert all of the items in a list to floats?
- Join a list of items with different types as string in Python
- Python’s most efficient way to choose longest string in list?
- Merge lists that share common elements
- Variable assignment and modification (in python) [duplicate]
- How to overcome TypeError: unhashable type: ‘list’
- python; modifying list inside a function
- Removing elements from a list containing specific characters [duplicate]
- How to compare a list of lists/sets in python?
- Subtracting two lists in Python
- Why python’s list slicing doesn’t produce index out of bound error? [duplicate]
- Python: determine if all items of a list are the same item [duplicate]
- Python extend with an empty list bug? [duplicate]
- How to flatten a hetrogenous list of list into a single list in python? [duplicate]
- Index all *except* one item in python
- How to convert a string with comma-delimited items to a list in Python?
- Creating a list in Python with multiple copies of a given object in a single line
- Python : how to append new elements in a list of list?