data = {1:{"attack":10,"lv":4,"id":2,"owner":1},5:{"attack":10,"lv":4,"id":3,"owner":1},
3:{"attack":10,"lv":5,"id":4,"owner":1},4:{"attack":9,"lv":4,"id":5,"owner":1},
2: {"attack": 10, "lv": 4, "id": 2, "owner": 2}, 6: {"attack": 10, "lv": 4,"id": 3, "owner": 2},8: {"attack": 10, "lv": 5, "id": 4, "owner": 2}, 7: {"attack": 9, "lv": 4, "id": 5, "owner": 2}}
conditions:
1. owner==1
2. attack ASC
3. lv DESC
4. id ASC
owner_data = filter(lambda x: x[1]["owner"] == 1, data.items())
sorted_result = sorted(owner_data,key=lambda x:(-x[1]["attack"],x[1]["lv"],-x[1]["id"]))
print sorted_result
本文介绍了一个使用Python进行数据处理的具体案例。通过对一个包含多个对象的数据集应用特定的筛选和排序条件,展示了如何根据所有者、攻击力升序、等级降序及ID升序等条件来组织数据。此案例适用于理解Python中数据操作的基础知识。

被折叠的 条评论
为什么被折叠?



