-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[3차] 파일명 정렬.py
48 lines (37 loc) · 1.06 KB
/
[3차] 파일명 정렬.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
"""
#2020.04.27
import re
def solution(files):
q = re.compile('\d+')
concat = []
for file in files:
span = q.search(file).span()
a = file[:span[0]].upper()
b = int(file[span[0]:span[1]])
concat.append((a,b,file))
concat = sorted(concat, key = lambda x: x[1])
concat = sorted(concat, key = lambda x: x[0])
return [c for a,b,c in concat]
"""
'''
import re
q = re.compile('\d+')
arr = []
for file in files:
sss = q.search(file)
arr.append((file[:sss.start()].lower(), int(sss.group()),file))
arr = sorted(arr, key = lambda x: x[1])
arr = sorted(arr, key = lambda x: x[0])
return [c for a,b,c in arr]
'''
#2022.12.02
import re
def solution(files):
lists = []
for file in files:
head = re.findall('[a-zA-Z.\-\\s]+', file)[0]
number = re.findall('^[^\d]*(\d+)', file)[0]
lists.append((file, head.lower(), int(number)))
lists = sorted(lists, key=lambda x: x[2])
lists = sorted(lists, key=lambda x: x[1])
return [file for file, head, number in lists]