最も単純なものは、リスト内包表記を使用することです:
In [126]: lis=[('Knightriders',), ('The Black Knight',), ('Fly by Knight',), ('An Arabian Knight',), ('A Bold, Bad Knight',)]
In [127]: [x[0] for x in lis]
Out[127]:
['Knightriders',
'The Black Knight',
'Fly by Knight',
'An Arabian Knight',
'A Bold, Bad Knight']
または使用itemgetter
:
In [128]: from operator import itemgetter
In [129]: list(map(itemgetter(0),lis))
Out[129]:
['Knightriders',
'The Black Knight',
'Fly by Knight',
'An Arabian Knight',
'A Bold, Bad Knight']
また:
In [131]: [next(x) for x in map(iter,lis)]
Out[131]:
['Knightriders',
'The Black Knight',
'Fly by Knight',
'An Arabian Knight',
'A Bold, Bad Knight']
またはzip()
@DSMの提案に従って使用:
In [132]: zip(*lis)[0]
Out[132]:
('Knightriders',
'The Black Knight',
'Fly by Knight',
'An Arabian Knight',
'A Bold, Bad Knight')
または使用ast.literal_eval
(最も推奨されない解決策、またはこれを試してはならない可能性があります):
In [148]: from ast import literal_eval
In [149]: literal_eval(repr(lis).replace(",)",")"))
Out[149]:
['Knightriders',
'The Black Knight',
'Fly by Knight',
'An Arabian Knight',
'A Bold, Bad Knight']