The above code creates an array but, each element is 4 bytes each.
Not an array in python we call it a list.
A list in python is much more flexible than "array" as it`s called in C/C++,java.
Python has 3 types ints, longs or floats.
eight bits unsigned(can store 0-->255) so in python it`s a int.I would like it to be as large as possible. I need it for a sieve prime number program.
In Python integers have a size only limited by your computer's memory.
If you want to force compatibility with C you can use Python module struct
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
Use the builtin function bytearray()
>>> L = bytearray(10)
>>> L
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>> L[3] = 'a'
>>> L
bytearray(b'\x00\x00\x00a\x00\x00\x00\x00\x00\x00')
edit: sorry, that was not exacly your question, but perhaps you can use a block of 8 consecutive bytes for your purpose.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
M = array.array('B',[0]*sizeA)
array.array() accepts an iterable, it would be much more efficientnot to create the list
M = array.array('B', (0 for x in xrange(sizeA)))
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
array.array() accepts an iterable, it would be much more efficient not to create the list
M = array.array('B', (0 for x in xrange(sizeA)))
Actually what I said isnot true, the list version is faster than the iterator version. I tried with itertools.repeat(0, sizeA) also, but the list version is still faster. Sorry.
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691