1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| items = ["Mac", "Phone", 123.11, 462.14, "Jason", "Bag", 512]
str_items = [] num_items = []
for i in items: if isinstance(i, float) or isinstance(i, int): num_items.append(i) elif isinstance(i, str): str_items.append(i) else: pass
print(str_items) print(num_items)
def parse_lists(some_list): str_list_items = [] num_list_items = [] for i in items: if isinstance(i, float) or isinstance(i, int): num_list_items.append(i) elif isinstance(i, str): str_list_items.append(i) else: pass return str_list_items,num_list_items
print(parse_lists(items))
|