且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Python的嵌套列表中删除列

更新时间:2023-12-04 22:12:04

您可以使用

You can simply delete the appropriate element from each row using del:

L = [[1,2,3,4],
     [5,6,7,8],
     [9,1,2,3]]

for row in L:
    del row[1]  # 0 for column 1, 1 for column 2, etc.

print L
# outputs [[1, 3, 4], [5, 7, 8], [9, 2, 3]]