array.array
Python's standard-library typed array, which stores numbers of one type as raw binary values instead of as full Python objects.
In more detail
You choose the element type with a one-letter typecode; 'i' means a signed integer stored in four bytes. Because it holds raw values rather than pointers to objects, it uses several times less memory than a list of the same numbers. It only holds that one numeric type, so it is not a general-purpose container.
Example
array('i', range(100))Related terms
- array — A sequence of same-sized slots stored one after another in a single block of memory, so any slot can be reached by its index directly.
- Python list — Python's built-in ordered, growable sequence, implemented as a dynamic array of pointers to objects.
- contiguous memory — Memory laid out as one unbroken block, with each item directly after the previous one.
Taught in
- Arrays: Contiguous Memory And Constant-Time Access — Algorithms & Data Structures for Working Engineers
- Choosing The Right Sequence — Algorithms & Data Structures for Working Engineers