tuple.py 588 字节
Newer Older
F
feilong 已提交
1
# -*- coding: UTF-8 -*-
F
feilong 已提交
2
# 作者:huanhuilong
F
feilong 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# 标题:Python 元组推导式
# 描述:Python 独步天下的推导式表达式,使用元表推式过滤长度小于等于4的书籍


def test():
    books = ('程序员修炼之道', '构建之法', '代码大全', 'TCP/IP协议详解')

    reading = (book for book in books if len(book) <= 4)

    print("太长的书就不看了,只读短的:")
    for book in reading:
        print(" ->《{}》".format(book))

    print("可是发现书的名字短,内容也可能很长啊!")


if __name__ == '__main__':
    test()