python 二维数组90度旋转的方法
如下所示:
#!/usr/bin/env python #-*- coding: utf-8 -*- """ [0, 1, 2, 3] [0, 1, 2, 3] [0, 1, 2, 3] [0, 1, 2, 3] 2维数组顺时针90度旋转后结果如下 [0, 0, 0, 0] [1, 1, 1, 1] [2, 2, 2, 2] [3, 3, 3, 3] [0][1] <==> [1][0] [0][2] <==> [2][0] [0][3] <==> [3][0] [1][2] <==> [2][1] [1][3] <==> [3][1] [2][3] <==> [3][2] """ data=[[i for i in range(4)] for raw in range(4)] for ele in data: print ele a=len(data) for i in range(a):#外层循环 for j in range(i+1,len(data[i])): #内层循环 #交换数据 temp=data[i][j] data[i][j]=data[j][i] data[j][i]=temp for ele in data: print ele
相关推荐
bizercsdn 2020-04-22
sdwylry 2020-02-20
liugan 2020-02-13
sasac 2020-09-25
huangjie0 2020-09-25
cloudking000 2020-09-11
xiaoxiaokeke 2020-07-28
mingyunxiaohai 2020-07-28
honghao0 2020-07-27
风吹夏天 2020-07-26
夕加加 2020-07-20
CallmeZhe 2020-06-29
zhoujiyu 2020-06-28
清风徐来水波不兴 2020-06-16
Happyunlimited 2020-06-15
wanff0 2020-06-14
cuiguanjun 2020-06-13
啸林 2020-06-12
jiayuqicz 2020-06-09