import re roadkeywords=['road' , 'ave' , 'lane' , 'sarani' , 'soroni' , 'rd#' , 'sarak' , 'sharak' , 'shorok' , 'sharani' , 'highway' , 'path' , 'poth' , 'chowrasta' , 'sarak' , 'rasta' , 'sorok' , 'goli' , 'street' , 'line'] roadkey="" blockkey="" houskey="" name="" subareakey="" parsed_aadr='koshba house, house A/1, senpara parbata' ge_addr='house 27/a, Road 5, Block F, Rupanagr, Mirpur' parsed_aadr=parsed_aadr.lower() parsed_aadr=parsed_aadr.split(',') parsed_aadr[0]=parsed_aadr[0].strip() if not re.match('house\s+\d+',parsed_aadr[0]): name=parsed_aadr[0] parsed_aadr.pop(0) print(parsed_aadr) for token in parsed_aadr: print(token) if 'house' in token: token=token.strip() housekey=token.strip() elif any(s in token for s in roadkeywords): roadkey=token.strip() elif 'block' in token: blockkey=token.strip() elif 'block' not in token and not any(s in token for s in roadkeywords) and 'house' not in token: subareakey=token.strip() print("Holding Name : "+name) print("House : "+housekey) print("Road : "+roadkey) print("Block : "+blockkey) print("Subarea : "+subareakey)