''实现列表与字典的练习'''

‘‘实现列表与字典的练习’’’

list1 = [‘name’,‘age’,‘gender’]

list2 = [‘laowang’,19,‘boy’]

ret = dict(zip(list1,list2))

print(ret)

for i in ret:

print(i)

dict_new = dict()

for i in range(2): #range默认从0开始

dict_new[list1[i]] = list2[i]

print(dict_new)

new_dict = {list1[i]:list2[i] for i in range(3)}

print(new_dict)

猜你喜欢

转载自blog.csdn.net/qq_44090577/article/details/88425641