[파이썬을 파이썬답게] 2차원 리스트 뒤집기
def solution(mylist): answer = [list(x) for x in zip(*mylist)] return answer for x 2 mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] new_list = [[], [], []] for i in range(len(mylist)): for j in range(len(mylist[i])): new_list[i].append(mylist[j][i]) pythonic mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] new_list = list(map(list, zip(*mylist))) ZIP zip으로 dict의 key, value를 넣어줄 수 도 있다. wikidocs.net/32#zip..
2021. 3. 8.
[프로그래머스] 삼각 달팽이
import itertools # 달팽이가 움직인 좌표 def get_next(x, y, d): DELTAS = {'up': (-1, -1), 'down': (1, 0), 'right': (0, 1)} dx, dy = DELTAS[d][0], DELTAS[d][1] nx, ny = x + dx, y + dy return nx, ny # 달팽이가 범위 안에 있는지 밖에 있는지 확인 def check_turn(nx, ny, n, snail): return nx = n or ny > nx or snail[nx][ny] != 0 def solution(n): NEXT = {"up" : "down", "down" : "right", "right" : "up"} snail = [[0] * i f..
2021. 3. 4.