Custom sorting 排序技巧
陣列
升冪排序
a = [1, 3, 2, 5, 4]
a.sort()
# [1, 2, 3, 4, 5]降冪排序
a = [1, 3, 2, 5, 4]
a.sort(reverse=True)
# [5, 4, 3, 2, 1]a = [1, 3, 2, 5, 4]
a.sort(key=lambda x: (-x))
# [5, 4, 3, 2, 1]二維陣列排序(降冪排序同一維陣列)
二維陣列按照第一個元素升冪排列,第二的元素降冪排列
354. Russian Doll Envelopes1024. Video Stitching按照字典序(lexicographic order)排序
Dict
按照 key 排序
Last updated