dic = {'a':1,
'b':2,
'c':3
}
print(dic.items())
keys = [key for key,value in dic.items()]
print(keys)
values = [value for key,value in dic.items()]
print(values)
keys1 = {value:key for key, value in dic.items()}
print(keys1)
keys2 = {key:value for key, value in dic.items() if key == 'a'}
print(keys2)
运行结果
dict_items([('a', 1), ('b', 2), ('c', 3)])
['a', 'b', 'c']
[1, 2, 3]
{1: 'a', 2: 'b', 3: 'c'}
{'a': 1}
网友评论