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
1my_list = ['Nagendra','Babu','Nitesh','Sathya']
2my_dict = dict()
3for index,value in enumerate(my_list):
4 my_dict[index] = value
5print(my_dict)
6#OUTPUT
7{0: 'Nagendra', 1: 'Babu', 2: 'Nitesh', 3: 'Sathya'}
1# Python3 program to Convert a
2# list to dictionary
3
4def Convert(lst):
5 res_dct = {lst[i]: lst[i + 1] for i in range(0, len(lst), 2)}
6 return res_dct
7
8# Driver code
9lst = ['a', 1, 'b', 2, 'c', 3]
10print(Convert(lst))
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]]
1dict = {"a": 1, "b": 2, "c": 3, "d": 4}
2
3data = list(dict.items())
4an_array = np.array(data)
5
6print(an_array)
7OUTPUT
8[['a' '1']
9 ['b' '2']
10 ['c' '3']
11 ['d' '4']]
1for key, value in dict.iteritems():
2 temp = [key,value]
3 dictlist.append(temp)
4