Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

combining array and list elemint by index

I have an array (which comes from a kdtree):

array =  [[a b c d e]
          [a b c d e]
          [a b c d e]]

and a list :

lst = [1, 2, 3, 4, 5]

I want to do some list comprehension (using array and lst) that makes it look like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

desired_result = [[a, b, c, d, e, 1]
                  [a, b, c, d, e, 2]
                  [a, b, c, d, e, 3]]

I am familiar with list comprehension just not familiar enough to know how to deal with this.

>Solution :

If you want a list comprehension:

result = [l+[x] for l,x in zip(array, lst)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading