数组实现分组
carts=[{ "shopping_id": 173744, "product_name": "aaa", "product_code": "TL11111100014", },{ "shopping_id": 173744, "product_name": "aaa", "product_code": "TL11111100018", },{ "shopping_id": 173744, "product_name": "bbb", "product_code": "TL11111100013", }]
groupcarts={};for x in carts: name = x['product_name'] if name in groupcarts: groupcarts[name].append(x) else: groupcarts[name] = [x]for x in groupcarts: print x, groupcarts[x]
[解决办法]