-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsorted_itemgetter.py
89 lines (86 loc) · 2.75 KB
/
sorted_itemgetter.py
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
from operator import itemgetter
from datetime import datetime
some_response={
'Snapshots': [
{
'DataEncryptionKeyId': 'string',
'Description': 'string',
'Encrypted': True,
'KmsKeyId': 'string',
'OwnerId': 'string',
'Progress': 'string',
'SnapshotId': 'string',
'StartTime': datetime(2015, 1, 1),
'State': 'pending',
'StateMessage': 'string',
'VolumeId': 'string',
'VolumeSize': 123,
'OwnerAlias': 'string',
'OutpostArn': 'string',
'Tags': [
{
'Key': 'string',
'Value': 'string'
},
],
'StorageTier': 'archive',
'RestoreExpiryTime': datetime(2015, 1, 1)
},
{
'DataEncryptionKeyId': 'string',
'Description': 'string',
'Encrypted': True,
'KmsKeyId': 'string',
'OwnerId': 'string',
'Progress': 'string',
'SnapshotId': 'string',
'StartTime': datetime(2017, 1, 1),
'State': 'pending',
'StateMessage': 'string',
'VolumeId': 'string',
'VolumeSize': 123,
'OwnerAlias': 'string',
'OutpostArn': 'string',
'Tags': [
{
'Key': 'string',
'Value': 'string'
},
],
'StorageTier': 'archive',
'RestoreExpiryTime': datetime(2017, 1, 1)
},
{
'DataEncryptionKeyId': 'string',
'Description': 'string',
'Encrypted': True,
'KmsKeyId': 'string',
'OwnerId': 'string',
'Progress': 'string',
'SnapshotId': 'string',
'StartTime': datetime(2011, 1, 1),
'State': 'pending',
'StateMessage': 'string',
'VolumeId': 'string',
'VolumeSize': 123,
'OwnerAlias': 'string',
'OutpostArn': 'string',
'Tags': [
{
'Key': 'string',
'Value': 'string'
},
],
'StorageTier': 'archive',
'RestoreExpiryTime': datetime(2011, 1, 1)
}
],
'NextToken': 'string'
}
#sorted() sort iterable
# param1: the iterable to sort | sort the list of dictionaries
# param2: custom key function to customize the sort order | sorts by dict key:'StartTime'
# param3: reverse | sort in descending order
da_sorted = sorted(some_response['Snapshots'], key=itemgetter('StartTime'), reverse=True)
for item in da_sorted:
print(item['StartTime'])