python:ValueError:没有足够的值来解包(预期为2,得到0)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33418903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:20:40  来源:igfitidea点击:

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

pythonpython-3.xtweets

提问by simplesystems

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))

回答by John Gordon

It means that python expected there to be two return values from zip(), but there were none.

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