I have two lists of tuples:
a=[(name_2,array_2),(name_7,array_7),...,(name_n,array_n)]
b=[(name_3,arr_3),(name_12,arr_12),...,(name_n,arr_n)]
I want to combine them depending on their name which is the first value of each tuple in each set. The lists are not sorted by name. The result shall look like:
combined=[(name_1,array_1,arr_1),(name_2,array_2,arr_2),...,(name_n,array_n,arr_n)]
Is there any more effective solution than iterating with two pointers?
>Solution :
sorted_a = sorted(a, key=lambda x: x[0])
sorted_b = sorted(b, key=lambda x: x[0])
combined = [(sorted_a[idx][0], sorted_a[idx][1], sorted_b[idx][1]) for idx in range(len(a))]