0

i got two lists:

L_1 = ['Value1', 'Value2', 'Value3', 'Value 4']
L_2 = [['Value1', 'Value1_01'], ['', 'Value1_02'], ['', 'Value1_03'], 
 ['Value2', 'Value2_01'], ['', 'Value2_02'], 
 ['Value3', 'Value3_01'], ['', 'Value3_02'], ['', 'Value3_03'], ['', 'Value3_04']
 ['Value4', 'Value4_01'], ['', 'Value4_02']]

from this i need a list that assign the elements Value1 to Value4 to their 'littler sisters'. should look like this:

L1 = ['Value1', 'Value2', 'Value3', 'Value 4']
L_res = [['Value1_01', 'Value1_02', 'Value1_03'], 
 ['Value2_01', 'Value2_02'], 
 ['Value3_01', 'Value3_02', 'Value3_03', 'Value3_04']
 ['Value4_01', 'Value4_02']

i need to count where L2[i][0] == '' or L2[i][0] == L1[i] and then give me the values from L2[i][1] and put it to L_res

Hopefully someone of you understand the problem and has got an idea to solve the problem.

I really appreciate this

asked Mar 10, 2020 at 15:27

1 Answer 1

1

This should do the trick:

L_res = []
for i in L_2:
 if i[0]:
 L_res.append([i[1]])
 else:
 L_res[-1].append(i[1])
L_res
# [['Value1_01', 'Value1_02', 'Value1_03'],
# ['Value2_01', 'Value2_02'],
# ['Value3_01', 'Value3_02', 'Value3_03', 'Value3_04'],
# ['Value4_01', 'Value4_02']]
answered Mar 10, 2020 at 15:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.