I have a statement like this
for word in tweet_text:
if word in new_words:
if new_words[word] == 0:
new_words[word] = sent_count
else:
new_words[word] = (new_words[word] + sent_count) / 2
And I am very suspicious that the else block is executed every time when the first condition is not met (if word in new_words), is this possible?Am I am doing something wrong with indentication?
asked May 8, 2013 at 20:29
Petr Mensik
27.7k17 gold badges94 silver badges119 bronze badges
1 Answer 1
The else clause corresponds to the if on the same level of indentation, as you expect.
The problem you see may be due to the fact that you are mixing tabs and spaces, so the apparent level of indentation is not the same as the one your interpreter sees.
Change all tabs into spaces and check if the problem goes away.
answered May 8, 2013 at 20:31
Lev Levitsky
66.4k23 gold badges155 silver badges184 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
python -tt your_program_name.pyto verify this, and then switch to four-space tabs.