码迷,mamicode.com
首页 > 其他好文 > 详细

二维数组的排序

时间:2014-08-07 18:12:20      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   数据   for   div   log   size   

 1 result =[[7250,1],[7510,2],[7759,0],[6523,33]]
 2 
 3 copy_result = []
 4 
 5 for item in result:
 6     copy_result.append([int(item[0]),item[1]])
 7 
 8 print result
 9 # output:
10 # [[‘7250‘, ‘1‘], [‘7510‘, ‘2‘], [‘7759‘, ‘0‘], [‘6523‘, ‘33‘]]
11 
12 print copy_result
13 # output
14 # [[7250, ‘1‘], [7510, ‘2‘], [7759, ‘0‘], [6523, ‘33‘]]
15 
16 copy_result.sort()
17 
18 print copy_result
19 # output
20 # [[6523, ‘33‘], [7250, ‘1‘], [7510, ‘2‘], [7759, ‘0‘]]
21 
22 back_result = []
23 
24 for item in copy_result:
25     back_result.append([str(item[0]),item[1]])
26 
27 print back_result
28 # output
29 # [[‘6523‘, ‘33‘], [‘7250‘, ‘1‘], [‘7510‘, ‘2‘], [‘7759‘, ‘0‘]]
 
用int()和str()转换数据类型

二维数组的排序 sort()方法根据第一维的排序 
 

如果是逆序,用reverse()

 

二维数组的排序,布布扣,bubuko.com

二维数组的排序

标签:style   blog   color   数据   for   div   log   size   

原文地址:http://www.cnblogs.com/tmmuyb/p/3897591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!