2

I have a list and a nested list in python that I want to combine. An example of the problem is below:

list_1 = [[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12],[13,14,15],[16,17,18]],[[19,20,21],
         [22,23,24],[25,26,27]]]
list_2 = ['23.43', '24.56', '25.78']

I want to combine the two list so I get the following result:

result = [['23.43',[1,2,3],[4,5,6],[7,8,9]],['24.56',[10,11,12],[13,14,15],[16,17,18]],
          ['25.78',[19,20,21],[22,23,24],[25,26,27]]]

I tried the following:

result = map(list.__add__, list_2, list_1)

But i got the following error:

TypeError: descriptor '__add__' requires a 'list' object but received a 'float'

I was wondering if there was a better way to approach this problem.

1 Answer 1

2

I believe this is what you're looking for, although you may have to modify it a bit to get it how you want your data:

   result = zip(list_1,list_2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.