i=['d','e','f','g']
t=['a','b','c']

n=0
while n < max(len(i),len(t)):
try:
print(i[n])
print(t[n])
except IndexError:
break
n+=1

for k,v in zip(i,t):
print(k)
print(v)

d
a
e
b
f
c

zip:

x = [1, 2, 3]

y = [4, 5, 6]

z = [7, 8, 9]

xyz = zip(x, y, z)

print xyz

[(1, 4, 7), (2, 5, 8), (3, 6, 9)]  从这个结果可以看出zip函数的基本运作方式。

#

x = [1, 2, 3]
y = [4, 5, 6, 7]
xy = zip(x, y)

print xy

[(1, 4), (2, 5), (3, 6)]

#zip压缩解压缩的用法：

Python2的写法：

x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = zip(x, y, z)
u = zip(*xyz)
print u

# [(1, 2, 3), (4, 5, 6), (7, 8, 9)]

python3的写法：

x = [1, 2, 3]

y = [4, 5, 6]

z = [7, 8, 9]

xyz=zip(x,y,z)

u = zip(*xyz)

print(u)

<zip object at 0x0000000002412F48>

x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
# xyz = zip(x, y, z)
xyz=list(zip(x,y,z))
u = list(zip(*xyz))
print(u)

# #

# # [(1, 2, 3), (4, 5, 6), (7, 8, 9)]

list(zip(*list(zip(x,y,z))))

a=list(zip([1,2,3],[4,5,6],[7,8,9]))
print(list(zip(*a)))

[(1, 2, 3), (4, 5, 6), (7, 8, 9)]

x = [1, 2, 3]
r = zip(* [x] * 3)print r

[(1, 1, 1), (2, 2, 2), (3, 3, 3)]

[x]生成一个列表的列表，它只有一个元素x

[x] * 3生成一个列表的列表，它有3个元素，[x, x, x]

zip(* [x] * 3)的意思就明确了，zip(x, x, x)

# 解压

x = [1, 2, 3]

y = [4, 5, 6]

z = [7, 8, 9]

a=list(zip([1,2,3],[4,5,6],[7,8,9])) #list(zip(x,y,z))

b=zip(*a)

for i in b:

print(i)

#打印结果

# (1, 2, 3)

# (4, 5, 6)

# (7, 8, 9)

# # 压缩

x = [1, 2, 3]

y = [4, 5, 6]

z = [7, 8, 9]

a=list(zip([1,2,3],[4,5,6],[7,8,9])) #list(zip(x,y,z))

print(list(zip(*a)))

#打印结果

#[(1, 2, 3), (4, 5, 6), (7, 8, 9)]

https://blog.csdn.net/shomy_liu/article/details/46968651

https://blog.csdn.net/heifan2014/article/details/78894729

http://www.pythonclub.org/python-files/zip  ---zipfile模块