python列表先按第一个元素排列,再按第二个元素排列(默认升序)
>>> array = [(3, 5), (1, 1), (2, 3), (5, 15),(4, 10)]>>> array.sort(key = lambda x : (x[0], x[1]))>>> array[(1, 1), (2, 3), (3, 5), (4, 10), (5, 15)]
·
>>> array = [(3, 5), (1, 1), (2, 3), (5, 15), (4, 10)]
>>> array.sort(key = lambda x : (x[0], x[1]))
>>> array
[(1, 1), (2, 3), (3, 5), (4, 10), (5, 15)]
更多推荐
已为社区贡献3条内容
所有评论(0)