Python学习笔记之集合推导式

2019-9-21 张宇童 Python

# 集合推导式
listvar = [
    {'name': '张三', 'age': 18},
    {'name': '李四', 'age': 21}
]

setvar = { '尊贵白金博客卡老'+i['name'][0] if 17 < i['age'] < 20 else '一边玩去卡老'+i['name'][0] for i in listvar }
print(setvar) # {'一边玩去卡老李', '尊贵白金博客卡老张'}

标签: python 学习笔记

发表评论:

Powered by emlog