表达式操作元组和字典


对元组内的内容 筛选后赋值给另一元组

字典  new_dirc={key:dic[key] for key in dirc if  条件语句}

#元组推导式
def test_():
    books=('程序员的必修课本','构建之法','代码大全','TCP/IP协议详解')
    reading=(book for book in books if len(book)<=4)
    print("太长的书就不看了,只读短的:")
    for book in reading:
        print(" ->《{}》".format(book))
    print("可是发现书的名字短,内容也可能很长啊!")
#字典推导式
def test2():
    install={
        'w':{'platform':'windows','desc': "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/"},
        "l": {
            "platform": "Linux",
            "desc": "请下载 Linux 的 Python 源码安装:https://www.python.org/downloads/source/",
        },
        "m": {
            "platform": "MacOS",
            "desc": "请下载 Mac 的安装包:https://www.python.org/downloads/macos/,或者使用 brew install python 安装",
        }
    }
    # install--> w l  m --> platform , desc ,
    # 将除了w 之外的 字典 放入no_windows
    no_windows={key:install[key] for key in install  if key !='w'}
   # print(no_windows)
    for a in no_windows:
        print("安装平台:{}".format(no_windows[a]['platform']))
        print ("安装说明:{}".format(no_windows[a]['desc']))
test2()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱吃龙虾的小黑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值