简体   繁体   中英

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?

In Python, the zip functions returns a custom iterator object that computes each tuple of items from the sequence it is given lazily. This object has no __repr__ method, so printing it produces the default <zip object at <address>> . The set constructor then evaluated the created iterator, creating a set of tuples. Sets do have a __repr__ , so printing the set will produce the expected output.

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