1>> d = {'a': 'Arthur', 'b': 'Belling'}
2
3>> d.items()
4[('a', 'Arthur'), ('b', 'Belling')]
5
6>> d.keys()
7['a', 'b']
8
9>> d.values()
10['Arthur', 'Belling']
11
1# To get all the keys of a dictionary use 'keys()'
2newdict = {1:0, 2:0, 3:0}
3newdict.keys()
4# Output:
5# dict_keys([1, 2, 3])
1# This is our example dictionary
2petAges = {"Cat": 4, "Dog": 2, "Fish": 1, "Parrot": 5}
3# This will be our list, epmty for now
4petAgesList = []
5# Search through the dictionary and find all the keys and values
6for key, value in petAges.items():
7 petAgesList.append([key, value]) # Add the key and value to the list
8print(petAgesList) # Print the now-filled list
9# Output: [['Cat', 4], ['Dog', 2], ['Fish', 1], ['Parrot', 5]]
1# To get all the keys of a dictionary as a list, see below
2newdict = {1:0, 2:0, 3:0}
3list(newdict)
4# Output:
5# [1, 2, 3]