任意の長さのコンテンツを持つタプルのリストを想定します。
quotes = [('Shakespeare', 'Piccard', 'Allen'),
("To be, or not to be", "Earl Grey, 60 degrees", "I feel that life is divided into the horrible and the miserable. That's the two categories. The horrible are like, I don't know, terminal cases, you know, and blind people, crippled. I don't know how they get through life. It's amazing to me. And the miserable is everyone else. So you should be thankful that you're miserable, because that's very lucky, to be miserable."),
('beer', 'tea', 'vodka')
]
デバッグの目的で、リストの内容を出力したいと思います。
print str(quotes)
ただし、タプル値の最初のN文字だけが必要です。3番目の引用符のように長い場合は、内容全体は必要ありません。リストを反復処理してから各タプルを反復処理して最初のN文字をスライスする関数を記述できることは知っていますが、Pythonであるため、より単純で、より短く、より「Pythonic」な方法があると思います。ある?
現在の例のXYソリューションを探しているわけではありません。これは、ポイントを説明するための単なる例です。