# 解压赋值 a,b = (1,2) print(a,b) # 1 2 # 交叉赋值 a = 1 b = 2 a,b = b,a print(a,b) # 2 1 # 按指定条件给字典排序 test = {'a':1,'b':3,'c':2} res = dict(sorted(test.items(),key=lambda item:item[1])) print(res) # {'a': 1, 'c': 2, 'b': 3} # 按指定条件,给列表内的字典进行排序 users = [{'name':'lili','age':20},{'name':'jerry','age':22},{'name':'tom','age':19}] users.sort(key=lambda item:item['age']) print(users)
# 解压赋值,交叉赋值,字典排序