파이썬으로 준비하던 코테,,,
자바 기초부터 공부한다고 한동안 자바로 코테 준비했더니 파이썬 초기화됨,,,
그래도 전에 하던게 있으니 금방 복구할 수 있음
그 동안 자바하면서 시간복잡도 솔직히 생각 안하고 많이 풀었었는데
파이썬은 좀 신경써야됨. 시간복잡도 생각하면서 풀기
1. input 여러개
a, b = map(int ,input().strip().split(' '))
위는 a,b가 int일때,
a,b = input().strip().split(' ')
얘는 a,b가 문자열로 저장됨.
2. swapcase()
str = input()
print(str.swapcase())
str안의 문자들이 소문자->대문자 & 대문자->소문자로 각각 변경됨.
3. 특수문자 출력
print(r'!@#$%^&*(\'"<>?:;')
앞에 r 붙여주면됨.
4. a가 b로 끝나는지 체크 ( 접미사 체크 )
def solution(my_string, is_suffix):
return int(my_string.endswith(is_suffix))
접미사이면 1, 아니면 0 리턴
or startswith도 있음
5. eval()
문자열로 작성된 식을 계산해주는 함수
# 숫자 계산
result = eval("3 + 4")
print(result) # 출력: 7
# 리스트 생성
result = eval("[1, 2, 3] + [4, 5]")
print(result) # 출력: [1, 2, 3, 4, 5]
# 함수 호출
def greet(name):
return f"Hello, {name}!"
result = eval("greet('Alice')")
print(result) # 출력: Hello, Alice!
6.replace()
문자열 안의 문자를 바꿔주는 함수. 연속으로 작성 가능
def solution(myString, pat):
temp = myString.replace("A","X").replace("B","A").replace("X","B")
print(temp)
answer = 0
return int(pat in temp)
7. 각 자리수 추출
temp = list(map(int,num_str))
ex) num_str :123
temp == [1, 2, 3]
8. 각 요소 2배
def solution(numbers):
return [num*2 for num in numbers]
'Python' 카테고리의 다른 글
[ Python ] 정렬 알고리즘 (0) | 2024.10.14 |
---|---|
[ Python ] SHDS_코테특강 (0) | 2024.10.14 |
[ Python ] filter()함수 (0) | 2024.10.08 |