2 ms·
Lists are very often used in the way arrays are, though. The heterogeneous use-case (that in C, etc. is usually a struct) is often filled by either tuples or (
by webmaven 8y ago
Lists are very often used in the way arrays are, though.
The heterogeneous use-case (that in C, etc. is usually a struct) is often filled by either tuples or (ordered) dictionaries in Python.
If you really want something a bit closer to a C array, you can fairly easily create a UserList that enforces the non-empty requirement and only allows items of a particular type.
- dorfsmay 8y agoIf you want some closer to C arrays, you can use Python array.array, which is part of the standard library. https://docs.python.org/3/library/array.html https://docs.python.org/3/library/array.html https://stackoverflow.com/questions/176011/python-list-vs-array-when-to-use https://stackoverflow.com/questions/176011/python-list-vs-ar...
- webmaven 8y agoThanks! I had forgotten about that module.