I have a problem, I will try to explain as best as I can. I have two lists with 3 items each. Each item in list1 has a score in list2.
List1= [[(3,4,5)], [(23,44), (23,5,3), (1,2)], [(23,5), (1,6)]]
List2= [2,4,1]
As you can see in list1, items 2 and 3 have multiple tuples that correspond to their score, I would like to separate them into their scores:
what I want:
List1= [(3,4,5), (23,44), (23,5,3), (1,2), (23,5), (1,6)]
List2= [2,4,4,4,1,1]
or
List1= [[(3,4,5)], [(23,44)], [(23,5,3)], [(1,2)], [(23,5)], [(1,6)]]
List2= [2,4,4,4,1,1]
so far, I have identified the items that needs changing.
double = [x for x in List1 if len(x)>1]
print(double)
[[(23, 44), (23, 5, 3), (1, 2)], [(23, 5), (1, 6)]]
I have found the index of these items:
indx = [i for y in double for i, x in enumerate(List1) if x== y ]
print(indx)
[1, 2]
I have flattened the nested list to get what I want in list1:
flat_list = [item for sublist in List1 for item in sublist]
[(3, 4, 5), (23, 44), (23, 5, 3), (1, 2), (23, 5), (1, 6)]
However I am not sure how I can change list2.
any help will be appreciated.
Thank you.