I have a list of tuples which in turn have 2 elements and a list. I wish to delete the tuples that have empty lists.
l = [('Receipt total', []), ('Total Amount (AED)', []), ('Grand total', []), ('Net Amount', []), ('Total Amount', ['593.52']), ('Net total ', []), ('Total', []), ('Gross Amount', []), ('Total Bill (AED)', []), ('Total AED', []), ('Net total in AED', []), ('Total (AED)', []), ('Total Invoice Amount', []), ('Invoice total', []), ('Amount Due', []), ('Grand Total (AED)', []), ('Total Amount Payable', []), ('Net Amt', []), ('Before Total', [('28.26n', '28.26n')]
Expected output:
l = [('Total Amount', ['593.52']), ('Before Total', [('28.26n', '28.26n')]
I tried :
l = [t for t in i if t != [] for i in l]
It throws me a Memory Error
Advertisement
Answer
One way using list
comprehension with unpacking:
[(i, j) for i, j in l if j]
Output:
[('Total Amount', ['593.52']), ('Before Total', [('28.26n', '28.26n')])]