【发布时间】:2015-02-03 17:38:20
【问题描述】:
假设我们有一个像a = [['a','b','c'], ['aber', 'jsfn', 'ff', 'fsf', '003'], [...] ...] 这样的数组,其中每个元素可以有不同的大小。我想要做的是删除每个子数组的最后一项,如果它符合我设置的条件。所以我有:
for x in range(len(a)):
if the last item in x matches some condition that is set:
then remove the last item from x
因为我正在处理一个数组,所以我尝试了a.remove(-1),但这是错误的。那么,有没有什么简单的方法呢?
举个例子,如果我有:
for x in range(len(a)):
if the last element of each sub-array starts with an "S":
then remove the last item from that sub-array
我该如何处理?非常感谢任何示例或指向某些教程的链接。
【问题讨论】:
-
这个问题可能比可能的重复问题更细微,因为它指的是从子数组中移动项目。