2017-01-13 9 views
0

は考えます私は地図3リスト

[[1,'one','first'],[2,'two','second','third'],[3,'three','third']] 

のように1つのリストにこれを結合する必要がある3つのリスト

[1,2,3] 
['one','two','three'] 
['first','second','third'] 

を持ってどのように我々はリスト内包を使用していますか?これを行うのですか他の最良の方法はありますか?

答えて

3

使用zip

>>>list(zip([1,2,3],['one','two','three'],['first','second','third'])) 
[(1, 'one', 'first'), (2, 'two', 'second'), (3, 'three', 'third')] 

または

>>>list(map(list, zip([1,2,3],['one','two','three'],['first','second','third']))) 
[[1, 'one', 'first'], [2, 'two', 'second'], [3, 'three', 'third']] 

注リストのリストとして:最も外側のlist呼び出しがmap/zip機能の即時評価を提供するためにのみ存在し、あなたがする場合は必要ありません後でそれらを繰り返します。