标签:方法 index names print for ems 练习 values item
#字典取值
score = (90,89,78)
d = {"name":"张三","sex":‘男‘,‘score‘:score}
#取字典的key
for k in d.keys():
print(k)
#取字典的value
for v in d.values():
print(v)
#同时取字典的key value
for k,v in d.items():
print(k,v)
#练习题
No = [1001,1002,1003,1004]
names = [‘张三‘,‘李四‘,‘王五‘,‘赵六‘]
#将上面的list合并成一个字典
#方法一:
d = {str(No[i]):names[i] for i in range(len(No))}
print(d)
#方法二:
d1= {n:names[No.index(n)] for n in No}
print(d1)
#生成新的list
kk = [item+‘ss‘ for item in names]
print(kk)
标签:方法 index names print for ems 练习 values item
原文地址:https://www.cnblogs.com/qd1228/p/13221785.html