-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorted.py
More file actions
42 lines (36 loc) · 1.25 KB
/
sorted.py
File metadata and controls
42 lines (36 loc) · 1.25 KB
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
# encoding: utf-8
# file name:
__author__ = 'wu ming ming'
import re
from collections import OrderedDict
def sorted_dict_by_key_digit(dict_value):
''''''
if not isinstance(dict_value, dict):
raise TypeError
value_tmp = dict_value.items()
for count in range(len(re.findall('\d+', dict_value.keys()[0])))[::-1]:
value_tmp = sorted(value_tmp, key=lambda x: int(re.findall('\d+', x[0])[count if count < len(re.findall('\d+', x[0])) else None]))
sorted_result = OrderedDict()
for value in value_tmp:
sorted_result[value[0]] = value[1]
return sorted_result
if __name__ == '__main__':
pass
dict_value = {
'12A/Frame12/1U23': {'a': 1},
'14A/Frame10/1U20': {'a': 1},
'15A/Frame1/1U': {'a': 1},
'13A/Frame8/1U25': {'a': 1},
'10A/Frame23/1U43': {'a': 1},
'12A/Frame10/1U': {'a': 1},
'14A/Frame13/1U20': {'a': 1},
'15A/Frame40/1U12': {'a': 1},
'13A/Frame12/1U25': {'a': 1},
'10A/Frame7/1U': {'a': 1},
'12A/Frame10/2U23': {'a': 1},
'14A/Frame13/4U20': {'a': 1},
'15A/Frame40/5U12': {'a': 1},
'13A/Frame12/3U': {'a': 1},
'10A/Frame7/9U43': {'a': 1},
}
print sorted_dict_by_key_digit(dict_value)