Trying to match key, values in dictionaries with nested list elements
dict = {'a':[1, 5], 'c':[7, 9], 'f':[10, 12], 'b':[15, 20]}
list_A = [['a', '4'], ['a', '7'], ['b', '17'], ['b', 10], ['c', '7'], ['d', '7'], ['f', '11'], ['f', '12']]
list_A_no_reps =['a', 'b', 'c', 'd', 'f']
I am trying to get a list which has the values that match with list_A and dict i.e. as in the values of list a ( the second elements in the nested lists) should lie between the value list pair of the dict.
match_list = [['a', '4'], ['b', '17'], ['c', '7'], ['f', '11'], ['f', '12']]
I am trying to first match the keys of dict with list_A_no_reps and if there is a match, I am trying to find out if it lies between the values of each key, value pair. I have this so far:
g = []
for key, values in dict.items():
for element in list_A_no_rep:
if key == element:
for cord in list_A:
if (values[0] <= int(cord[1]) <= values[2]):
g.append(cord)
I would group the sublists in a dict by the first element which is the letter then iterate over your original dict and check if each key is in the grouping dict and do your comparison.
Or use viewkeys to get the common keys:
Or just loop over listA: