-4

How do you split a list of dictionaries into separate dictionaries?

dict_example = [{'limited': 1, 'all': 16, 'concept': 1, 'secondly': 1}, {'hello': 3, 'bye': 6}]

The desired output:

dict_1: {'limited': 1, 'all': 16, 'concept': 1, 'secondly': 1}
dict_2: {'hello': 3, 'bye': 6}
Julien
  • 13,986
  • 5
  • 29
  • 53
evc
  • 13
  • 3

1 Answers1

-1

dict_1, dict_2 = dict_example.

happydave
  • 7,127
  • 1
  • 26
  • 25
  • In the example I only have two dictionaries, let's say I had a list of 50 dictionaries, is there an easier way to write it out so that it's not I'm writing dict_1, dict_2 ...dict_50? – evc Oct 10 '19 at 23:30
  • 1
    @happydave do you really think this deserves an answer? I've seen downvotes raining for less than this... – Julien Oct 10 '19 at 23:32
  • @julien, I have no objection to closing the question, but as long as it's there, it's easy enough to give the answer – happydave Oct 10 '19 at 23:42
  • @evc, the way to avoid declaring 50 dictionary variables is to store them in a list :) – happydave Oct 10 '19 at 23:43