tags:

views:

116

answers:

3
def LCS(word_list1, word_list2):
    m = len(word_list1)
    n = len(word_list2)
    print m
    print n
    C = [[0] * (n+1) for i in range(m+1)]   # IndentationError: unindent does not match          any outer indentation level
    print C
    i=0
    j=0
    for word in word_list1:
        j=0
        for word in word_list2:
        if word_list1[i-1] == word_list2[j-1]: 
            C[i][j] = C[i-1][j-1] + 1
        else:
            C[i][j] = max(word_list1(C[i][j-1], C[i-1][j]))
        j+=1
    i+=1
    return C
+1  A: 

These two lines

  C = [[0] * (n+1) for i in range(m+1)]   # IndentationError: unindent does not match          any outer indentation level
print C

should be indented at the same level. I.e.:

C = [[0] * (n+1) for i in range(m+1)]
print C

Update

Op has corrected the above problem. I checked the code and the error is elsewhere now:

for word in word_list2:
if word_list1[i-1] == word_list2[j-1]: 
    C[i][j] = C[i-1][j-1] + 1
else:
    C[i][j] = max(word_list1(C[i][j-1], C[i-1][j]))
j+=1

Should be:

for word in word_list2: 
    # These lines have been indented extra.
    if word_list1[i-1] == word_list2[j-1]: 
        C[i][j] = C[i-1][j-1] + 1
    else:
        C[i][j] = max(word_list1(C[i][j-1], C[i-1][j]))
    j+=1
Manoj Govindan
No.. i correctly indented..still it's showing the same error..
Aneeshia
@Aneeshia: I have updated my answer. See above.
Manoj Govindan
@Aneeshia. It was not showing the same error. it was showing a _different_ error because you had two _different_ errors to begin with.
aaronasterling
@Manoj Govindan: I changed that.. still the error is in line no:7
Aneeshia
@Aneeshia: I am unable to reproduce your error. Why don't you make sure that your indentation is consistent? Use spaces everywhere or tabs everywhere but DON'T mix and match.
Manoj Govindan
+2  A: 

It's hard to answer a question on why indentation is incorrect when the question keeps being edited and the indentation corrected.

However, I suggest you read PEP8 before writing any more Python code and avoid mixing tabs and spaces. This would explain why you still see an IndentationError on line seven after you have corrected the indentation.

I also recommend that you try to run your script using the '-tt' command-line option to determine when you accidentally mix tabs and spaces. Of course any decent editor will be able to highlight tabs versus spaces (such as Vim's 'list' option).

Johnsyweb
A: 

I think its due use of mixed indentation - Tabs and Spaces

Recommendation: Use 4 spaces per indentation level,
Never mix tabs and spaces. Maximum Line Length: 80

Check your Python - Editor's Setting,

GEdit:

From Tools -> Preferences -> Editor -> Tab Width = 4 and use Spaces instead of Tabs

Eclipse:

use Pydev - http://pydev.org

VIM:

use following vim settings - for vim editor

:set tabstop=4 expandtab shiftwidth=4 softtabstop=4
Tumbleweed