41번 이상한 문자 만들기
def solution(s):
answer = ''
a = s.split(' ')
for i in range(len(a)) :
for j in range(len(a[i])) :
if j%2 == 0:
answer += a[i][j].upper()
else :
answer += a[i][j].lower()
answer += ' '
return answer[0:-1]
def solution(s):
sentence =[]
word =''
a =s.split(' ')
for i in range(len(a)):
for j in range(len(a[i])):
if j%2==0:
word += a[i][j].upper()
else:
word += a[i][j].lower()
sentence.append(word)
word=''
return " ".join(sentence)
> map, lamda, enumerate, join으로 합치기
def solution(s):
return " ".join(map(lambda x: "".join([a.lower() if i % 2 else a.upper() for i, a in enumerate(x)]), s.split(" ")))
42번 삼총사
def solution(number):
answer = 0
l = len(number)
for i in range(l):
for j in range(i+1, l):
for k in range(j+1, l):
if number[i] + number[j] + number[k] == 0:
answer += 1
return answe
> 새롭게 안 라이브러리
def solution (number) :
from itertools import combinations
cnt = 0
for i in combinations(number,3) :
if sum(i) == 0 :
cnt += 1
return cnt
43번 크기가 작은 부분
def solution(t, p):
answer = 0
for i in range(len(t)-len(p)+1):
if t[i:i+len(p)] <= p :
answer += 1
else :
continue
return answer
'[스파르타코딩클럽]데이터분석 과정 > PYTHON' 카테고리의 다른 글
[Python 코드카타] 47 ~ 49번 (프로그래머스) (1) | 2024.01.19 |
---|---|
[Python 코드카타] 44~46번 (프로그래머스) (0) | 2024.01.18 |
[Python 코드카타] 39 ~ 40번(프로그래머스) (1) | 2024.01.14 |
[Python 코드카타] 37번 ~ 38번 (프로그래머스) (0) | 2024.01.12 |
[Python 코드카타] 36번 (프로그래머스) (0) | 2024.01.11 |