简体   繁体   中英

Why does zip return 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM