Remove a column from a nested list in Python
list, python
Solution
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]]
Problem
I need help figuring how to work around removing a 'column' from a nested list to modify it. Say I have ``` L = [[1,2,3,4], [5,6,7,8], [9,1,2,3]] ``` and I want to remove the second column (so values 2,6,1) to get: ``` L = [[1,3,4], [5,7,8], [9,2,3]] ``` I'm stuck with how to modify the list with just taking out a column. I've done something sort of like this before? Except we were printing it instead, and of course it wouldn't work in this case because I believe the break conflicts with the rest of the values I want in the list. ``` def L_break(L): i = 0 while i < len(L): k = 0 while k < len(L[i]): print( L[i][k] , end = " ") if k == 1: break k = k + 1 print() i = i + 1 ``` So, how would you go about modifying this nested list? Is my mind in the right place comparing it to the code I have posted or does this require something different?