タプルを含む単一のリストの最も単純な例は次のとおりです。
[x[1] for x in myList]
# [None, None, None, None]
または、常にタプルの最後の値である場合 (2 つ以上の値が含まれている場合):
[x[-1] for x in myList]
# [None, None, None, None]
以下の例では、ネストされたリストを使用していることに注意してください。タプルを含むリストのリストです。リストの2つのバリエーションを表示していたので、それがあなたが探していたものだと思いました.
ネストされた内包リストを使用します。
myList =[ [(' whether', None), (' mated', None), (' rooster', None), ('', None)] ,
[(' produced', None), (' without', None), (' rooster', None), (' infertile', None), ('', None)] ]
print [[x[1] for x in el] for el in myList]
# [[None, None, None, None], [None, None, None, None, None]]
またはいくつかの他のバリエーション:
myList =[ [(None, None), (' mated', None), (' rooster', None), ('', None)] ,
[(' produced', None), (' without', None), (' rooster', None), (' infertile', None), ('', None)] ]
# If there are multiple none values (if the tuple isn't always just two values)
print [ [ [ x for x in z if x == None] for z in el ] for el in myList ]
# [[[None, None], [None], [None], [None]], [[None], [None], [None], [None], [None]]]
# If it's always the last value in the tuple
print [[x[-1] for x in el] for el in myList]
# [[None, None, None, None], [None, None, None, None, None]]
参照:
SO: ネストされたリスト内包表記について