3 ms·
> There’s only one kind of list container (an Array), and it’s mutable. What are the other kinds of list containers in Python? I only know of `list()`/`[]`, bu
by wodenokoto 4y ago
> There’s only one kind of list container (an Array), and it’s mutable.
What are the other kinds of list containers in Python? I only know of `list()`/`[]`, but maybe I just don’t realize that some other thing I use is also a list container.
- uranusjr 4y agoI’m guessing they’re implying tuple, it’s pretty common to consider that type as “immutable list” (although personally I very much dislike this categorisation)
- masklinn 4y ago> although personally I very much dislike this categorisation It’s not a categorisation, it’s literally the nature of the thing in Python. And while I agree that it’s distasteful the error was in the original introduction. As things are, python tuples are immutable sequences with all that implies. They are iterable, indexable, sliceable, …
- baq 4y agoImmutability crucially allows for hashability, so you can use (some) tuples as dict keys.
- kevin_thibedeau 4y agoarray.array
- zbentley 4y agoarray.array, as another commenter mentioned; numpy.array is popular for performance-oriented code (but not in the stdlib); collections.deque; queue.Queue; tuple; struct (though it's a bit of a pain to make one behave in an array-like way and is usually better to use array.array); heapq; and multiprocessing.shared_memory.ShareableList. Out in pypi there are many additional esoteric list-like data structures: bitarray is one of my favorites, and there's also awkward-array, cyarray, tinyarray, fixedlist, blist, bigarray, sortedcontainers, and many many more.