Set up
It looks like you're using the numpy package because your code has array(...)
and dtype=...
formatting. So, to prepare to show code examples, I did these commands:
import numpy as np
a = np.array([['T-Shirts', '1 Piece'], ['Capris', 'Leggings', 'Skirts']])
After those, when I enter:
a
I get this result (your starting point):
array([['T-Shirts', '1 Piece'], ['Capris', 'Leggings', 'Skirts']], dtype=object)
Desired output
When I do this command:
[[[x] for x in l] for l in a]
I get this result:
[[['T-Shirts'], ['1 Piece']], [['Capris'], ['Leggings'], ['Skirts']]]
The command I ran was a Python list comprehension. It is syntactic sugar for making a list with for loops. You can read more here or by searching for "python list comprehension".
Note: I did not use numpy for that conversion. If you want the same kind of list you had before, you could place the code inside np.array( )
, like this:
np.array([[[x] for x in l] for l in a])
The result of that command is:
array([[['T-Shirts'], ['1 Piece']], [['Capris'], ['Leggings'], ['Skirts']]], dtype=object)
Bonus
Also, on a side note, you can do this:
[[x] for l in a for x in l]
and get this:
[['T-Shirts'], ['1 Piece'], ['Capris'], ['Leggings'], ['Skirts']]