简体   繁体   English

python:ValueError:没有足够的值要解压(预期2,得到0)

[英]python: ValueError: not enough values to unpack (expected 2, got 0)

What does this error mean? 这个错误是什么意思?

labels, freq = zip(*terms_hash)
ValueError: not enough values to unpack (expected 2, got 0) 

When I just print the terms out there is no error. 当我只打印条款时,没有错误。

code: 码:

fname = 'stream.json'
with open(fname, 'r') as f:
    print('alle Hashtags')
    count_all = Counter()
    for line in f:
        tweet = json.loads(line)
# Count hashtags only

        terms_hash = [term for term in preprocess(tweet['text']) 
              if term.startswith('#')]

        # Update the counter
        count_all.update(terms_hash)

        terms_hash = count_all.most_common(5)

        labels, freq = zip(*terms_hash)
        data = {'data': freq, 'x': labels}
        bar = vincent.Bar(data, iter_idx='x')
        bar.to_json('term_freq.json')    


    # Print the first 5 most frequent words
    print(count_all.most_common(5))

这意味着python期望zip()有两个返回值,但没有一个。

暂无
暂无

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

相关问题 Python 2-ValueError:没有足够的值可解包(预期6,得到1) - Python 2 - ValueError: not enough values to unpack (expected 6, got 1) Python:ValueError:没有足够的值来解包(预期为 3,得到 1) - Python: ValueError: not enough values to unpack (expected 3, got 1) Python ValueError:没有足够的值来解包(预期 3,得到 2) - Python ValueError: not enough values to unpack (expected 3, got 2) Python ValueError:没有足够的值来解压(预期 3,得到 1) - Python ValueError: not enough values to unpack (expected 3, got 1) Python 3 - ValueError:没有足够的值来解包(预期 3,得到 2) - Python 3 - ValueError: not enough values to unpack (expected 3, got 2) Python,ValueError:没有足够的值来解包(预期 2,得到 1) - Python, ValueError: not enough values to unpack (expected 2, got 1) Python ValueError:没有足够的值来解压(预期 2,得到 1) - Python ValueError: not enough values to unpack (expected 2, got 1) Python,ValueError:没有足够的值来解压(预期 2,得到 1),Python OOP - Python, ValueError: not enough values to unpack (expected 2, got 1), Python OOP ValueError:没有足够的值来解包(预期为 3,得到 2)-python/tensorflow - ValueError: not enough values to unpack (expected 3, got 2) - python/tensorflow Python 版本 3 - ValueError: 没有足够的值来解包(预期 2,得到 1) - Python Version 3 - ValueError: not enough values to unpack (expected 2, got 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM