sandyroddick
sandyroddick

Reputation: 77

python : unindent does not match any outer indentation level

I am using nested for loops to check if the substring "f" is present in one of the permutation of given string as parameter in the following function.

   import itertools

   def permute(f,string):
        permutation_list = []
        permutations = itertools.permutations(string)
        for item in permutations:
           permutation_list.append(''.join(item))
           for item in permutation_list:                  
               if f in item:                         # unindentation error
                   print "YES"
                   break
               else:
                   print "NO"
                   break  



   if __name__ == "__main__":
   t1=input()
   for i in range(0,t1):
        a=raw_input()
        b=raw_input()
        c=a+b
        print c
        t2=input()
        f=""
        for j in range(0,t2):
           d=raw_input()
           f=f+d
        permute(f,c)

It is giving unindentation error at line 10

Upvotes: -1

Views: 3753

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174624

A few possibilities:

  1. You have all other indents at 3 spaces, but your highlighted line is indented 4 spaces.
  2. You have mixed tabs and spaces.
  3. You didn't start at the first column.

A good Python-aware text editor should highlight these for you and offer a quick fix.

Here is a fixed version:

import itertools

def permute(f,string):
    permutation_list = []
    permutations = itertools.permutations(string)
    for item in permutations:
        permutation_list.append(''.join(item))
        for item in permutation_list:                  
            if f in item:                         # unindentation error
                print "YES"
                break
            else:
                print "NO"
                break  

if __name__ == "__main__":
    t1=input()
    for i in range(0,t1):
        a=raw_input()
        b=raw_input()
        c=a+b
        print c
        t2=input()
        f=""
        for j in range(0,t2):
            d=raw_input()
            f=f+d
        permute(f,c)

Upvotes: 2

Related Questions