


def solution(lottos, win_nums):
answer = []
count = 0
'''
당첨가능한 최고순위와 최저순위를 answer에 차례대로 담아서 return하기
1. 순서는 상관없으니까 sort(lottos)랑 sort(win_nums)하기
2. lottos를 for루프로 돌면서 각 원소가 win_nums에 있는지 확인
3. 있으면 counter에 +1하기 -> count가 최저 맞춘 개수
4. count+=lottos.count(0)가 최대맞출 수 있는 개수
5. 7-count:등수,if count<2: 6을 반환
'''
for i in lottos:
if i in win_nums:
count+=1
if count+lottos.count(0)>1:
answer.append(7-count-lottos.count(0))
else:
answer.append(6)
if count > 1:
answer.append(7-count)
else:
answer.append(6)
return answer
배울점
count()함수는 중요하다! → 개수세기..


def solution(s, skip, index):
answer = ''
abc = list('abcdefghijklmnopqrstuvwxyz')
abc_use = []
for i in range(len(abc)):
if abc[i] in skip:
continue
else:
abc_use.append(abc[i]) #쓸 문자들만 append
for i in s:
answer+=abc_use[(abc_use.index(i)+index)%len(abc_use)]
return answer
배울점
remove() 함수를 쓸수있음 → remove함수는 값을 인자로 제공함.replace() 로 공백으로 만든다음에, 공백을 없애면서 “ “.join()할 수 있음.
def solution(s):
answer = 0
tmp = ''
cnt_1 = 0
cnt_2 = 0
'''
split한 첫 문자의 개수세기 - 첫 문자가 아닌 문제 개수 세기
두 문자 개수가 같아지는 순간 멈추기 -> 지금까지 읽은 문자열 분리 -> answer += 1
'''
for i in range(len(s)):
tmp += s[i]
cnt_1 = tmp.count(tmp[0]) #tmp에서 첫번째 문자가 몇갠지 샌다.
cnt_2 = len(tmp) - cnt_1
if cnt_1 == cnt_2:
tmp = ''
answer += 1
continue
elif i == (len(s)-1):
answer += 1
return answer
배울점
