简体   繁体   English

为什么 print(zip(*A)), 给 output 形式<zip object at 0x7f8ef0f82b48> ,但在执行 set(zip(*A)) 时预期 output? 注意 A 是一个列表</zip>

[英]Why does print(zip(*A)), give output in the form <zip object at 0x7f8ef0f82b48>, but expected output when doing set(zip(*A))? Note that A is a list

I do understand this is an object, but can you throw some insights on how it is able to map to different lists?我确实知道这是一个 object,但是您能否就它如何能够将 map 放到不同的列表中提供一些见解?

In Python, the zip functions returns a custom iterator object that computes each tuple of items from the sequence it is given lazily.在 Python 中, zip函数返回一个自定义迭代器 object,该迭代器从惰性给出的序列中计算每个项目的元组。 This object has no __repr__ method, so printing it produces the default <zip object at <address>> .这个 object 没有__repr__方法,因此打印它会<zip object at <address>> The set constructor then evaluated the created iterator, creating a set of tuples.然后set构造函数评估创建的迭代器,创建一组元组。 Sets do have a __repr__ , so printing the set will produce the expected output.集合确实有__repr__ ,因此打印集合将产生预期的 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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