The ZIP function accepts any number of sequences (including 0 and 1) as parameters, returning a tuple list.
The zip function is useful for generating a dictionary (dict) after getting the data.
For examples:
1 #Code based on Python 3.x2 #_*_ coding:utf-8 _*_3 #__author: "LEMON"4 5PList = [('Li','LY', 80), ('Zeng','ZW', 90), ('Dudu','LR', 98)]6Names = []7Scores = []8 forIinchRange (len (pList)):9ASTR =Plist[i][0]TenBSTR = plist[i][2] One names.append (ASTR) A scores.append (BSTR) - - theAdict =dict (Zip (names, scores)) - Print(adict)
Operation Result:
1 {'dudu'Zeng'li': 70R
Of course, the above case has a simpler implementation:
1 #Code based on Python 3.x2 #_*_ coding:utf-8 _*_3 #__author: "LEMON"4 5PList = [('Li','LY', 80), ('Zeng','ZW', 90), ('Dudu','LR', 98)]6Adict = {}7 forDatainchpList:8Adict[data[0]] = data[2]9 #Dict[key]=valueTen Print(adict)
Zip function-python 3