Cody Bable

Generation

generate functionThu, 13 Apr 2023

divide list ['a', 'b', 'c', '1', '2', '3'] into three separate list

def divide(): string_list = ['a', 'b', 'c', '1', '2', '3'] list_1 = [] list_2 = [] list_3 = [] for item in string_list: if item.isalpha(): list_1.append(item) elif item.isdigit(): if int(item) % 2 == 0: list_2.append(item) elif int(item) % 2 ==1: list_3.append(item) return list_1, list_2, list_3 divide()

Questions about programming?Chat with your personal AI assistant