2016-12-11 7 views

答えて

3

である必要があり、単純に3つの項目各反復とリスト生成する必要がありますあなたのリスト内包:

output = [[word, len(word), word.upper()] for word in sent] 

デモ:

>>> sent = "this is a fun day" 
>>> sent = sent.split() 
>>> [[word, len(word), word.upper()] for word in sent] 
[['this', 4, 'THIS'], ['is', 2, 'IS'], ['a', 1, 'A'], ['fun', 3, 'FUN'], ['day', 3, 'DAY']] 
1

あなたはリストの理解に必要な任意の式を使用できます。この場合、リスト:

newList = [[ch, len(ch), ch.upper()] for ch in sent] 
関連する問題