地址解析[PY]
因此,我想编写一个将以形式输入输入的函数:
123 1st street APT 32S or
320 Jumping Alien Road
555 Google Ave
字典 / json中的输出所有从输入字符串字典中解析的所有信息
看起来就像是
output = {
"streetNum" : "123",
"roadName" : "1st",
"suffix" : "street",
"enders" : "APT", #or None /null
"room" : "32S" #or None / null
}
我试图使用逻辑的内容,但我可以提出的最好的是是沿着地址的路线。Split(''),然后以路线名,后缀和街道名称通常位于该字符串中它们内部的空间也会破坏功能。
def addressParser(addressString):
return {
"streetNum" : addressString.split(' ')[0], #prob need regex help
"roadName" : addressString.split(' ')[1],
"suffix" : addressString.split(' ')[2],
"enders" : addressString.split(' ')[3],
"room" : addressString.split(' ')[4]
}
编辑:确切找到我在这里需要的东西 https://pypi.org/project/project/address/address/
so im looking to write a function that will take input in the form:
123 1st street APT 32S or
320 Jumping Alien Road
555 Google Ave
and output in a dictionary / json all the information parsed from the inputted string
dictionary would look something like
output = {
"streetNum" : "123",
"roadName" : "1st",
"suffix" : "street",
"enders" : "APT", #or None /null
"room" : "32S" #or None / null
}
Im trying to thing of the logic but the best I can come up with is something along the lines of address.split(' ') and then taking where the roadname, suffix, and streetname would typically be located in said string but obviously these things aren't always gonna be located in that order and when road names have spaces inside them that would break the function as well.
def addressParser(addressString):
return {
"streetNum" : addressString.split(' ')[0], #prob need regex help
"roadName" : addressString.split(' ')[1],
"suffix" : addressString.split(' ')[2],
"enders" : addressString.split(' ')[3],
"room" : addressString.split(' ')[4]
}
Edit: found exactly what i needed here https://pypi.org/project/address/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论