Python 尝试将列表中的每个项目的一部分拉入新列表

Python 尝试将列表中的每个项目的一部分拉入新列表,python,list,for-loop,list-comprehension,delimiter,Python,List,For Loop,List Comprehension,Delimiter,我有一个很长的列表(称为“CurrentTitleAndCompany”),如下所示: [阿肯色州玻璃容器公司人力资源副总裁2019年-现在”,“俄勒冈州温泉联盟部落薪酬福利管理员2018年-现在”,“USI保险服务公司副总裁员工福利2020年-现在”,“ASM研究公司福利团队副组长2019年-现在”“现在”,] 我想创建一个新的列表(称为“CurrentTitle”),它从“at”之前的每个项目中获取部分 这是我写的,但我得到一个“列表索引超出范围”错误: 我个人建议您创建一个类,并将标题与公

我有一个很长的列表(称为“CurrentTitleAndCompany”),如下所示:

[阿肯色州玻璃容器公司人力资源副总裁2019年-现在”,“俄勒冈州温泉联盟部落薪酬福利管理员2018年-现在”,“USI保险服务公司副总裁员工福利2020年-现在”,“ASM研究公司福利团队副组长2019年-现在”“现在”,]

我想创建一个新的列表(称为“CurrentTitle”),它从“at”之前的每个项目中获取部分

这是我写的,但我得到一个“列表索引超出范围”错误:


我个人建议您创建一个类,并将标题与公司分开,例如:

class CurrentTitleAndCompany:
    CompanyPersonOne = "Apple"
    TitlePersonOne = "CEO"
    CompanyPersonTwo = "Microsoft"
    TitlePersonTwo = "Vice President"


print("Person One currently works at", CurrentTitleAndCompany.CompanyPersonOne, 
"and occupies the title of ",
      CurrentTitleAndCompany.TitlePersonOne)

print("Person Two currently works at", CurrentTitleAndCompany.CompanyPersonTwo, 
"and occupies the title of ",
      CurrentTitleAndCompany.TitlePersonTwo)

如果您需要任何其他类型的澄清,请联系我!

您的问题中似乎有一些编码错误。输入列表根本不包含
at
titles=…
您长长的标题列表。然后
CurrentTitle=[title.split('at')[0]用于标题中的标题]
谢谢!LPR,您的解决方案解决了这个问题
class CurrentTitleAndCompany:
    CompanyPersonOne = "Apple"
    TitlePersonOne = "CEO"
    CompanyPersonTwo = "Microsoft"
    TitlePersonTwo = "Vice President"


print("Person One currently works at", CurrentTitleAndCompany.CompanyPersonOne, 
"and occupies the title of ",
      CurrentTitleAndCompany.TitlePersonOne)

print("Person Two currently works at", CurrentTitleAndCompany.CompanyPersonTwo, 
"and occupies the title of ",
      CurrentTitleAndCompany.TitlePersonTwo)