Possible Duplicate:
Initialize list with same bool value
I'm attempting to make a prime number generator in python 2.7 and plan to use an array (or list) of booleans which will indicate whether a given number is prime.
Let's say I wanted to initialize a list of 5000 booleans, how would I do so without having to manually type [True, True, ...]
You could try this:
[True] * 5000
Lists can be multiplied in Python (as can strings):
>>> [True] * 3
[True, True, True]
>>> "abc" * 3
'abcabcabc'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With