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

时间:2015-10-29 15:50:29

标签: python python-3.x tweets

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

1 个答案:

答案 0 :(得分:6)

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