在python字典组成的数组中,按照其中的字典的一个key的值进行排序

对接海康的系统,取出客流信息后,发现返回的结果是乱序的, 并没有按照时间先后顺序排列。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
[
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 28,
"flowOutNum": 17,
"holdValue": 0,
"createTime": 1622070960029,
"updateTime": 1622073660035,
"statTime": "2021-05-27T07:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 25,
"flowOutNum": 44,
"holdValue": 0,
"createTime": 1622103360028,
"updateTime": 1622106060028,
"statTime": "2021-05-27T16:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 40,
"flowOutNum": 33,
"holdValue": 0,
"createTime": 1622078160028,
"updateTime": 1622080920032,
"statTime": "2021-05-27T09:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 33,
"flowOutNum": 41,
"holdValue": 0,
"createTime": 1622081760029,
"updateTime": 1622084460028,
"statTime": "2021-05-27T10:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 28,
"flowOutNum": 30,
"holdValue": 0,
"createTime": 1622096160028,
"updateTime": 1622098860029,
"statTime": "2021-05-27T14:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 32,
"flowOutNum": 24,
"holdValue": 0,
"createTime": 1622092560213,
"updateTime": 1622095260028,
"statTime": "2021-05-27T13:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622045760027,
"updateTime": 1622048460027,
"statTime": "2021-05-27T00:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622056560027,
"updateTime": 1622059260043,
"statTime": "2021-05-27T03:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622049360031,
"updateTime": 1622052060029,
"statTime": "2021-05-27T01:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 15,
"flowOutNum": 21,
"holdValue": 0,
"createTime": 1622063760027,
"updateTime": 1622066460027,
"statTime": "2021-05-27T05:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 29,
"flowOutNum": 19,
"holdValue": 0,
"createTime": 1622067360029,
"updateTime": 1622070060027,
"statTime": "2021-05-27T06:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622052960029,
"updateTime": 1622055660027,
"statTime": "2021-05-27T02:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 2,
"holdValue": 0,
"createTime": 1622060160028,
"updateTime": 1622062861776,
"statTime": "2021-05-27T04:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 30,
"flowOutNum": 28,
"holdValue": 0,
"createTime": 1622074560035,
"updateTime": 1622077260037,
"statTime": "2021-05-27T08:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 19,
"flowOutNum": 51,
"holdValue": 0,
"createTime": 1622085360028,
"updateTime": 1622088060029,
"statTime": "2021-05-27T11:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 27,
"flowOutNum": 23,
"holdValue": 0,
"createTime": 1622088960033,
"updateTime": 1622091660029,
"statTime": "2021-05-27T12:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 16,
"flowOutNum": 21,
"holdValue": 0,
"createTime": 1622099760030,
"updateTime": 1622102460029,
"statTime": "2021-05-27T15:00:00.000+08:00"
}
]

Python的 sorted 内置函数提供了一个lambda 参数可以对它排序。

1
2
data = hik_http_request(url, body).json()['data']['list']
return sorted(data, key=lambda e: e.__getitem__('createTime'))

排序后的结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
[
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622045760027,
"updateTime": 1622048460027,
"statTime": "2021-05-27T00:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622049360031,
"updateTime": 1622052060029,
"statTime": "2021-05-27T01:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622052960029,
"updateTime": 1622055660027,
"statTime": "2021-05-27T02:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 0,
"holdValue": 0,
"createTime": 1622056560027,
"updateTime": 1622059260043,
"statTime": "2021-05-27T03:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 0,
"flowOutNum": 2,
"holdValue": 0,
"createTime": 1622060160028,
"updateTime": 1622062861776,
"statTime": "2021-05-27T04:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 15,
"flowOutNum": 21,
"holdValue": 0,
"createTime": 1622063760027,
"updateTime": 1622066460027,
"statTime": "2021-05-27T05:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 29,
"flowOutNum": 19,
"holdValue": 0,
"createTime": 1622067360029,
"updateTime": 1622070060027,
"statTime": "2021-05-27T06:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 28,
"flowOutNum": 17,
"holdValue": 0,
"createTime": 1622070960029,
"updateTime": 1622073660035,
"statTime": "2021-05-27T07:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 30,
"flowOutNum": 28,
"holdValue": 0,
"createTime": 1622074560035,
"updateTime": 1622077260037,
"statTime": "2021-05-27T08:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 40,
"flowOutNum": 33,
"holdValue": 0,
"createTime": 1622078160028,
"updateTime": 1622080920032,
"statTime": "2021-05-27T09:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 33,
"flowOutNum": 41,
"holdValue": 0,
"createTime": 1622081760029,
"updateTime": 1622084460028,
"statTime": "2021-05-27T10:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 19,
"flowOutNum": 51,
"holdValue": 0,
"createTime": 1622085360028,
"updateTime": 1622088060029,
"statTime": "2021-05-27T11:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 27,
"flowOutNum": 23,
"holdValue": 0,
"createTime": 1622088960033,
"updateTime": 1622091660029,
"statTime": "2021-05-27T12:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 32,
"flowOutNum": 24,
"holdValue": 0,
"createTime": 1622092560213,
"updateTime": 1622095260028,
"statTime": "2021-05-27T13:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 28,
"flowOutNum": 30,
"holdValue": 0,
"createTime": 1622096160028,
"updateTime": 1622098860029,
"statTime": "2021-05-27T14:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 16,
"flowOutNum": 21,
"holdValue": 0,
"createTime": 1622099760030,
"updateTime": 1622102460029,
"statTime": "2021-05-27T15:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 25,
"flowOutNum": 44,
"holdValue": 0,
"createTime": 1622103360028,
"updateTime": 1622106060028,
"statTime": "2021-05-27T16:00:00.000+08:00"
},
{
"groupId": "b5900064-b435-4886-8061-2ba39148c7c6",
"groupName": "主入口",
"flowInNum": 7,
"flowOutNum": 8,
"holdValue": 0,
"createTime": 1622106960027,
"updateTime": 1622106960027,
"statTime": "2021-05-27T17:00:00.000+08:00"
}
]
Notice: 正常情况下,这里会有一个基于utteranc.es的留言系统,如果看不到,可能要想想办法才能看到。

Powered by Hexo and Hexo-theme-hiker

Copyright © 2012 - 2024 Tiaobug All Rights Reserved.

鲁ICP备2024124237号-1