-1
My question is how to compare my list and filter it. The case would be if, the data entry on my list contains a list, I separate this list. I tried by type(list) but returned nothing. I appreciate the strength!
class SearchList():
def __init__(self, insert_list):
self.insert = insert_list
def exec_list(self):
for i in self.insert:
if i == type(list):
print(i)
my_list = ["a", "b", 1, 2, 3, ["x1", "x2", 4.7]]
prt_list = SearchList(my_list)
print(prt_list.exec_list())
if i == type(list)
, here you are comparing the Valor ofi
with the guy oflist
, That doesn’t make any sense. Why not do something liketype(i) == list
? It wouldn’t make more sense?– Woss
Wouldn’t it be easier to do
filter(lambda e: isinstance(e, list), my_list)
– Augusto Vasques