zipped = zip(['one', 'two', 'three'], [1, 2, 3])
print(zipped)
print(list(zipped))
print(zipped)
letter, number = zip(*zipped) # *将元组解压为列表,返回二维矩阵,再打包为元组,拆包为两个变量
print("num_zip: ", letter, number)
解释器报错
<zip object at 0x00000251976CB5C0>
[('one', 1), ('two', 2), ('three', 3)]
<zip object at 0x00000251976CB5C0>
Traceback (most recent call last):File "D:\Project\Python\test\main.py", line 5, in <module>letter, number = zip(*zipped) # *将元组解压为列表,返回二维矩阵,再打包为元组,拆包为两个变量
ValueError: not enough values to unpack (expected 2, got 0)Process finished with exit code 1
注释掉第三行list(zipped)之后,正确输出,说明list()转换改变了zip对象的属性。但我不理解。
D:\Softdocument\Python\python.exe D:/Project/Python/test/main.py
<zip object at 0x000001788933B680>
<zip object at 0x000001788933B680>
num_zip: ('one', 'two', 'three') (1, 2, 3)Process finished with exit code 0