1

input:

letters = [['a', 'b', 'c'], ['a', 'b', 'c']]
row= 0
column=0

output

[['b', 'c'], ['a', 'b', 'c']]

I tried to do this:

letters[0].remove(0)

but it gives me a value error, while when I use pop like this:

letters[0].pop(0) 

it does what I need but the problem with pop is that it returns me something while I just need the item to be removed

11
  • Just ignore the return value. Commented Jul 25, 2022 at 17:27
  • so there is no way to do it by just using remove? Commented Jul 25, 2022 at 17:28
  • 2
    The argument to remove() is the value, not the index. Commented Jul 25, 2022 at 17:29
  • and there is no way to make it take the index?? Commented Jul 25, 2022 at 17:30
  • 1
    If this column in pandas, It's raising errors because your column getting different length with other columns Commented Jul 25, 2022 at 17:31

3 Answers 3

3
letters = [['a', 'b', 'c'], ['a', 'b', 'c']]

del list1[0][0]

use the del keyword

Sign up to request clarification or add additional context in comments.

Comments

1
  • list.remove() removes an item by value, not by index. So letters[0].remove('b') would work.
  • Simply deleting a single element with the same syntax, you could address it in any other statement is del which could be used as del letters[0][0]
  • As @Barmar said: list.pop) can return an element by index and remove it from the list.

Comments

0

You can try this if you want to delete the element by index value of the list:

del letters[0][0]  # [['b', 'c'], ['a', 'b', 'c']]
del letters[1][0]  # [['a', 'b', 'c'], ['b', 'c']]

or if you want remove specific value in the first occurance:

letters[0].remove('a')  # [['b', 'c'], ['a', 'b', 'c']]
letters[1].remove('a')  # [['a', 'b', 'c'], ['b', 'c']]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.