array of bits?
Fredrik Lundh
fredrik at pythonware.com
Mon Feb 14 17:21:25 EST 2005
"MM" wrote:
> What is the best structure/way to create an array of bits (actually true/false flags) of an
> arbitrary length ranging from about 20 upto about 500. Speed of access more of an issue than
> compactness.
>
> eg:
> [0] 0
> [1] 0
> [2] 1
> [3] 0
> [4] 1
> ...
> [n] 0
> etc.
if you need a list of flags, use a list of flags:
[False] * 500
(compared to a bit array, you'll waste a whopping 31 bits per flag, but
unless you plan to use tens of thousands of lists, that shouldn't be much
of a problem)
</F>
More information about the Python-list
mailing list