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. php做推送服务端实现ios消息推送

    本文部分内容引用于 http://zxs19861202.iteye.com/blog/1532460 准备工作 1.获取手机注册应用的deviceToken(iphone手机注册应用时返回唯一值de ...

  2. vCenter创建标准网络

          vmware虚拟化,有2种网络类型,一种是标准网络,另外一种是分布式网络.这里重点介绍标准网络,标准网络可通过vCenter创建vSwitch标准虚拟交换机(vSS).vSS的承载体是物理 ...

  3. sql limit offset 区别

    select * from table limit 2,1;                  //含义是跳过2条取1条数据,即读取第3条数据 select * from table limit 2 ...

  4. 第一百七十七节,jQuery,知问前端--概述及 jQuery UI

    jQuery,知问前端--概述及 jQuery UI 学习要点: 1.项目介绍 2.jQuery UI 3.UI 主题 一.项目介绍 我们重点仿照“知乎”的架构模式来搭建界面和布局,以及大部分前端功能 ...

  5. 桥接模式和NAT模式差别

    bridged networking(桥接模式)      在这样的模式下.VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机,它能够訪问网内不论什么一台机器. 在桥接模式下.你须要手工为虚 ...

  6. python3----智能检测编码的工具

    f = open('C:/Users/Administrator/Desktop/100.txt', 'rb') data = f.read() # print(data) f.close() imp ...

  7. jquery中end()方法的解释

    来源:http://www.jquery001.com/jquery-end-method.html 对于end()方法,jQuery文档是这样解释的:jQuery回到最近的一个"破坏性&q ...

  8. day11函数的进阶动态参数,命名空间,作用域,第一类对象

    一.习题收藏 5.写函数,计算传入字符串中[数字].[字母].[空格] 以及 [其他]的个数,并返回结果. # def func4(s): # dic = { # 'num':0,'alpha':0, ...

  9. 爬虫-python调用百度API/requests

    from urllib.request import urlopen import requests import json url = "http://apis.baidu.com/txa ...

  10. Yii2 Queue队列

    github地址:https://github.com/yiisoft/yii2-queue 问题:https://github.com/yiisoft/yii2-queue/issues Jobs ...