Categories
Development Python

Is there a pythonic way to decouple optional functionality from a function’s main purpose?

Context Suppose I have the following Python code: def example_function(numbers, n_iters): sum_all = 0 for number in numbers: for _ in range(n_iters): number = halve(number) sum_all += number return sum_all ns = [1, 3, 12] print(example_function(ns, 3)) example_function here is simply going through each of the elements in the ns list and halving them 3 […]