社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

alissongranemann

alissongranemann 最近创建的主题
alissongranemann 最近回复了
5 年前
回复了 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)