-2

I have a numpy array

arr = np.array([
        [1, (10, 20, 30, 40)],
        [2, (10, 20, 30, 40)],
        [5, (11, 22, 33, 44)]
      ])

I wonder if there's a way that I can get :

ans = [
        [1, 10, 20, 30, 40],
        [2, 10, 20, 30, 40],
        [5, 11, 22, 33, 44]
      ]

using list comprehension in python.

I've tried:

ans = [list(row[1]).append(row[0]) for row in arr]

but got [None, None, None] as the output

1 Answers1

0

append returns None, not the list being appended to. (Also, append would insert the item at the wrong end anyway.)

ans = [[x, *y] for x, y in arr]
chepner
  • 497,756
  • 71
  • 530
  • 681