I have the list called 'list_one', which I seek to relate to 'list_relation', to finally have a final list of values, my logic is as follows:
By looping in the range of 'list_one' and for each 'items_relation' of 'list_relation':
1.If 'list_one [i] [0]' is inside 'items_relation', I add the corresponding operation of 'list_one'.
list_one = [[1, 0],
[2, 0],
[3, 0],
[4, 0],
[11, 0],
[12, 0],
[13, 2000],
[14, 3000],
[15, 3500],
[16, 5000],
[17, 6500],
[18, 8800],
[19, 6700],
[20, 280]]
# Code to get this 'list_relation' ...
list_relation = [[13, 14], [15, 16],
[17, 18], [19, 20]]
final = []
for i in range(len(list_one)):
for items_elements in list_relation:
for k in items_elements:
if list_one[i][0] in items_elements:
final.append((list_one[i][1] + list_one[i][0]))
print(final)
I am looking for a list like this:
[[2013, 3014], [3515, 5016], [6517, 8818], [6719, 300]]
What is the best way to do it? Thank you.