2015-07-22 135 views
-4

的名单我有这样一个字符串列表:列表映射到列表

mylist = ["This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave.", "I hate this movie."] 

我想扩大mylist尺寸:

[["This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave."], ["I hate this movie."]] 

我怎样才能做到这一点?

+2

好的,你是Python新手,但我敢打赌,你至少在编码方面尝试过,对吧? – Raptor

+0

你的意思是你想把列表中的每个字符串转换成一个单词列表? –

+0

是的。我仍在寻找解决方案。对不起,如果它是烦你 – Ideal

回答

1
list_of_strings = ["string one", "string two", "etc."] 
list_of_lists = [x.split() for x in list_of_strings] 
+0

FWIW,这根本不适用于改写的问题,但它是对原始问题的回答。 –

0

这个怎么样?

import itertools 
str = ["This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave.", 'I hate this movie.'] 
result = list(itertools.chain.from_iterable([i.split() for i in str ])) 

但如果我是你,我会写的几行,使之可读。

1
>>> mylist = ["This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave.", "I hate this movie."] 
>>> [[x] for x in mylist] 
[['This is quite possibly the worst movie ever made. Even my 4 year old hated it and wanted to leave.'], ['I hate this movie.']]