Skip to navigation
Find substring in a python list
07.12.13
import re list=['a cat','a dog','a yacht','cats'] regex=re.compile(".*(cat).*") print [m.group(0) for l in list for m in [regex.search(l)] if m] ['a cat', 'cats'] http://www.cademuir.eu/blog/2011/10/20/python-searching-for-a-string-within-a-list-list-comprehension/
Reply
Anonymous
Information Epoch 1732510269
Design programs to be connected to other programs.
Home
Notebook
Contact us