Get next node in a breadth-first traversal of nodes that have not been used yet

def getNextNode(nodes,usednodes,parent):
    '''Get next node in a breadth-first traversal of nodes that have not been used yet'''
    for e in edges:
        if e.source==parent:
            if e.target in usednodes:
                x = e.target
                break
        elif e.target==parent:
            if e.source in usednoes:
                x = e.source
                break  
    return x