Remove object from a list of objects in python

后端 未结 7 1378
醉酒成梦
醉酒成梦 2020-12-09 14:20

In Python, how can I remove an object from array of objects? Like this:

x = object()
y = object()
array = [x,y]
# Remove x

I\'ve tried

7条回答
  •  轮回少年
    2020-12-09 14:59

    If you know the array location you can can pass it into itself. If you are removing multiple items I suggest you remove them in reverse order.

    #Setup array
    array = [55,126,555,2,36]
    #Remove 55 which is in position 0
    array.remove(array[0])
    

提交回复
热议问题