Python—数据类型之字典(Dict)
程序员文章站
2023-09-29 08:44:27
其它数据类型转成字典 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}
上一篇: 冒泡排序法(C语言)
推荐阅读