Last active
March 11, 2020 07:21
-
-
Save luisenriquecorona/9fada8b084a4470ec51ca32cb4f653e2 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> Order(joe, long_order, best_promo) | |
<Order total: 10.00 due: 9.30> | |
>>> Order(joe, banana_cart, best_promo) | |
<Order total: 30.00 due: 28.50> | |
>>> Order(ann, cart, best_promo) | |
<Order total: 42.00 due: 39.90> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment