for key in d:
    avg.append(sum(d[key]) / len(d[key]))
return list(d.keys()), avg

def f_numpy(names, values):
    result_names = np.unique(names)
result_values = np.empty(result_names.shape)
for i, name in enumerate(result_names):
    result_values[i] = np.mean(values[names == name])
return result_names, result_values
Average duplicate values from two paired lists in Python using NumPy