myList = ["Example", "Example2", "Example3"]
mySecondList = ["0000", "1111", "2222"]
for a, b in zip(myList, mySecondList):
print("- {} {}".format(a, b))
def custom_zip(a, b, fill=None):
length = max(len(a), len(b))
for k in range(length):
if k > len(a):
yield fill, b[k]
elif k > len(b):
yield a[k], fill
else:
yield a[k], b[k]
a = ["Example", "Example2", "Example3"]
b = ["0000", "1111", "2222"]
for k, v in custom_zip(a,b):
print("- {} {}".format(k, v))
是的,找^{} :
如果列表具有相同的大小,则上述方法将起作用,否则您应该根据所使用的python版本从} 或^{}
itertools
模块查看^{我建议用
zip()
或zip_longest()
来回答你的问题。你知道吗但是,不使用任何
built-in
模块/函数。您可以通过自己的类似于zip()
函数的方法创建自己的“hacky”方法。你知道吗举个例子:
输出:
此外,您还可以查看official documentation中
zip()
的等价物。你知道吗相关问题 更多 >
编程相关推荐