orders = [ {'order_fy':2015,'line_items':['123','124','567']}, {'order_fy':2016,'line_items':['441','442','443','333']} ] all_orders = [item['order_fy'] for item in orders] #all_orders_w_item_count = [ [item['order_fy'],len(item['line_items'])] for item in orders] all_orders_w_item_count = [ {'order_fy':item['order_fy'],'order_items':item['line_items'],'order_count':len(item['line_items'])} for item in orders] #print all_orders print all_orders_w_item_count """ for order in orders: print order['order_fy'] order_items = order['line_items'] line_item_index = 0 for item in order_items: line_item_index +=1 print 'item ID %s'% item print line_item_index """
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question