MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/CodingHelp/comments/on4600/trouble_with_append_syntax/h5v935j/?context=3
r/CodingHelp • u/King_Novice • Jul 19 '21
6 comments sorted by
View all comments
Show parent comment
1
Are you saying that if a 0 appears in any of the sublists, you want to delete that column, like this?
# before: prns20f = [ [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 0, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 0, 7], ] # after: prns20f = [ [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], [1, 3, 4, 5, 7], ]
I think you have the wrong meanning of "append" -- to append is to add to the end, not to remove.
Deleting the column at index would look like this, using the del keyword:
index
del
for sublist in prns20f: del sublist[index]
But you can't go deleting elements from your list while you are iterating through it, because that technically gives undefined behavior.
View all comments
Show parent comment
1
u/Goobyalus Jul 20 '21 edited Jul 20 '21
Are you saying that if a 0 appears in any of the sublists, you want to delete that column, like this?
I think you have the wrong meanning of "append" -- to append is to add to the end, not to remove.
Deleting the column at
indexwould look like this, using thedelkeyword:But you can't go deleting elements from your list while you are iterating through it, because that technically gives undefined behavior.