Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Python内包表記で定数のリストをどのように生成するのか疑問に思っていましたか?
たとえば、100 個の 5 のリストを生成したい場合、どうすればよいでしょうか?
リスト内の要素の数を追跡する方法が、出力したいものとは異なるため、これを理解するのに苦労しています。
できるよ:
my_list = [5 for _ in xrange(100)]
次のこともできます。
import itertools my_list = list(itertools.repeat(5, 100))