How to remove an instance of object from a list in python? : <p>I'm working on implementing Dijkstra's algorithm in python and I was wondering how I can remove an instance of an object from a list ? 
Here's a part of my code in which I get an error: "list.remove(x): x not in list".</p>

<pre><code>class Vertex:
    def __init__(self, id, name):
        self.id = id
        self.name = name
        self.minDistance = float("inf")
        self.previousVertex = None
        self.edges = []

    def computePath(self, sourceId):
        for i in self.vertexes:
            if i.id == sourceId:
                startVertex = i
                startVertex.minDistance=0
                break
            else:
                continue
        unvisited = []
        for vertex in self.vertexes:
            unvisited.append(vertex)
        while len(unvisited)!=0:
            self.visited.append(startVertex)
            unvisited.remove(startVertex)
</code></pre>
