首页 > 解决方案 > 如何循环和删除包含子字符串的嵌套列表中的元素?

问题描述

我曾尝试使用列表理解,但我只是不知道如何为我的特定问题构建它。我有一个嵌套列表。子列表在最后:

['x', '', 'x', 'y', 'x', Suite 111', 'Prairie Village', 'KS', '\t66207', '5200 W. 94th Terrace, Suite 111', 'Prairie Village', 'KS', '\t66207', 'x', 'y', 'x', 'y', 'Kansas City', 'SLBE', 'This company provides Framing and Finish Carpentry installation services, Drywall & Acoustical Ceilings installation services and Construction Management services for Commercial & Institutional Buildings construction projects. . Metal Studs - Trim - Cabinetry - Carpenters - Doors - Windows - Hardware - Sheet Rock - Suspended ceilings - Construction Administration - Project Management - Tenant Finish - Interior Finish', '', ['236220 - Construction management, commercial and institutional building', '236220 - Project Management (Inactive effective 02-12-2020)', '238130 - Framing contractors', '238130 - Stud wall (e.g., wood, steel) installation', '238130 - Carpentry', '238310 - Acoustical ceiling tile and panel installation', '238310 - Ceiling tile installation', '238310 - Drywall contractors', '238310 - Drywall hanging', '238350 - Cabinetry work performed at the construction site', '238350 - Door and window, prefabricated, installation', '238350 - Trim and finish carpentry contractors', '238350 - Finish Carpentry Contractors']]

我想检查并从包含子字符串'Inactive'的列表中删除整个元素,但是我不知道如何。我在想我可以使用正则表达式,但我只是对如何去做这件事感到困惑。

我想要的结果是:

['x', '', 'x', 'y', 'x', Suite 111', 'Prairie Village', 'KS', '\t66207', '5200 W. 94th Terrace, Suite 111', 'Prairie Village', 'KS', '\t66207', 'x', 'y', 'x', 'y', 'Kansas City', 'SLBE', 'This company provides Framing and Finish Carpentry installation services, Drywall & Acoustical Ceilings installation services and Construction Management services for Commercial & Institutional Buildings construction projects. . Metal Studs - Trim - Cabinetry - Carpenters - Doors - Windows - Hardware - Sheet Rock - Suspended ceilings - Construction Administration - Project Management - Tenant Finish - Interior Finish', '', ['236220 - Construction management, commercial and institutional building', '238130 - Framing contractors', '238130 - Stud wall (e.g., wood, steel) installation', '238130 - Carpentry', '238310 - Acoustical ceiling tile and panel installation', '238310 - Ceiling tile installation', '238310 - Drywall contractors', '238310 - Drywall hanging', '238350 - Cabinetry work performed at the construction site', '238350 - Door and window, prefabricated, installation', '238350 - Trim and finish carpentry contractors', '238350 - Finish Carpentry Contractors']]

有人可以帮助我吗?

标签: pythonlist

解决方案


推荐阅读