1

I have a 3D array with lists in lists but i want each seperate list to become just one value in the list.

eg.

[['q', 'w', 'e'], ['w', 'e', 'r'], ['e', 'r', 't'], ['r', 't', 'y']] 

is my 3D array with lists in lists and i want to convert this list into:

[qwe, wer, ert, rty]

effectively joining up the lists into 1 element in the list.

Is there a simple way to do this?

2
  • 1
    That's not a 3d array, but a 2d list. Commented Feb 1, 2018 at 21:52
  • What's the value of that qwe variable? Commented Feb 1, 2018 at 22:02

2 Answers 2

2

You can join these together with ''.join, and we can define a mapping over it:

>>> list(map(''.join, data))
['qwe', 'wer', 'ert', 'rty']
Sign up to request clarification or add additional context in comments.

Comments

2

You can do something like:

>>> [['q', 'w', 'e'], ['w', 'e', 'r'], ['e', 'r', 't'], ['r', 't', 'y']]
>>> [''.join(l) for l in _]

Output:

['qwe', 'wer', 'ert', 'rty']

1 Comment

That is not the output, but the input.

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.