I just found this code:
def get_product_item(jsonld_items):
for item in jsonld_items:
if item['@type'] == 'Product':
return item
else:
return {}
My argument is that the intent is clearer in:
def get_product_item(jsonld_items):
return first((item for item in jsonld_items if item['@type'] ==
'Product'), {})
As a reminder, first()'s definition in Python is:
def first(seq, default=None):
return next(iter(seq), default=default)
It could be optimized (implemented in C) if it makes it into the stdlib.
--
Juancarlo *Añez*
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/TVFD2RNRAU3SLHGMNQPBO4DHWFT274W3/
Code of Conduct: http://python.org/psf/codeofconduct/