I have two lists
list1 = [577, 553, 613, 673, 773, 827, 923, 963, 993, 1049, 1117, 1153, 1173, 1183]
list2 = ['Al,', 'Alan', 'Latin', 'Amer', '2', 'P', '1', 'vo', '|', '1', 't', '|', '2', 'Avg']
If the difference between list1 adjacent elements is < 75 keep joining corresponding elements in list2 until condition met, if condition fails current element to the output and move on
Output is like
['Al, Alan Latin Amer', '2 P', '1 vo | 1 | 2 Avg']
I have tried the below logic but its just joining only two elements
for i in list2:
indx_val = list2.index(i)
if indx_val !=0:
if list1[indx_val] - list1[indx_val-1] < 75:
list2[indx_val - 1] = list2[indx_val -1] +' '+ list2[indx_val]
list1.pop(indx_val)
list2.pop(indx_val)
And giving output as
['Al, Alan', 'Latin Amer', '2 P', '1 vo', '| 1', 't |', '2 Avg']
can you please help me in getting the output as below?, Thanks in advance
['Al, Alan Latin Amer', '2 P', '1 vo | 1 | 2 Avg']