Decompress assignment
a,b = (1,2)
print(a,b) # 1 2
Cross assignments
a = 1
b = 2
a,b = b,a
print(a,b) # 2 1
Sort dictionaries by specified criteria
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}
According to the specified conditions , Sort the dictionaries in the list
#Python Learning exchange group :153708845
users = [{
'name':'lili','age':20},{
'name':'jerry','age':22},{
'name':'tom','age':19}]
users.sort(key=lambda item:item['age'])
print(users)