Promos.py

promos = [fidelity_promo, bulk_item_promo, large_order_promo] def best_promo(order): """Select best discount available """ return max(promo(order) for promo in promos)
Is straightforward: promos is a list of functions. Once you get used to the idea that functions are first class objects, it naturally follows that building data structures holding functions often makes sense.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.