Preallocating list in python
I was looking for a way to preallocate a Boolean list in Python but didn't know a simple way.
After googling I got the following:-
# this would give us a 100 element list, each element initialized to False
flags = [False] * 100
'interesting' i thought but how do I explain this syntax ?
After looking at the Python language reference, I got the explanation:-
"The * (multiplication) operator yields the product of its
arguments. The arguments must either both be numbers, or one argument
must be an integer (plain or long) and the other must be a sequence.
In the former case, the numbers are converted to a common type and
then multiplied together. In the latter case, sequence repetition is
performed; a negative repetition factor yields an empty sequence."
source: http://docs.python.org/ref/binary.html