I have a list of words (even 2 or 3 words in 1 object) . I have compiled a regex to match any of the words in the list to a random string . If it matches , that object of the list is returned ,else it will execute another regex on the string to return an expression.
my code:
"layouts" is the list of words and "layout_re" uses the words in list to match in the string "str". If ms is present in list , return ms as it is otherwise use expression of p to return the pattern.
def layout_corr(str):
ms = layout_re.search(str)
if ms in layouts:
ms=ms
else:
p = re.compile(r'(?:\w+\s+){1,2}layout')
ms = re.findall(p,str)
return ms
The output i get is that of the else statement .
eg:- str = " no 804 8th main 2nd c cross hrbr layout 1st block"
the list contains "hrbr layout" hence hrbr layout must be returned. But instead , the function returns "cross hrbr layout" which is the ms calculated by else statement.. What is the problem with the if statement??
re.searchreturns amatchobject (orNone), whilere.findallreturns alist. Neither one returns purely object matched.