Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does zip return tuples?

Tags:

python

tuples

I'm wondering why zip() was designed to return tuples and not lists for instance. Is it something that has to do with performance or mutability? Or is it something else?

like image 670
Theo C Avatar asked Jul 05 '19 06:07

Theo C


1 Answers

In the fact is that the zip function is designed to :

Return a list of tuples, where each tuple contains the i-th element from each of the argument sequences. (Source: the docstring of zip function)

From this with given arguments you only get one possible result which can't be affected by something else than input that you give. So if the result was list you can modify it and the result will no more be the one expected. The tuples are the solution because they are immutable and you can't affect the result.

like image 165
Xiidref Avatar answered Oct 10 '22 00:10

Xiidref