Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python:缩进错误:缩进与任何外部缩进级别都不匹配_Python_Indentation - Fatal编程技术网

python:缩进错误:缩进与任何外部缩进级别都不匹配

python:缩进错误:缩进与任何外部缩进级别都不匹配,python,indentation,Python,Indentation,我的压痕有问题。有人能帮我一下吗:第一个和第二个if语句中有错误 data_graph = {"a" : ["b", "d", "f"],"b" : ["c", "f"],"c" : ["d"],"d" : ["b"],"e" : ["d", "f"],"f" : ["d"] } def depth_first_search(data_graph): def depth_first(nodes_visited, data_graph, nodes): if nodes in node

我的压痕有问题。有人能帮我一下吗:第一个和第二个if语句中有错误

data_graph = {"a" : ["b", "d", "f"],"b" : ["c", "f"],"c" : ["d"],"d" : ["b"],"e" : ["d", "f"],"f" : ["d"]
}

def depth_first_search(data_graph):
def depth_first(nodes_visited, data_graph, nodes):

    if nodes in nodes_visited:
        pass
    else:
        nodes_visited[len(nodes_visited):] =[nodes]
        print ("Nodes visited:", nodes, len(nodes_visited)) 

    for i in data_graph[nodes]:
        if i in nodes_visited:
            pass
        else:
            depth_first( nodes_visited,data_graph, i)

nodes_visited = []
while  (len(data_graph) > len(nodes_visited)): 
     for nodes in data_graph:
        if nodes in nodes_visited:
            pass
        else:
            depth_first(nodes_visited, data_graph, nodes)

depth_first_search(data_graph)

注意嵌套函数没有缩进

data_graph = {"a" : ["b", "d", "f"],"b" : ["c", "f"],"c" : ["d"],"d" : ["b"],"e" : ["d", "f"],"f" : ["d"]
}

# you need to indent this function inside a function
def depth_first_search(data_graph):
    def depth_first(nodes_visited, data_graph, nodes):

        if nodes in nodes_visited:
            pass
        else:
            nodes_visited[len(nodes_visited):] =[nodes]
            print ("Nodes visited:", nodes, len(nodes_visited)) 

        for i in data_graph[nodes]:
            if i in nodes_visited:
                pass
            else:
                depth_first( nodes_visited,data_graph, i)

    nodes_visited = []
    while  (len(data_graph) > len(nodes_visited)): 
         for nodes in data_graph:
            if nodes in nodes_visited:
                pass
            else:
                depth_first(nodes_visited, data_graph, nodes)

    depth_first_search(data_graph)

您的
def depth\u first\u搜索(数据图):
?您正试图在下面直接定义另一个函数。如果您打算在
深度优先搜索
中使用
深度优先搜索
功能,则需要在该功能中缩进
深度优先搜索
下的所有内容。