zoukankan      html  css  js  c++  java
  • 二维数组的排序

     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()

  • 相关阅读:
    谎言,
    happy,
    架构,
    休闲游戏随想,
    IOS响应者链
    application 几个方法
    ios block 循环引用
    洛谷 P 1133 教主的花园
    Codevs 1148 == 洛谷 P1057 传球游戏
    Codevs 1169 == 洛谷 P1006 传纸条
  • 原文地址:https://www.cnblogs.com/tmmuyb/p/3897591.html
Copyright © 2011-2022 走看看