1 # ###集合推到式 2 """ 3 案例: 4 满足年龄在18到21,存款大于等于5000 小于等于5500的人, 5 """ 6 listvar = [ 7 {"name": "王家辉", "age": 18, "money": 10000}, 8 {"name": "王水机", "age": 19, "money": 5100}, 9 {"name": "王鹏", "age": 20, "money": 4800}, 10 {"name": "李站", "age": 21, "money": 2000}, 11 {"name": "李小龙", "age": 180, "money": 20} 12 ] 13 setvar = {'vip' + i['name'][0] if 18 < i['age'] < 21 and 5000 <= i['money'] <= 5500 else '大汉' + i['name'][0] for i in 14 listvar} 15 16 print(setvar)