1

I have a list of lists of strings. It looks like this:

[['okay'],
 ['d', 'so'],
 ['i', 'guess']]

I want further nest each string inside of list so it looks like this:

[[['okay']],
 [['d'], ['so']],
 [['i'], ['guess']]]

Please advise on how to do this. Thank you.

1
  • I added an answer to your question. Commented Oct 1, 2019 at 1:44

1 Answer 1

1

Use the following list comprehension

[[[s2] for s2 in s1] for s1 in l]

Running example:

>>> l =  [['okay'],
 ['d', 'so'],
 ['i', 'guess']]
>>> [[[s2] for s2 in s1] for s1 in l]
[[['okay']], [['d'], ['so']], [['i'], ['guess']]]
Sign up to request clarification or add additional context in comments.

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.