I have two lists. One gives me the IDs, say:
list1 = [0, 0, 0, 0, 1, 1, 2, 3, 3, 3]
Another gives me values associated with those IDs, say:
list2 = [10, 20, 30, 40, 1, 5, 9, 10, 15, 20]
I want to organize the values of list2 based on the values in list1, such that:
dict = {0:[10,20,30,40], 1:[1, 5], 2:[9], 3:[10,15,20]}
My current problem is that I need an efficient way to do this since my lists are ~150000 points long and my solution is very slow:
dict = {i:list2[np.where(np.array(obid)==i)] for i in np.unique(list1)}
Seems like a simple problem and perhaps there is an obvious answer but I just can't seem to find the right combination of words to get a good answer.