-4

I have written following code:

b=[]
c=['I am so excited about Data-X. It is important to be able to work with data.']
b=c[0].split()
count=0
for i1 in range (0, len(b)):
    for i2 in range (0, len(b[i1])): 
       if(b[i1][i2]=='e'):
            ++count
        ++i2
    ++i1
print(count)

This yields the following error code:

   File "<tokenize>", line 7
     i2=i2+1
     ^ IndentationError: unindent does not match any outer indentation level

I use Jupyter Notebook as editor.

martineau
  • 119,623
  • 25
  • 170
  • 301
pythonlearner
  • 57
  • 2
  • 11
  • This error means that a line of code is not correctly indented. The lines below that also seem to have a strange indentation. In Python, it is required by syntax for each block of code to conform to a certain indentation level. Usually, if you use spaces instead of tabs for indents, you need to keep that consistent across the board and vice versa. – gmdev Jan 27 '20 at 21:49
  • @pythonlearner, you need to read https://stackoverflow.com/questions/1485841/behaviour-of-increment-and-decrement-operators-in-python – Jongware Jan 27 '20 at 21:55
  • 2
    @kaya3: they are not invalid but they don't do anything. Anyway, OP chose to not show the original code here (there is no such line, be it 7 or otherwise). – Jongware Jan 27 '20 at 22:04

1 Answers1

2

The i2=i2+1 line corresponds to your ++i2 it seems to be indented one space too many. I copied your code and received the same error you have. But when I moved the i2++ line to be directly under the if(b.. line, I got an output of 0

It should be noted that sometimes 'invisible' indentation errors can arise when tabs and spaces are mixed in the code (see @martineau's comment)

user1245262
  • 6,968
  • 8
  • 50
  • 77
  • I think it's important to note that sometimes you can get indentation errors because you've used a mixture of tabs and spaces in the source code, so even when thing seem to "line up" the interpreter will think differently. I speak from [experience](https://stackoverflow.com/questions/14900821/why-is-this-else-pass-needed-for-processing-to-continue) with the issue. – martineau Jan 27 '20 at 22:08
  • @martineau - Point taken – user1245262 Jan 27 '20 at 22:21