ValueError: not enough values to unpack (expected 3, got 0)

来源:互联网 发布:网络活动策划 编辑:程序博客网 时间:2024/06/05 04:19

原代码:

#!/usr/local/bin/python3try:    import numpy as npexcept ImportError:    print("numpy is not installed")sizes = [37, 5, 6];print(sizes[-1]);result = zip(sizes[:-1], sizes[1:]);ll = len(result);   #cause error: ll = len(result); TypeError: object of type 'zip' has no len()print(*result);   # correct deference, output (37, 5) (5, 6)print("len of result = ", ll);

修改:

#!/usr/local/bin/python3import copy;try:    import numpy as npexcept ImportError:    print("numpy is not installed")sizes = [37, 5, 6];print(sizes[-1]);result = zip(sizes[:-1], sizes[1:]);tt = copy.deepcopy(result);tt = tuple(tt);ll = len(tt);print("result = ", *result);print("tuple = ", tt);print("len of result = ", ll);

运行结果:

6result =  (37, 5) (5, 6)tuple =  ((37, 5), (5, 6))len of result =  2
阅读全文
0 0