Python基础编程20例之一:列表元祖字典的转换

20221226星期一:


列表元祖字典的转换

list1 = [1,2,3,4,5]
list2 = ['python','java','ruby','js','javascript']
dict1 = dict(zip(list1,list2))
print(type(dict1),dict1) #  {1: 'python', 2: 'java', 3: 'ruby', 4: 'js', 5: 'javascript'}


# 2,元祖转成字典:
tup1 = (1,2,3)
tup2 = ('python','java','js')
dict2 = dict(zip(tup1,tup2))
print(type(dict2),dict2) #  {1: 'python', 2: 'java', 3: 'js'}


# 3,列表中嵌套元祖,转成字典:
list3 = [(1,'python'),(2,'java'),(3,'js')]
dict3 = dict(list3)
print(type(dict3),dict3) #  {1: 'python', 2: 'java', 3: 'js'}
展开阅读全文

页面更新:2024-05-14

标签:元祖   字典   列表   嵌套   星期   基础

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top