运维开发网
广告位招商联系QQ:123077622
 
广告位招商联系QQ:123077622

python 列表字典按照字典中某个valu属性进行排序

运维开发网 https://www.qedev.com 2020-07-09 10:31 出处:网络 作者:运维开发网整理
 对用户名进行排序 1. 直接上代码 base_dn_list = [ {‘userID‘: ‘1‘, ‘mail‘: ‘\"[email protected]‘, ‘name‘: ‘\"zhangsan‘, ‘mobile‘: ‘111111333‘, ‘tenant‘: ‘HAD‘, ‘role‘

 对用户名进行排序

1. 直接上代码

base_dn_list = [
    {‘userID‘: ‘1‘, ‘mail‘: ‘"[email protected]‘, ‘name‘: ‘"zhangsan‘, ‘mobile‘: ‘111111333‘, ‘tenant‘: ‘HAD‘, ‘role‘: {‘roleID‘: ‘project‘, ‘roleName‘: ‘项目经理‘}},
    {‘userID‘: ‘6‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘aaaww‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部‘, ‘role‘: {}}, 
    {‘userID‘: ‘11‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘ffffw‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘CoreMap,云事业部‘, ‘role‘: {‘roleID‘: ‘root‘, ‘roleName‘: ‘平台管理员‘}},
    {‘userID‘: ‘12‘, ‘mail‘: ‘"[email protected]‘, ‘name‘: ‘yulian‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部,CoreMap‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, 
    {‘userID‘: ‘13‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘admin‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, 
    {‘userID‘: ‘14‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, 
    {‘userID‘: ‘15‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao007‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}},
    {‘userID‘: ‘16‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao009‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, 
    {‘userID‘: ‘17‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao0110‘, ‘mobile‘: ‘13224423123‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, 
    {‘userID‘: ‘18‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, 
    {‘userID‘: ‘19‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}},
    {‘userID‘: ‘20‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, 
    {‘userID‘: ‘21‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, 
    {‘userID‘: ‘22‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}},
    {‘userID‘: ‘23‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, 
    {‘userID‘: ‘24‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, 
    {‘userID‘: ‘25‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}]

user_list = sorted(base_dn_list, key=lambda e: e.__getitem__(‘name‘), reverse=False)
print(user_list)

for i in user_list:
    print(i)

2 . 执行结果

 D:/dev/PYSCRIPTS/other/s1.py
[{‘userID‘: ‘6‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘aaaww‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部‘, ‘role‘: {}}, {‘userID‘: ‘13‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘admin‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘11‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘ffffw‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘CoreMap,云事业部‘, ‘role‘: {‘roleID‘: ‘root‘, ‘roleName‘: ‘平台管理员‘}}, {‘userID‘: ‘22‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘23‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘24‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘25‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘18‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘19‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘20‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘21‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}, {‘userID‘: ‘14‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘15‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao007‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘16‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao009‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘17‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao0110‘, ‘mobile‘: ‘13224423123‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘12‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yulian‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部,CoreMap‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}, {‘userID‘: ‘1‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yulianhui‘, ‘mobile‘: ‘111111333‘, ‘tenant‘: ‘HAD‘, ‘role‘: {‘roleID‘: ‘project‘, ‘roleName‘: ‘项目经理‘}}]
{‘userID‘: ‘6‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘aaaww‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部‘, ‘role‘: {}}
{‘userID‘: ‘13‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘admin‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘11‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘ffffw‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘CoreMap,云事业部‘, ‘role‘: {‘roleID‘: ‘root‘, ‘roleName‘: ‘平台管理员‘}}
{‘userID‘: ‘22‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘23‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘24‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘25‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘liyapeng4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘18‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun1‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘19‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun2‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘20‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun3‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘21‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘wangyakun4‘, ‘mobile‘: ‘null‘, ‘tenant‘: ‘tenant01,tenant02‘, ‘role‘: {‘roleID‘: ‘tester‘, ‘roleName‘: ‘测试‘}}
{‘userID‘: ‘14‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘15‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao007‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘16‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao009‘, ‘mobile‘: ‘12345678901‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘17‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yanhao0110‘, ‘mobile‘: ‘13224423123‘, ‘tenant‘: ‘CoreMAP,HAD,人事部‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘12‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yulian‘, ‘mobile‘: ‘ ‘, ‘tenant‘: ‘云事业部,CoreMap‘, ‘role‘: {‘roleID‘: ‘admin‘, ‘roleName‘: ‘租户管理员‘}}
{‘userID‘: ‘1‘, ‘mail‘: ‘[email protected]‘, ‘name‘: ‘yulianhui‘, ‘mobile‘: ‘111111333‘, ‘tenant‘: ‘HAD‘, ‘role‘: {‘roleID‘: ‘project‘, ‘roleName‘: ‘项目经理‘}}

Process finished with exit code 0

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消