Readily small note python

About python list append usage:

list = []

list = list.append("c")

print(list)

>>>None

 

Correct wording should be:

list = []

list.append("c")

print(list)

>>>["c"]

 

Zip on the dictionary usage:

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

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

 Thus, zip stitching together a plurality of lists, are combined into a new list, each list element whose elements are spliced ​​into the position corresponding tuple

For the application of the composition of the dictionary is this;

key ="abcdef"

value = range(1, 6)

dic = dict(zip(key, value))

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

 

Guess you like

Origin www.cnblogs.com/fish-101/p/11420099.html