I have this ugly piece of code..
orders = got_something_from_db()
if orders:
for order in orders:
#print order
event_id = order["event_id"]
if event_id in event_id_dict: # something i grabbed earlier
product_id = order["product_id"] # products in an event
qty = order["qty"]
if product_id in product_sku_dict:
sku_id =product_sku_dict[product_id]
for i in range(qty):
sku_ids.append(sku_id)
How do I made this more pythonic (and terse)
With limited context, here’s the best I can do.
Also, consider changing event_id, product_id, etc to attributes. You probably want a namedtuple here, not a dict.