zip拉链函数

# zip() # 拉链函数

lst1 = [1, 2, 3, 4, 45, 5]
lst2 = [1, 1, 1, 1, 1]
print((zip(lst1, lst2)))
print(list(zip(lst1, lst2)))
print(tuple(zip(lst1, lst2)))

# 这个比较特殊,需要注意!
print(dict(zip(lst2, lst1)))

print(dict(zip(lst1, lst2)))

# <zip object at 0x00000231764792C8>
# [(1, 1), (2, 1), (3, 1), (4, 1), (45, 1)]
# ((1, 1), (2, 1), (3, 1), (4, 1), (45, 1))

# 注意:集合是没有值的字典,字典的键是惟一的!
# {1: 45}

# {1: 1, 2: 1, 3: 1, 4: 1, 45: 1}

print(dict(zip(lst1, lst2)))
d = dict(a=1, b=2, c=3)
print(d)

# {'a': 1, 'b': 2, 'c': 3}
原文地址:https://www.cnblogs.com/fengting0913/p/13721361.html