python-3.x - Python slice all except the second to last row in an array
问题描述
I know how to slice an array with all except a row at the beggining or end of an array but not an array with just one row in the middle (like the second to the last row) missing. How would I do this?
解决方案
要使用切片从中间删除一个项目,您几乎总是需要连接两个不同的切片,一个用于之前的项目,一个用于之后的项目。如果n
是您要删除的项目的索引,您通常可以这样做
new_list = old_list[:n] + old_list[n+1:]
推荐阅读
- sql-server - 可空列的 NULL 默认约束
- android - Chrome 检查器无法正确连接到 Cordova 应用程序
- c++ - 使用 dpbtrf 时出现分段错误
- python - 不和谐机器人没有响应
- node.js - 注销所有设备、NodeJS 和 Angular 6
- cocoa - 为什么我的 NSBox 会画背景?(boxType = .primary)
- algorithm - 如何获得装箱算法的前 N 个解决方案?
- python - 在 Pandas 中查找 groupby 之后与最大日期相关的行
- java - springSecurityFilterChain - ObjectPostProcessor 是必需的 bean 异常
- amazon-web-services - 使用 ApiGateway Authorizer 验证 Github Payload Signature (X-Hub-Signature)