在python中只分割列表的一部分 [英] Split only part of list in python

查看:323
本文介绍了在python中只分割列表的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表

['Paris, 458 boulevard Saint-Germain', 'Marseille, 29 rue Camille Desmoulins', 'Marseille, 1 chemin des Aubagnens']

我想要关键字boulevard,rue,chemin 像输出

i want split after keyword "boulevard, rue, chemin" like in output

['Saint-Germain', 'Camille Desmoulins', 'des Aubagnens']

感谢您的时间

推荐答案

它不工作,因为你只是在分裂后提取一个单词:

It's not working because you are only extracting one word after you split:

adresse = [i.split(' ', 8)[3] for i in my_list`]

由于 3]

尝试 [3:] 。啊,但是这还不够,因为当你想要一个字符串列表时,你会得到一个列表列表。所以你还需要使用 join

Try [3:] instead. Ah, but that still won't be enough, because you'll get a list of lists, when you want a list of strings. So you also need to use join.

adresse = [' '.join(i.split(' ', 8)[3:]) for i in my_list`]

现在你唯一的困难是处理不规则的街道地址,例如没有房屋号码的人,或街头名字的几个字。我没有解决办法!

Now your only difficulty is dealing with irregular street addresses, e.g. people who don't have a house number, or several words in the street name. I have no solution for that!

这篇关于在python中只分割列表的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆