Python のクラスで考えられるすべての用途についてitertools.repeat()
、同じ効果を達成するための、同等に (場合によってはそれ以上の) 受け入れ可能な別のソリューションを考えることができます。例えば:
>>> [i for i in itertools.repeat('example', 5)]
['example', 'example', 'example', 'example', 'example']
>>> ['example'] * 5
['example', 'example', 'example', 'example', 'example']
>>> list(map(str.upper, itertools.repeat('example', 5)))
['EXAMPLE', 'EXAMPLE', 'EXAMPLE', 'EXAMPLE', 'EXAMPLE']
>>> ['example'.upper()] * 5
['EXAMPLE', 'EXAMPLE', 'EXAMPLE', 'EXAMPLE', 'EXAMPLE']
itertools.repeat()
最も適切な解決策になるケースはありますか? もしそうなら、どのような状況で?