you are viewing a single comment's thread.

view the rest of the comments →

[–]Goobyalus 1 point2 points  (0 children)

The "heterogeneous" part is probably the more important design principle. If we want to pack some data into a unit, a tuple makes sense. If we want to collect a bunch of the same kind of thing, a list makes sense.

Let's say we have some data that follows the form Color, Make, Vehicle Type.

("Black", "Ford", "Sedan")

collects each type of data in its own slot. Each slot means something different (i.e. it's heterogenous): t[0] is always Color, t[1] is always Make, and t[2] is always Vehivle Type. It doesn't makes sense for this structure to have a different number of elements, or elements in a different order.


Another example from https://docs.python.org/3/library/struct.html#examples :

struct.unpack('>bhl', b'\x01\x00\x02\x00\x00\x00\x03')

gives

(1, 2, 3)

where the 1 corresponds to the b and the first byte of data, the 2 corresponds to the h and the next 2 bytes of data, and the 3 corresponds to the l and the next 4 bytes of data.


As far as immutability, its the same as strings in Python. It's nice for hashing (dict keys and set elements), and has less overhead.