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.

medium-dimensional
  • 1,974
  • 10
  • 19

2 Answers2

1

If you want a list comprehension:

result = [l+[x] for l,x in zip(array, lst)]
mozway
  • 194,879
  • 13
  • 39
  • 75
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.

medium-dimensional
  • 1,974
  • 10
  • 19