Hi please how can I loop through lst2, check for the matching ones and the sum up the value of v in the in the corresponding dictionary.
i.e. if the elements of ('1','2') in lst2 matches the '1', '2' in lst1, get the value of v ie 5 and add the v values for all the tuples in that list of list.
lst1 = [('1','2',{"v" : 5, "a" : 3}),('7','9',{"v" : 7, "a" : 3}),('3','4',{"v" : 4, "a" : 3}),('1','6',{"v" : 0, "a" : 3}),('2','9',{"v" : 4, "a" : 3})]
lst2 = [[('1','2'),('2','9')], [('1','6'),('7','9')]]
output should be vol = 5 + 4 = 9 for [('1','2'),('2','9')]
please I tried this and it did give the desired output. Please help
vol = []
f = 0.0
for b in lst2:
if float(b[0][0]) == float(lst1[0][0]) and float(b[0][0])== float(lst1[0][1]):
f = f + float(lst1[0][0][v])
vol.append(f)
lst1to a dictionary with the format{('1', '2'): {'v': 5, 'a': 3}, ('7', '9'): {'v': 7, 'a': 3}}(and so on for the other elements).