#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018-01-15 20:40
# @Author : hhj
# @Site :
#
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# ----------------二维数组90度旋转----
# [0, 0, 0, 0, 0]
# [1, 1, 1, 1, 1]
# [2, 2, 2, 2, 2]
# [3, 3, 3, 3, 3]
# [4, 4, 4, 4, 4]
data=[[col for col in range(10)] for row in range(5)]
for col in data:print(col)
# 方法一
for r_index,row in enumerate(data):
for c_index in range(r_index,len(row)):
temp=data[c_index][r_index]
data[c_index][r_index] =row[c_index]
data[r_index][c_index]=temp
print("--------------------%s" %r_index)
for r in data:print(r)
# 方法二
n=len(data)
for i in range(len(data)):
a=[data[i][i] for row in range(n)]
print(a)
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# [0, 1, 2, 3, 4]
# ----------------二维数组90度旋转----
# [0, 0, 0, 0, 0]
# [1, 1, 1, 1, 1]
# [2, 2, 2, 2, 2]
# [3, 3, 3, 3, 3]
# [4, 4, 4, 4, 4]
Text-to-speech function is limited to 200 characters