Python—数据类型之字典(Dict)
程序员文章站
2022-06-05 17:23:21
其它数据类型转成字典 arr1 = ['jack', 'rose', 'marry'] arr2 = [68, 85, 66] dict1 = dict(zip(arr1, arr2)) print(dict1) # {'rose': 85, 'marry': 66, 'jack': 68} dic ......
其它数据类型转成字典
arr1 = ['jack', 'rose', 'marry']
arr2 = [68, 85, 66]
dict1 = dict(zip(arr1, arr2))
print(dict1) # {'rose': 85, 'marry': 66, 'jack': 68}
dict2 = dict((('a',2), ('b',4)))
print(dict2) # {'a': 2, 'b': 4}
dict3 = dict((['a',2], ['b',4]))
print(dict3) # {'a': 2, 'b': 4}
dict4 = dict([('a',2), ('b',4)])
print(dict4) # {'a': 2, 'b': 4}
dict5 = dict([['a',2], ['b',4]])
print(dict5) # {'a': 2, 'b': 4}
上一篇: Qt之命令行运行