Say I have 2 lists:
list_a=[1, 5, 10, 11]
list_b = [2, 3, 4, 6, 7, 8, 9, 12, 13]
I want to create the following dictionary:
[{1: [2, 3, 4]}, {5: [6, 7, 8, 9]}, {10: []}, {11:[12,13]}]
such that any numbers in list_b that are higher than an item in list_a but less than a succeeding item in the same list are appended together in a list.
Please let me know if you have any doubts about the question.
My attempt:
for x in range(len(list_a)-1):
temp=[]
for y in range(x,len(list_b)):
if list_b[y] < list_a[x+1] and list_b[y]>list_a[x]:
temp.append(list_b[y])
result.append({list_a[x]:temp})