number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
def solution(files):
arr = [['' for _ in range(3)] for _ in range(len(files))]
for file in range(len(files)):
do = False
slice = 0
for x in range(len(files[file])):
if files[file][x] in number:
if not do:
arr[file][0] = files[file][:x]
slice = x
do = True
if x == len(files[file])-1:
arr[file][1] = files[file][x:]
if x == len(files[file])-1:
arr[file][1] = files[file][slice:]
if files[file][x] not in number:
if do:
arr[file][1] = files[file][slice:x]
arr[file][2] = files[file][x:]
break
arr.sort(key=lambda x: (x[0].lower(), int(x[1])))
answer = []
for i in range(len(arr)):
answer.append(arr[i][0]+arr[i][1]+arr[i][2])
return answer
2018 카카오 블라인드 3차 - 3번
1. files를 HEADER, NUMBER, TAIL로 나눈 arr에 분할해서 넣어준다
- 숫자가 등장하면 이전까지의 값을 HEADER에 슬라이싱해서 넣어준다
- 다시 숫자가 아닌 값이 등장하면 NUMBER에 슬라이싱해서 넣어주고 나머지를 TAIL로 넣어준다
2. arr를 HEADER, NUMBER순으로 정렬
3. answer에 합쳐서 append
4. answer 출력
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] - 오픈채팅방 (파이썬) (0) | 2022.02.15 |
---|---|
[프로그래머스] - 방금그곡 (파이썬) (0) | 2022.02.06 |
[프로그래머스] - 압축 (파이썬) (0) | 2022.02.06 |
[프로그래머스] - n진수 게임 (파이썬) (0) | 2022.02.06 |
[프로그래머스] - 추석 트랙픽 (파이썬) (0) | 2022.01.30 |