简体   繁体   English

python 2.7的缩进错误

[英]Indentation error for python 2.7

def ispermute(str1, str2):
    d1 = {}
    d2 = {}
    for letter in str1:
        if letter not in d1:
            d1[letter] = 1
        else:
            d1[letter] += 1

    for letter in str2:
        if letter not in d2:
            d2[letter] = 1
        else:
            d2[letter] +=1

    if d1 != d2:
        return False
    return True

While running this I am getting error as: 运行此程序时,我收到以下错误消息:

File "2.py", line 16
    if d1 != d2:
               ^
IndentationError: unindent does not match any outer indentation level

Can someone suggest what is the issue? 有人可以建议出什么问题吗? This code is made to check the permutation of two strings. 编写此代码来检查两个字符串的排列。

You have mixed tabs and spaces in your code. 您的代码中混合了制表符和空格。 If you are usings Sublime Text (as stated in the comments) you can: 如果您使用Sublime Text(如注释中所述),则可以:

  1. Select all your text ( Ctrl + A ) 选择所有文本( Ctrl + A
  2. View -> Indentation -> Convert Indentation to Spaces 查看->缩进->将缩进转换为空格

You can avoid the problem in the future by turning on "Indent Using Spaces" under the View -> Indentation tab. 通过在“视图”->“缩进”选项卡下启用“缩进使用空格”,可以避免将来出现此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM