Super Kawaii Cute Cat Kaoani [Python 코테준비] itertools 안쓰고 리스트 회전하기

기타/코테 대비

[Python 코테준비] itertools 안쓰고 리스트 회전하기

치킨고양이짱아 2025. 4. 9. 15:14
728x90
728x90

다른 라이브러리 없이 리스트를 회전하는 방법이다. 외워두면 편하게 사용할 수 있다.

# 시계방향 90도 회전
def rotate_array_90(array):
    rotated_array = []
    for row in zip(*array[::-1]):
        rotated_array.append(list(row))

    return rotated_array

# 시계방향 180도 회전
def rotate_array_180(array):
    rotated_array = []
    for row in array[::-1]:
        rotated_array.append(row[::-1])

    return rotated_array

# 시계방향 270도 회전
def rotate_array_270(array):
    rotated_array = []
    for row in list(zip(*array))[::-1]:
        rotated_array.append(list(row))

    return rotated_array

# transpose
def transpose_array(array):
    transposed_array = []
    for row in zip(*array):
        transposed_array.append(list(row))
    
    return transposed_array

 

728x90
728x90