I have a list similar to the following:
my_list =
[(1, 'item_19'),
(2, 'item_20'),
(3, 'item_21'),
(4, 'item_22'),
(5, 'item_23'),
(6, 'item_24'),
(7, 'item_25'),
(8, 'item_26'),
(9, 'item_27'),
(10, 'item_28'),
(11, 'item_29'),
(12, 'item_30'),
(13, 'item_31'),
(14, 'item_32'),
(15, 'item_33'),
(16, 'item_34'),
(17, 'item_35')]
I would like to make a dictionary of each element of the list, i.e. 1:'item_19',2:'item_20'
I currently do this:
list_1 = [l[0] for l in my_list]
list_2 = [l[1] for l in my_list]
and then zip the two lists
my_dict = dict(zip(list_1,list_2))
However there are more than a million element in my_list
, so is this the best way to do this, or is there a quicker/more optimal way to do it(Memory wise).
To put this in context, I want a lookup table to check if elements in my_dict
already exist in a different dictionary my_dict_old