私信  •  关注

alissongranemann

alissongranemann 最近创建的主题
alissongranemann 最近回复了
4 年前
回复了 alissongranemann 创建的主题 » 移除嵌套列表python中特定项之后的所有项

my_lst = [['John C, CEO & Co-Funder, ABC company','Eric P, CFO, QWE company','My Profile','Herber W, CTO, PPP company'],
['Eli S, AVP, ACV Company', 'My Profile','Brian M, Analyst, LPL company'],
['Diana F, Managing Director, MS company','Alan X, Associate, JPM company','My Profile', 'Jame R, Manager, AL company']]
results = [nested[:nested.index('My Profile')] if 'My Profile' in nested else nested for nested in my_lst]

不理解列表:

my_lst = [['John C, CEO & Co-Funder, ABC company','Eric P, CFO, QWE company','My Profile','Herber W, CTO, PPP company'],
    ['Eli S, AVP, ACV Company', 'My Profile','Brian M, Analyst, LPL company'],
    ['Diana F, Managing Director, MS company','Alan X, Associate, JPM company','My Profile', 'Jame R, Manager, AL company']]
results = []
for nested in my_lst:
    filtered = nested[:nested.index('My Profile')] if 'My Profile' in nested else nested
    results.append(filtered)