从Python中的另一个字符串中提取字符串

发布于 2025-02-08 19:56:02 字数 545 浏览 2 评论 0原文

我有两个列表

a = ['Shri Vatsav Ltd','Paytm Pvt ltd','Paypal ltd']
b = ['Shri Vatsav Ltd 123 HAL 2nd Stage Indiranagar Banagalore 560008','Paytm Pvt ltd 143 Jallianwallabagh Mumbai India 34567','Paypal ltd 345 Greenwood drive 123ST Long Beach CA 34566 US']

我只需要使用列表“ a” a“ IE,某种交集或类似的东西提取地址。并将其存储为称为“ C”的列表,

请找到示例输出:

输出

['123 HAL 2nd Stage Indiranagar Banagalore 560008','143 Jallianwallabagh Mumbai India 3456','345 Greenwood drive 123ST Long Beach CA 34566 US']

谢谢。

I have two lists

a = ['Shri Vatsav Ltd','Paytm Pvt ltd','Paypal ltd']
b = ['Shri Vatsav Ltd 123 HAL 2nd Stage Indiranagar Banagalore 560008','Paytm Pvt ltd 143 Jallianwallabagh Mumbai India 34567','Paypal ltd 345 Greenwood drive 123ST Long Beach CA 34566 US']

I need to extract only the address from list "b" using list "a" i.e, some kind of intersection or something like that. and store it as a list called "c"

Please find the example output:

output

['123 HAL 2nd Stage Indiranagar Banagalore 560008','143 Jallianwallabagh Mumbai India 3456','345 Greenwood drive 123ST Long Beach CA 34566 US']

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2025-02-15 19:56:02
a = ['Shri Vatsav Ltd', 'Paytm Pvt ltd', 'Paypal ltd']
b = ['Shri Vatsav Ltd 123 HAL 2nd Stage Indiranagar Banagalore 560008','Paytm Pvt ltd 143 Jallianwallabagh Mumbai India 34567','Paypal ltd 345 Greenwood drive 123ST Long Beach CA 34566 US']

c = [i.replace(j, "") for i in b for j in a if j in i]
print(c)  # [' 123 HAL 2nd Stage Indiranagar Banagalore 560008', ' 143 Jallianwallabagh Mumbai India 34567', ' 345 Greenwood drive 123ST Long Beach CA 34566 US']
a = ['Shri Vatsav Ltd', 'Paytm Pvt ltd', 'Paypal ltd']
b = ['Shri Vatsav Ltd 123 HAL 2nd Stage Indiranagar Banagalore 560008','Paytm Pvt ltd 143 Jallianwallabagh Mumbai India 34567','Paypal ltd 345 Greenwood drive 123ST Long Beach CA 34566 US']

c = [i.replace(j, "") for i in b for j in a if j in i]
print(c)  # [' 123 HAL 2nd Stage Indiranagar Banagalore 560008', ' 143 Jallianwallabagh Mumbai India 34567', ' 345 Greenwood drive 123ST Long Beach CA 34566 US']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文