Rotating a two-dimensional array in Python

后端 未结 7 1355
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 19:38

In a program I\'m writing the need to rotate a two-dimensional array came up. Searching for the optimal solution I found this impressive one-liner that does the job:

7条回答
  •  死守一世寂寞
    2020-11-28 19:45

    def ruota_orario(matrix):
       ruota=list(zip(*reversed(matrix)))
       return[list(elemento) for elemento in ruota]
    def ruota_antiorario(matrix):
       ruota=list(zip(*reversed(matrix)))
       return[list(elemento)[::-1] for elemento in ruota][::-1]
    

提交回复
热议问题