python postcode_match
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python postcode_match相关的知识,希望对你有一定的参考价值。
def postcode_match(postal_code, text):
codes = re.compile(r'(\b\d{4}\b)')
codes_set = set([re.sub(r'\s', '', code) for code in set(codes.findall(text))]) # noqa
postcode_found = int(postal_code in codes_set)
other_postcode = 0
if postcode_found == 0:
for code in codes_set:
if code[:2] == postal_code [:2]:
other_postcode = 1
break
return (postcode_found, other_postcode)
以上是关于python postcode_match的主要内容,如果未能解决你的问题,请参考以下文章
001--python全栈--基础知识--python安装
Python代写,Python作业代写,代写Python,代做Python
Python开发
Python,python,python
Python 介绍
Python学习之认识python