I'd like to remove repetitive code but I'm stuck. I want the for loop to iterate through a list and append the object to another list depending on if the list has "red","blue",or "green" in it. I'm also trying to remove None data and strings of the names of the list. Not quite sure what to do here but I'd really appreciate some help!
for item in sublist:
if "red" in sublist:
red_list.append(item)
if "blue" in sublist:
blue_list.append(item)
if "green" in sublist:
green_list.append(item)
red_list = list(filter(None, red_list)
blue_list = list(filter(None, blue_list)
green_list = list(filter(None, green_list)
red_list.remove("red")
blue_list.remove("blue")
green_list.remove("green")
I've tried appending the items to a dictionary instead of three separate lists and that has been helpful, but I'm still not sure what to do about the for loop and if statements.