Malcolm Moss
Malcolm Moss

Reputation: 1

Removing a specific list from an array

I have this list

list = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 1], [2, 2], [2, 0]]

I want to take 2 integers

row = 2 and column = 1

Combine them

thing = (str(row) + str(", ") + str(column))

then I want to remove the list

[2, 1]

from the array. How would I do this?

EDIT: The language is Python

Upvotes: 0

Views: 71

Answers (1)

Nils Werner
Nils Werner

Reputation: 36765

First of all, don't name your list list. It will overwrite the builtin function list() and potentially mess with your code later.

Secondly, finding and removing elements in a list is done like

data.remove(value)

or in your case

data.remove([2, 1])

Specifically, where you are looking for an entry [row, column], you would do

data.remove([row, column])

where row and column are your two variables.

It may be a bit confusing to name them row and column, though. because your data could be interpreted as a matrix/2D array, where "row" and "column" have a different meaning.

Upvotes: 1

Related Questions