regex - How do I have the index of an item in a python list which exactly matches a given regular expression pattern? -
suppose have list of string items following:
lst = ['apple', 'mango', 'mime'] p = r"mime" # regex pattern
now, want have index of item matches pattern p
. clearly, answer 2
. how do it?
here code re module regular expressions
import re lst = ['apple', 'mango', 'mime'] p = r"mime" # regex pattern in range(0,len(lst)): if re.compile(p).match(lst[i]): print
Comments
Post a Comment