2017-04-10 13 views
-1

のリストは、私がこのような何かを行くリストを持っていると言う:分割特定Characer

['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.] 
+2

あなたのリスト既に分割されているようです。最初の例のコンマを見てください。リストのリストを作成したいですか? – umutto

+0

あなたが達成したいことがわかりません。新しい行の文字 '\ n'を削除し、各要素をそれ自身のリストに変換したい場合、' '[phrase in arr]' '[phrase.strip()]' – user2829759

答えて

1

あなたの期待される結果は使用して達成することができるもの、各項目は空白を取り除いたリスト項目で構成される単一の要素を含むリストにあるアイテムのリストのように思える:

result = [[line.strip()] for line in lines] 
関連する問題