python comparisons
Python 2.7
I am learning Python and I cannot understand why the code below gives Code:
SyntaxError: invalid syntax Code:
if c == "." or c == "," or c == ":" or c == ";" or c == "!" or c == "?" or c == "'" or c == '"' The problem I am trying to solve consists of 2 arrays of words obtained from splitting 2 strings of UTF-8 text and trying to find if any word in both arrays is terminated by punctuation mark that the split function did not remove. This punctuation mark must be removed to subsequently compare words from the 2 arrays. Here is the code I used: Code:
array_words = line.split(u" ")# variable 'line' being a line of text with punctuation Can anyone make suggestions? Thank you for your help. |
would be nice to show us your code, not only parts:
if should be ended with a :, which is now missing the indentation of the last line c = word[-1:] is not ok. |
You forgot tu put the : at the end of the line
|
There's a better way to do that comparison, you know.
Code:
for word in array_words: |
Another idea, you could try the punct character class in a regex as your test.
|
Thank you for the answers, the missing ":" was the problem.
dugan's solution is better than my code and helps to understand how Python works. |
All times are GMT -5. The time now is 12:32 PM. |