Reputation: 101
I have a problem to combining array to multidimensional array.
My Array
['Fiat', 'black', 'new', 'BMW', 'white', 'new']
The result should look like this
[['Fiat'], ['black'], ['new'], ['BMW'], ['white'], ['new']]
What do I have to do to achieve this result?
I am newbie. Please help.
Upvotes: 1
Views: 59
Reputation: 107
Maybe you can try that:
a = ['Fiat', 'black', 'new', 'BMW', 'white', 'new']
b = []
for i in a:
b.append([i])
print(b) # u will see result..
Upvotes: 1
Reputation: 2790
That simplest way is probably to use a list comprehension:
>>> l = ['Fiat', 'black', 'new', 'BMW', 'white', 'new']
>>> [[x] for x in l]
[['Fiat'], ['black'], ['new'], ['BMW'], ['white'], ['new']]
Upvotes: 6