-1
I need to remove objects that have the same conta, saldo_devedor, and that the limite be equal to 0.
list = [
          {
            'conta': u'1.3.02', 
            'saldo_devedor': 999.08, 
            'limite': 2500.0
          }, 
          { 'conta': u'1.3.02', 
            'saldo_devedor': 999.08, 
            'limite': 0.0
          },
          { 'conta': u'1.3.03', 
            'saldo_devedor': 600.00, 
            'limite': 1000.00
          }
        ]
In this case there are 2 records that have the same conta and saldo_devedor, but the one that has the limite equal to 0 has to be removed, thus leaving the list:
list = [
          {
            'conta': u'1.3.02', 
            'saldo_devedor': 999.08, 
            'limite': 2500.0
          },
          { 'conta': u'1.3.03', 
            'saldo_devedor': 600.00, 
            'limite': 1000.00
          }
        ]
I tried an example I saw, but the error and I don’t know if that’s the way you can do it:
new_list = list(filter(lambda x, y: x.conta == y.conta and x.saldo_devedor == y.saldo_devedor and x.limit != 0, list_1))
Error:
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    new_list = list(filter(lambda x, y: x.conta == y.conta and x.saldo_devedor == y.saldo_devedor and x.limit != 0, list_1))
TypeError: <lambda>() missing 1 required positional argument: 'y'
What problem presented with your code?
– Augusto Vasques
I’m new to Python, so I don’t know how to do it,
new_list = filter(lambda x, y: x.conta == y.conta and x.saldo_devedor == y.saldo_devedor and x.limit == 0, list_1), I tried that there, but it didn’t work.– ALE_ROM
Would do using
for(instead of using filter and lambda)?– Danizavtz
Use a
foreven to solve, but I wonder if you have a better solution.– ALE_ROM