def update_averages(self, **stats: Number): for key, value in stats.items(): self.averages.setdefault(key, {'count': 0, 'sum': 0}) item = self.averages[key] item['count'] += 1 item['sum'] += value self.status['average_' + key] = item['sum'] / item['count']
def adjust(self, **adjustments: Number) -> MorphologySelection: for name, adjust in adjustments.items(): for elem in self.selected: value = getattr(elem, name) + adjust setattr(elem, name, value) return self