Sometimes we have some functions with infinite argument, we can pass a list with all elements or pass a generator or
*args to it.
def normalize_purchases_status(purchases): for purchase in purchases: purchase.status = 'xxx' normalize_purchases_status([one_purchase]) normalize_purchases_status(purchases)
another version of
def normalize_purchases_status(*purchases): for purchase in purchases: purchase.status = 'xxx' normalize_purchases_status(one_purchase) normalize_purchases_status(*purchases)
the second version looks better than first one,
caller must guarantee argument is not
None, because there is no check in
if we pass a generator, it will failed because the
callee don't know the type of argument.
generator is a
Iterable, if it is a
iterable, we can
Subscribe to TradeOff
Get the latest posts delivered right to your inbox