【问题标题】:compare strings in two lists and return the count for the number of times each value is present Python [closed]比较两个列表中的字符串并返回每个值出现的次数Python [关闭]
【发布时间】:2022-06-14 23:24:15
【问题描述】:

我有两个用 csv 数据填充的列表。第一个列表包含建筑物名称,第二个列表包含对应于该建筑物的访问点。例如

l1 = ["research hall", "agriculture building", "accounting building"]
l2 = ["researchhall-1012312", "researchhall-1042122", "accountingbuilding121", "agriculture131"]

我试图做的是在 python 中编写一个函数,它遍历建筑物列表并输出在第二个列表中找到每个建筑物名称的次数,而无需与数字进行 1-1 匹配.我一直在尝试使用正则表达式并 findall 收效甚微,希望能提供任何帮助。

【问题讨论】:

  • 请编辑问题,向我们展示您最近尝试的代码以及您遇到的问题。另请参阅:How to Askhelp center
  • 我们可以假设l1 中没有空格的项目是l2 中项目的子字符串吗?如果是,则: (1) 通过删除空格将l1 转换为l3l3 = ["researchhall", "agriculturebuilding", "accountingbuilding"], (2) 匹配 in 运算符(子字符串) i。 e. “researchhall-1012312”中的“researchhall”
  • “农业建筑”应该匹配“agriculture131”吗?

标签: python regex list csv


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
  • 1970-01-01
相关资源
最近更新 更多