[Solved] syntax error when using ConditionalFreqDist [closed]


First of all, for information on basic syntax you should probably refer to a Python tutorial.

I’ll quote the official documentation on compound statements:

Compound statements consist of one or more ‘clauses.’ A clause consists of a header and a ‘suite.’ The clause headers of a particular compound statement are all at the same indentation level. Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite is a group of statements controlled by a clause. A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines. Only the latter form of suite can contain nested compound statements

(Emphasis is mine).

As you can see from the same page, a for loop also is a compound statement, and since in your case the “suites” are not on the same line as “headers”, they should be indented. Also, a colon is needed at the end of the “header”.

Without the indentation, we cannot say where the loop bodies end, but what I mentioned are probably only parts of the problems with this code.

For example, the category variable is used as the outer loop counter, but is reassigned in the loop. This is not a syntax error, but may or may not be an oversight by the author.

solved syntax error when using ConditionalFreqDist [closed]