human
Give me a code to 4 given the following:
4.7 Build order.
You are given a list of projects and a list of dependencies. All of a project's dependencies must be built before the project is. Find a build order that will allow the projects to be built. If there is no valid build order, return an error. 
This is a tolopological sort problem, it can also be approached as a depth first search problem but the most important aspect is that we deal with cycles, when using a DFS approach the most important part is that we have a 'visiting' label so that if we come back to a node and it is labeled as 'visiting' then we have come across a cycle."
Please write code following the instructions in jupyter notebook style.
assistant
#Here is code to 4.

from collections import defaultdict

class Graph:
    def __init__(self, vertices):
        self.graph = defaultdict(list)
        self.v = vertices
        
    def addEdge(self, u, v):
        self.graph[u].append(v)
        
    def topologicalSortUtil(self, v, visited, stack):
        visited[v] = True
    
        for i in self.graph[v]:
            if visited[i] == False:
                self.topologicalSortUtil(i, visited, stack)
            else:
                
                raise ValueError('cycle: %s' % i)
            
        stack.insert(0, v)
        
    def topologicalSort(self):
        visited = [False]*self.v
        stack = []
        print(self.graph)
        
        for i in range(self.v):
            if visited[i] == False:
                self.topologicalSortUtil(i, visited, stack)
       
        print(stack)
    
g= Graph(6)
g.addEdge(5, 2)
g.addEdge(5, 0)

g.addEdge(4, 3)
g.addEdge(4, 1)

g.topologicalSort()