Today I learned
1. 코드카타
- 숫자 문자열과 영단어
숫자+문자로 되어있는 혼합문을 숫자로 전부 교체
|
num_dic = {
"zero": "0",
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9"
}
def solution(strings):
results = [] # 변환된 결과를 담을 리스트
for s in strings:
answer = s
for key, value in num_dic.items():
answer = answer.replace(key, value)
results.append(int(answer))
return results
|
- num_dic 딕셔너리 영단어 -> 숫자 문자열로의 매핑 테이블 - 함수 results = [] : 변환된 문자열의 결과를 담는 바구니 for s in strings: strings를 한 원소씩 순회 for key, value in num_dic.items() : 딕셔너리의 모든 (영단어, 숫자) 쌍을 순서대로 순회함 answer = answer.replace(key,value) : 현재 문자열 answer 안에서 모든 key(영단어)를 value(숫자)치환 result.append(int(answer)): 모든 영단어 - 숫자 치훤이 끝난 answer값은 숫자로만 이루어진 문자열인데 이를 정수형으로 바꿔 'results'에 추가 |
|
print(solution(['one4seveneight','23four5six7','2three45sixseven','123']))
|
[1478, 234567, 234567, 123] |
- 문자열 정렬하기
특정 n번째 문자열 기준으로 전체 문자열 정렬
|
def solution(strings,n):
return sorted(strings, key = lambda x: (x[n],x))
|
- sorted() sorted(iterable, key=..., reverse=...) 구조로 작성 새로 정렬된 리스트를 반환함 - key 매개변수 정렬 기준값을 만들어 정렬 - lambda lambda x: (x[n],x) 각 문자열 x에 대해 (x:) 먼저 n번째 글자 기준으로 정렬(x[n]) x[n]이 같으면, 문자열 자체 기준으로 정렬(x) |
|
print(solution(['sun','bed','car'], 1))
print(solution(['abce','abcd','cdx'], 2))
|
['car', 'bed', 'sun'] ['abcd', 'abce', 'cdx'] |
2. [심화프로젝트]
- 렌덤 포레스트 분류
- XGBoost 분류
- Feature Importance 확인
- Accurancy, ROC_AUC 데이터 확인
- Confusion matrix 확인 및 5-fold 값 계산 예정.
'빅데이터 QAQC_3기 > 빅데이터 QAQC_3기 TIL' 카테고리의 다른 글
| TIL_251112 (0) | 2025.11.12 |
|---|---|
| TIL_251111 (0) | 2025.11.11 |
| TIL_251107 (0) | 2025.11.07 |
| TIL_251105 (0) | 2025.11.05 |
| TIL_251103 (0) | 2025.11.03 |