How to sort nested lists into seperate lists with unique values in python?
I have two variables: unique_val = [1,2,3] nested_list = [['name1',1],['name2',1],['name3',3],['name4',2],['name5',2],['name6',3]] Basically I want separate lists of the names at each unique value. I struggled to put together a set of nested for loops to no avail. Ideally the output would be something like this: list_1 = ['name1','name2'] list_2 = ['name4','name5'] list_3 = ['name3',name6'] Creating variables for each item in unique_val is not a good idea. Instead of hard coding everything better use a dict with keys like list_1 as it'll handle any number number of variables. >>> from