Remove object from a list of objects in python

后端 未结 7 1374
醉酒成梦
醉酒成梦 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 15:12

    If you want to remove multiple object from a list. There are various ways to delete an object from a list

    Try this code. a is list with all object, b is list object you want to remove.

    example :

    a = [1,2,3,4,5,6]
    b = [2,3]
    
    for i in b:
       if i in a:
          a.remove(i)
    
    print(a)
    

    the output is [1,4,5,6] I hope, it will work for you

提交回复
热议问题