1

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.

2 Answers 2

6

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']]
Sign up to request clarification or add additional context in comments.

Comments

1

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..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.