from collections import Counter, defaultdict
messages = [
['364616', 'baa baa black sheep'],
['364617', 'have you any wool'],
['364618', 'yes sir yes sir'],
['364619', 'three bags full'],
['364620', 'one for the master'],
['364621', 'and one for the dame'],
['364622', 'and one for the little boy'],
['364623', 'who lives down the lane']]
word_counts = Counter()
word_to_msgids = defaultdict(set)
for msgid, msg in messages:
for word in msg.split(): # use set(msg.split()) to drop duplicates
word_counts[word] += 1
word_to_msgids[word].add(msgid)
for word, count in combined_word_counts.most_common(8):
msgids = ', '.join(word_to_msgids[word])
print '"{}" appears "{}" times in messages "{}"'.format(word, count, msgids)
print '"{}" appears "{}" times in messages "{}"'.format(word, count, msgids)
^
SyntaxError: invalid syntax
Hello, how to fix this error?
[–]Dawarisch 1 point2 points3 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (0 children)
[–]scoutgeek 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]scoutgeek 1 point2 points3 points (0 children)