0

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:

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.

2
  • Can you share the data type of the array? Commented Oct 18, 2022 at 20:24
  • 1
    yeah they are all numbers Commented Oct 18, 2022 at 20:32

2 Answers 2

1

If you want a list comprehension:

result = [l+[x] for l,x in zip(array, lst)]
Sign up to request clarification or add additional context in comments.

Comments

0

An alternative way to list comprehension if array is of the type numpy.ndarray:

result = numpy.c_[array, lst]

Please check this answer for more details.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.