slicing list of lists in Python

后端 未结 6 1537
旧巷少年郎
旧巷少年郎 2020-12-10 14:40

I need to slice a list of lists in python.

A = [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]]
idx = slice(0,4)
B = A[:][idx]

The code above isn\'t

6条回答
  •  遥遥无期
    2020-12-10 14:58

    I am new in programming and Python is my First Language. it's only 4 to 5 days only to start learning. I just learned about List and slicing and looking for some example I found your problem and try to solve it Kindly appreciate if my code is correct. Here is my code A = [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]] print(A[0][0:3],A[1][0:3],A[1][0:3])

提交回复
热议问题