Check if the strings inside a list of tuples contain whitespace and remove the tuple if true

24 views Asked by At

I have a list of tuples:

[('a', 'a', 'a'), ('b', 'b', 'b), ('c',' \n     \n      \n ', 'c'), ('d', 'd', 'd'),('e', ' \n        \n      \n ', 'e'] 

I want to delete the tuples that contain whitespace. My code is:

for tuple in list:
    for string in tuple:
        if string.isspace()  == True:
            list.remove(tuple)

It only deletes the second of the tuples with whitespace. If I re-execute the code it deletes the other as well.

0

There are 0 answers