I have a small function (see below) that returns a list of names that are mapped from a list of integers (eg [1,2,3,4]) which can be of length up to a thousand.
This function can potentially get called tens of thousands of times at a time and I want to know if I can do anything to make it run faster.
The graph_hash is a large hash that maps keys to sets of length 1000 or less. I am iterating over a set and mapping the values to names and returning a list. The u.get_name_from_id() queries an sqlite database. 
Any thoughts to optimize any part of this function?
def get_neighbors(pid):
    names = []
    for p in graph_hash[pid]:
        names.append(u.get_name_from_id(p))
    return names
 
     
     
     
    