all 函数 判断可迭代对象中是否所有元素都为真
any函数 判断可迭代对象中是否存在某个元素的值为真
enumerate() 函数 用于返回一个枚举对象,将可迭代对象中的每个元素及从0开始的序号共同构成一个二元组的列表
>>> seasons=["Spring","Summer","Fall","Winter"]
>>> enumerate(seasons)
<enumerate object at 0x00000219C0693C18>
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')] -----跟一个从0开始的索引构成一个元组
>>> list(enumerate(seasons,10))
[(10, 'Spring'), (11, 'Summer'), (12, 'Fall'), (13, 'Winter')] ----从10开始
zip函数 将作为参数传入的每个可迭代对象的每个元组依次组合成元组 即第i个元组包含来自每个参数的第i个元素
>>> x=[1,2,3]
>>> y=[4,5,6]
>>> zipped=zip(x,y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> z=[7,8,9]
>>> zipped=zip(x,y,z)
>>> list(zipped)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
>>> z="FishC"
>>> import itertools
>>> zipped=itertools.zip_longest(x,y,z)
>>> list(zipped)
[(1, 4, 'F'), (2, 5, 'i'), (3, 6, 's'), (None, None, 'h'), (None, None, 'C')]
map函数 根据提供的函数对指定可迭代对象的每个元素进行运算,并将返回运算结果的迭代器
>>> mapped=map(pow,[2,3,10],[5,2,3])
>>> list(mapped)
[32, 9, 1000] -------------------2的5次方 3的2次方 10的3次方
>>> [pow(2,5),pow(3,2),pow(10,3)]
[32, 9, 1000]
filter 函数会根据提供的函数对指定的可迭代对象的每个元素进行运算,并将运算结果为真的元素,以迭代器的形式返回
>>> list(filter(str.islower,"FishC"))
['i', 's', 'h']
>>> mapped=map(ord,"FishC")
>>> for each in mapped:
print(each)
70
105
115
104
67
>>> list(mapped)
[] ---------可迭代对象可以重复使用 而迭代器只能稿一次
>>> x=[1,2,3,4,5]
>>> y=iter(x)
>>> type(x)
<class 'list'>
>>> type(y)
<class 'list_iterator'>
>>> next(y)
1
>>> next(y)
2
>>> next(y)
3
>>> next(y)
4
>>> next(y)
5
>>> z=iter(x)
>>> next(z,"没有啦")
1
>>> next(z,"没有啦")
2
>>> next(z,"没有啦")
3
>>>
>>> next(z,"没有啦")
4
>>> next(z,"没有啦")
5
>>> next(z,"没有啦")
'没有啦'
字典 python中唯一实现映射关系的内置类型
这个数据结构活跃在Python程序的背后,即便源代码里并没有直接用到它