在某些Characer上拆分列表

时间:2017-04-10 07:09:59

标签: python

说我有一个类似的列表:

['Try not to become a man of success, but rather try to become a man of value.
\n', 'Look deep into nature, and then you will understand everything 
better.\n', 'The true sign of intelligence is not knowledge but imagination.
\n', 'We cannot solve our problems with the same thinking we used when we 
created them. \n', 'Weakness of attitude becomes weakness of character.\n', 
"You can't blame gravity for falling in love. \n", 'The difference between 
stupidity and genius is that genius has its limits. \n']

如何在每个换行符中将此列表拆分为子列表? 如何将上面的输出转到下面的所需输出?

['Try not to become a man of success, but rather try to become a man of value.'] 
['Look deep into nature, and then you will understand everything better']  ['The true sign of intelligence is not knowledge but imagination.] 

1 个答案:

答案 0 :(得分:1)

您的预期结果看起来像项目列表,其中每个项目都是一个列表,其中包含一个由删除空格的列表项组成的单个元素,可以通过以下方式实现:

result = [[line.strip()] for line in lines]