1.https://school.programmers.co.kr/learn/courses/30/lessons/120905
def solution(n, numlist):
answer = []
for i in numlist:
if i%n==0:
answer.append(i)
return answer
print(solution(3,[4, 5, 6, 7, 8, 9, 10, 11, 12]))
2.https://school.programmers.co.kr/learn/courses/30/lessons/120842
def solution(num_list, n):
answer = []
temp_list = []
count = 0
for i in num_list:
if count != n:
temp_list.append(i)
count += 1
else:
answer.append(temp_list)
temp_list=[]
temp_list.append(i)
count = 1
answer.append(temp_list)
return answer
3.https://school.programmers.co.kr/learn/courses/30/lessons/120861
def solution(keyinput, board):
x = board[0]//2
y = board[1]//2
answer = [0,0]
for i in keyinput:
#처음부터 보드 밖인지 아닌지 확인하는 조건을 거니까 타임아웃 걸렸음
if i == "left" and answer[0] > -x:
answer[0] -= 1
elif i == "right" and answer[0] < x:
answer[0] += 1
elif i == "down" and answer[1] > -y:
answer[1] -= 1
elif i == "up" and answer[1] < y:
answer[1] += 1
return answer
print(solution(["left", "right", "up", "right", "right"], [7, 9]))
4.https://school.programmers.co.kr/learn/courses/30/lessons/120861
def solution(numbers):
answer = numbers
for i,num in enumerate(['zero','one','two','three','four','five','six','seven','eight','nine']):
answer = answer.replace(num,str(i))
return int(answer)
print(solution("onetwothreefourfivesixseveneightnine"))