2025-09-10:仓库迁移

This commit is contained in:
2025-09-10 16:12:45 +08:00
parent e0e49b0ac9
commit 3130e336a1
146 changed files with 4066 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
if __name__ == '__main__':
# 如果想要同时迭代多个序列那么可以使用zip函数
list1 = [1, 2, 3, 4, 5]
list2 = ['a', 'b', 'c', 'd', 'e']
for i, j in zip(list1, list2):
print(i, j)
# zip遵循最短木板原则迭代长度等于最短的可迭代对象长度如果想要打破这种限制请使用itertools.zip_longest()
from itertools import zip_longest
short_list = [1, 2, 3]
# fillvalue字段用来填充短列表的缺失值默认为None
for i, j in zip_longest(short_list, list1, fillvalue=0):
print(i, j)
# zip函数会构建一个元组它的长度与输入的可迭代对象数量有关
for i in zip(short_list, list2, list1):
print(i)
# 双对象元组可以直接视作键值对转成字典
dic = dict(zip(list1, list2))
print(dic)
# 重点zip函数返回的是一个一次性迭代器如果需要长久保存请转成列表在内存里持久化
storage_list = list(zip(list1, list2))