Construct the tree from a list of edges
The following is very Pythonic, but a little too terse if you are not used to it:

def createTreeFromEdges(edges):
    tree = {}
    for v1, v2 in edges:
        tree.setdefault(v1, []).append(v2)
        tree.setdefault(v2, []).append(v1)
    return tree


Basically, setdefault does the following:

def setdefault(self, key, default=None):
    if key not in self:
        self[key] = default
    return self[key]