关于python 列表append的用法:

list = []

list = list.append("c")

print(list)

>>>None

 

正确写法应为:

list = []

list.append("c")

print(list)

>>>["c"]

 

关于字典zip的用法:

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

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

 由此可见,zip是把多个列表拼接起来,组合成一个新的列表,其元素为每个列表对应位置的元素拼接成的元组

对于组成字典的应用是这样的;

key ="abcdef"

value = range(1, 6)

dic = dict(zip(key, value))

print(dic)
>>>
{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

 

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2021-06-20
  • 2022-12-23
  • 2021-05-02
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-30
  • 2022-01-02
  • 2022-01-19
  • 2021-11-30
  • 2021-11-24
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案