items(),zip(),map()函数
相关连接https://www.cnblogs.com/wkhzwmr/p/15574127.html
scores = {'张三':100,'李四':98,'王五':45}
items = scores.items() # items获取的是字符串
a = str(items)
print(str(items))
print(a[0]) # items()返回的时dict_items([(),()])这样的对象
a = [1,2,3,4,5]
b = [11,22,33,44,55]
c = [111,222,333,444,555]
zip_list = zip(a,b)
print(zip_list) # <zip object at 0x0000017FCE4639C8>
# 看样子只能打包
list_zip = list(zip_list)
# list作用在zip
print(list_zip) # [(1, 11), (2, 22), (3, 33), (4, 44), (5, 55)]
# tuple作用在zip
zip_list = zip(a,c)
tuple_zip = tuple(zip_list)
print(tuple(zip_list)) # () 无法被tuple作用;((1, 111), (2, 222), (3, 333), (4, 444), (5, 555))
# dict
zip_list = zip(b,c)
# dict()函数作用不能赋值对象么
# dict_zip = dict(zip)
print(dict(zip_list)) # ()zip只能解包一次{11: 111, 22: 222, 33: 333, 44: 444, 55: 555}
#索引方法not subscriptable
map_to = map(str,list_zip)
print(type(map_to)) # <class 'map'>
# print(map_to[1]) # 'map' object is not subscriptable
map_list =''.join(map(str,list_zip)) # 指定函数映射对象,可用join()提取处元素
print(map_list) # (1, 11)(2, 22)(3, 33)(4, 44)(5, 55)
for i in map(str,tuple_zip):
print(i) # 可以使用for
# 使用iter()函数可以使集合列表转化为迭代器
n = [1,2,3,4,5,6]
a = iter(n) # iter(对象)返回个迭代器
print(a) # <list_iterator object at 0x00000186A6360710>
print(a.__next__) # <method-wrapper '__next__' of list_iterator object at 0x000001E0522C1860>
print(a.__next__()) # 1
print(a.__next__()) # 2