0

I am new to python, this code is meant to print out the top 100 frequent words in file MusicTaste.csv and print it in a table. I've solved past syntax error, but have never seen this error before.

Please see code below

import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())   
for label, data in ('Word', words) THE_ERROR_APPEARS_HERE_BLANK_SPACE

pt = PrettyTable(field_names=[label, 'Count'])
c = Counter(words)
[ pt.add_row(kv) for kv in c.most_common()[:100]

print pt
1
  • You need a colon at the end of the line. for a in b: Commented Mar 13, 2015 at 9:03

1 Answer 1

2
import re
from collections import Counter
from prettytable import PrettyTable

words = re.findall('\w+',open('MusicTaste2.csv').read().lower())   
for label, data in ('Word', words):
    pt = PrettyTable(field_names=[label, 'Count'])
    c = Counter(words)
    [pt.add_row(kv) for kv in c.most_common()[:100]]
    print (pt)

First problem is indent your code properly

Second problem is missing of : in the follwing line

for label, data in ('Word', words):

Third problem i am seeing is missing of ] in the following line

[pt.add_row(kv) for kv in c.most_common()[:100]]
Sign up to request clarification or add additional context in comments.

1 Comment

Note that using a list comprehension and throwing away the value is probably not the thing OP should be doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.