educative.io

Educative

Any alternative to copy.deepcopy?

Any ideas?

Hello @Athar_Mehboob

I was working on similar idea. Please check this out

def find_all_paths(graph, source, destination):
    """
    Finds all paths between source and destination in given graph
    :param graph: A directed graph
    :param source: Source Vertex
    :param destination: Destination Vertex
    """
    result = []
    dfs(graph, source, destination, result, [])
    return result

def dfs(graph, source, destination, result, current = []):
    if source == destination:
        result.append(current + [destination])
        return
    
    temp = graph.graph[source]
    while temp:
        dfs(graph, temp.vertex, destination, result, current + [source])
        temp = temp.next
    
    return