Issue
Suppose that you have the python list:
a = ["a", " ", "b", "i", "g", " ", "d", "o", "g", " ", "b", "i", "t", " ", "m", "e"]
Is there a way to split this list such that you get:
a = [["a"],["big"],["dog"],["bit"],["me"]]
or similar?
Solution
Something like this:
>>> a = ["a", " ", "b", "i", "g", " ", "d", "o", "g", " ", "b", "i", "t", " ", "m", "e"]
>>> ''.join(a)
'a big dog bit me'
>>> [[word] for word in ''.join(a).split()]
[['a'], ['big'], ['dog'], ['bit'], ['me']]
Answered By - funnydman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.