Accessing dict_keys() and dict.values() in python 3

python3  how to get the elements of the dict.keys() and dict.values()

Python 3

mydict = {'a': 'one', 'b': 'two', 'c': 'three'}
mykeys = [*mydict]          #list of keys
myvals = [*mydict.values()] #list of values

print(mykeys)
print(myvals)

Output

['a', 'b', 'c']
['one', 'two', 'three']




References:
https://stackoverflow.com/questions/18552001/accessing-dict-keys-element-by-index-in-python3
posted @ 2022-04-23 11:05  呦呦南山  阅读(23)  评论(0编辑  收藏  举报