mylist = [['apple', 3], ['banana', 2], ['pear', 5], ['orange', 1]] mydict = {} for i in mylist: str1=i[0] str2=i[1] mydict[str1] = str2 print(mydict)
结果
{'apple': 3, 'banana': 2, 'pear': 5, 'orange': 1}
mylist = [['apple', 3], ['banana', 2], ['pear', 5], ['orange', 1]] mydict = {} for i in mylist: str1=i[0] str2=i[1] mydict[str1] = str2 print(mydict)
结果
{'apple': 3, 'banana': 2, 'pear': 5, 'orange': 1}