python - python中列表的数据清理
问题描述
我已经阅读了 dvd 标题描述和价格作为列表中的句子,DVD 的标题以 [t] 开头,例如:
['[t] the little mermaid.','disney fairytale','price of this $5.99', '[t] star wars.','disney fantasy','price $6']
如何从列表中删除整个标题.. 所以以 [t] 开头的项目因此列表将只有描述和价格。
我尝试使用 list.remove 但这仅删除了 [t] 而不是 dvd 标题
解决方案
你可以使用startswith
:
lst = ['[t] the little mermaid.','disney fairytale','price of this $5.99', '[t] star wars.','disney fantasy','price $6']
print([i for i in lst if not i.startswith('[t] ')])
输出:
['disney fairytale', 'price of this $5.99', 'disney fantasy', 'price $6']
推荐阅读
- swift - 访问 iCloud 日历事件 - macOS 应用程序
- sql-server - SQL 链接服务器 - 查询失败
- botframework - 如何将用户的文本转发到另一个对话框
- tensorflow - 如何在张量流中分配张量的元素
- hangfire - Hangfire 作业卡在处理状态
- sql - 仅返回满足 2 个或更多条件的行
- java - Hibernate 使用 java.sql.Date 错误吗?
- reactjs - 无法从用户输入数据更新反应状态
- android-linearlayout - 使用 Constraint Layout 开发 TV android Apps
- python - 最接近python中的虚拟调用