How to remove all strings from a list of tuples in Python

1 Answer

0 votes
def instance_of_string(e): 
    return not isinstance(e, str) 

lst_tpl = [('python', 1), ('c++', 'c'), (3, 'php'), ('java', 4)]     

result = ([tuple(filter(instance_of_string, e)) for e in lst_tpl]) 
  
print(result) 




'''
run:

[(1,), (), (3,), (4,)]

'''

 



answered Dec 16, 2019 by avibootz
...