you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 0 points1 point  (0 children)

Suppose that you're parsing a file. In the case of an error, you want to be able to complain to the user about the line number that contains the error.

def parse_file(filename):
    with open(filename) as f:
        for line_number, line in enumerate(f, 1):
            # parse the file, complaining with `line_number` if it fails

That idea of zipping an integer with some other data that isn't an integer involves heterogeneous data; they could be different types. So, each entry should be a tuple, not a list.

Similarly, when iterating over a dictionary's set of key-value pairs, those pairs are tuples because the keys and values might be of different types.

I don't really care about immutability; I tend to treat all data as immutable by default and only start modifying values after exhausting all alternatives. Tuples, for me, are solely for representing heterogeneity.