https://www.bilibili.com/video/av17396749/?p=12

Python函数式编程中的迭代器,生成器详解

课程内容

1.iterators are objects that contain other objects
2.some built-in iterators are such as list,dict,tuple, and set.
3.learned the collections module offers other convenient iterators
4.generators are functions that yield and they are also iterators
5.understood that fenerators allow for lazy evaluation and coroutines,or light-weight threading.

以下是笔记

collections.namedtuple

namedtuple() is a factory function;that is,it generates a class,and not an instance of a class(an object)

two steps:
1.First,use namedtuple() to generate a class
2.then create an instance of this class

 from collections import namedtuple
Person=namedtuple('Person',['name','age'])
jay_z=Person(name='Sean Carter',age=47)
print('%s is %s years old'%(jay_z.name,jay_z.age))
print('%s is %s years old'%(jay_z[0],jay_z[1])) 输出 Sean Carter is 47 years old
Sean Carter is 47 years old

collections.OrderedDict

 from collections import OrderedDict
d=OrderedDict([
('Lizard','Reptile'),
('Whale','Mammal')
]
) for species,_class in d.items():
print('%s is a %s'%(species,_class)) 输出: Lizard is a Reptile
Whale is a Mammal

collections.defaultdict

 from collections import defaultdict
languages={
'Jack':'java',
'Pony':'Ruby',
'Sara':'javascript'
}
d=defaultdict(lambda:'Python')
d.update(languages) 输出:
python

The Collections Module内建collections集合模块的更多相关文章

  1. 查看Python的版本、内建方法和模块等内容的方法

    若想更好地应用Python帮助我们解决日常生活的问题,就必须了解清楚它的内建方法和模块等特性.相信不少同学在安装某个版本的Python后,对于内建方法之类都是一知半解,希望本文能帮助了解Python的 ...

  2. collections:内建模块,提供额外的集合类

    介绍 collections里面包含了很多除了内置类型之外的数据类型,我们使用它们有时可以很方便的完成一系列操作 ChainMap:搜索多个字典 from collections import Cha ...

  3. Python3 内建模块 datetime/collections/base64/struct

    datetime 我们先看如何获取当前日期和时间: >>> from datetime import datetime >>> now = datetime.now ...

  4. python常用内建模块 collections,bs64,struct,hashlib,itertools,contextlib,xml

    #  2  collections 是Python内建的一个集合模块,提供了许多有用的集合类. # 2.1 namedtuple #tuple可以表示不变集合,例如,一个点的二维坐标就可以表示成: p ...

  5. 四十二 常用内建模块 collections

    collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtuple 我们知道tuple可以表示不变集合,例如,一个点的二维坐标就可以表示成: >>> ...

  6. collections(python常用内建模块)

    文章来源:https://www.liaoxuefeng.com/wiki/897692888725344/973805065315456 collections collections是Python ...

  7. Python内建模块--collections

    python内建模块--collections collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtuple 我们知道tuple可以表示不变集合,例如,一个点 ...

  8. collections集合模块 [namedtuple,deque,*]

    collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtuple namedtuple是一个函数, 它用来创建一个自定义的tuple对象,并且规定了 tuple元 ...

  9. Python自建collections模块

    本篇将学习python的另一个内建模块collections,更多内容请参考:Python学习指南 collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtupl ...

随机推荐

  1. 开发GPIO驱动的基本套路

    最近完成了基于AR9331的GPIO驱动的开发,主要包括:控制一个连接GPIO的灯控:接收一个连接GPIO的按键事件:以及接收一个连接GPIO的脉冲事件. 这里,结合开发实践,总结一下GPIO驱动开发 ...

  2. AJAX是基于现有的Internet标准

    AJAX是基于现有的Internet标准 AJAX是基于现有的Internet标准,并且联合使用它们: XMLHttpRequest 对象 (异步的与服务器交换数据) JavaScript/DOM ( ...

  3. 福昕阅读器打开PDF文档速度慢

    RT---------------- 操作如下两步可加快打开速度: 1.Program Files\Foxit Software\Foxit Reader下面的Shell Extensions文件夹删 ...

  4. json responseJson

    private void doResoponseJson(HttpServletResponse resp,String jsonString){ Trace.logError(Trace.COMPO ...

  5. C++中计算矩阵的行列式

    使用eigen库: 求行列式: #include <iostream> #include <Eigen/Dense> using namespace std; using na ...

  6. Android Studio Error -- Could not create the Java Virtual Machine

    :app:dexDebug Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurre ...

  7. scrapy初体验 - 安装遇到的坑及第一个范例

    scrapy,python开发的一个快速,高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据.scrapy用途广泛,可以用于数据挖掘.监测和自动化测试.scrapy的安装稍 ...

  8. mysql的体系架构和存储引擎

    定义数据库和实例 数据库:物理操作系统的文件或其他形式文件类型的集合.在mysql数据库中,数据库文件可以是frm.MYD.MYI.ibd结尾的文件. 实例:MySQL数据库由后台线程以及一个共享内存 ...

  9. Win7 sql2005附加数据库失败 错误5120

      错误信息如下: 标题: Microsoft SQL Server Management Studio Express------------------------------ 附加数据库 对于 ...

  10. entropy 压缩信息的熵更加高 实际上英文文本的熵大概只有4.7比特

    https://en.wikipedia.org/wiki/Entropy_(information_theory) https://zh.wikipedia.org/wiki/熵(信息论) 熵的概念 ...