Skip to content
Advertisement

How to remove a specific element from a 2d array in Python?

I am new to Python and now I’m trying to create a game called Pong

Everything looks to work fine but unfortunately, I can’t remove a specific element from 2D-Array /List once the ball touches a brick.

Here is my code:

JavaScript

In the following method, I want to remove the specific element:

JavaScript

I have tried many ways with remove() and del but as a result, I couldn’t solve it.

Thanks in advance.

Advertisement

Answer

using for loops just gives you a copy to the element (so you can’t modify it directly). To solve this problem, you should use the enumerate class:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement