0
test_list = [2,123,1234,3,4,5345,345,334,534,534,-566546,-3,2321,-23132,-12,-31,23,-12,(),(),(3,5)]
for i in test_list:
    if i == ():
        test_list.remove(i)
print(test_list)

I have written this code to remove all the empty tuples in the list.

I have tried other ways and they have worked but this one way is not working correctly. Only a single tuple is deleted rater than all (both) of them. Please explain why it is not giving me results as expected.

darshan
  • 1
  • 2
  • general rule of thumb, do not delete the thing you are iterating over. Create a new list and assign it to original variable. – Albin Paul Nov 24 '22 at 11:05

0 Answers0