-1

私は2次元リストを持っています

a= [['Turn', 'the', 'light', 'out', 'now'], ['Now', ',', 'I', 'll', 'take', 'you', 'by', 'the', 'hand'], ['Hand', 'you', 'anoth', 'drink'], ['Drink', 'it', 'if', 'you', 'can'], ['Can', 'you', 'spend', 'a', 'littl', 'time'], ['Time', 'is', 'slip', 'away'], ['Away', 'from', 'us', ',', 'stay'], ['Stay', 'with', 'me', 'I', 'can', 'make'], ['Make', 'you', 'glad', 'you', 'came']]

このリストから値の範囲を取得する簡単な方法はありますか?

私が書く場合:

print a[0][0] 

「ターン」と出ますが、リストから複数のものを切り出して新しいリストを作る方法はありますか?値が i=0 で n=2 の場合、a=[i][n] で始まる新しいリストを作成し、そのインデックスの両側にリスト アイテムを含む新しいリストを作成しようとしています。

助けてくれてありがとう

4

1 に答える 1

0

多分あなたが意味する

print a[0][0:2]

また

print [d[0] for d in a]
于 2013-07-02T20:38:10.703 に答える