def wells(stats, year=None, playerid=None, teamid=None, idx=None):
    if idx is None:
        raise ValueError('idx must be specified')
specifiers = [(i, x) for x in enumerate((year, playerid, teamid)) if x is not
    None]
if len(specifiers) != 2:
    raise ValueError('Exactly one of year, playerid, teamid, must be given')
ikey, keyv = specifiers[0]
return sum(v[idx] for k, v in stats.items() if k[ikey] == keyv)
Рекомендация по структуре данных Python?