标签:ons lpm 定义 msi reverse 0ms cci vcc list
c = [3,2,5] c.sort() print(c) [2,3,5] #升序
c.sort(reverse=True) print(c) [5,3,2] #降序
c.reverse() print(c) [2,3,5] #将列表定义的顺序颠倒
# 实现列表逆序方法 def reverse_list(cl): # 定义一个空列表 ret_l = [] i = len(cl) - 1 while i >= 0: ret_l.append(cl[i]) # s += c i -= 1 return ret_l print(reverse_list(cl))
# 实现对列表中的字典元素自定义顺序排序 l = [{‘name‘: ‘tom‘, ‘id‘: 3},{‘name‘: ‘tom‘, ‘id‘: 4}] l.sort(key=lambda d: d[‘id‘]) print(l) # 根据id升序排列, # >>> [{‘name‘: ‘tom‘, ‘id‘: 3}, {‘name‘: ‘tom‘, ‘id‘: 4}] l.sort(key=lambda d: d[‘id‘], reverse=True) print(l) # 根据id降序排序 # >>> [{‘name‘: ‘tom‘, ‘id‘: 4}, {‘name‘: ‘tom‘, ‘id‘: 3}]
标签:ons lpm 定义 msi reverse 0ms cci vcc list
原文地址:https://www.cnblogs.com/tanhuan-share/p/12996493.html