Convert values of a dictionary into key value pair

I have a sample dictionary

sample_dict = [{"id":1, "count":10},
               {"id":2, "count":20},
               {"id":3, "count":30}]

I want something like this

sample_dict = [{1: 10}, {2: 20}, {3: 30}]

how can I do this optimally?

Answer

You probably want a single object like this:

sample_dict = [{"id":1, "count":10},{"id":2, "count":20},{"id":3, "count":30}]

out = { o['id']: o['count'] for o in sample_dict }
print(out) # {1: 10, 2: 20, 3: 30}
print(out[2]) # 20

Note that although the id and count values are in-order, this is not a requirement for this method. So long as the id values are unique, this will work.