0

I have a dictionary. I wish to convert each key/item pair to a separate list. Is this possible?

#  Current dictionary
values_dict = {"label_1": [1,3,6,7], "label_2": [4,8,6,3], "label_3": [5,8,7,2]}

#  From the dictionary above, I would like to make each key/item pair into a separate list so it can be used in matplotlib
#  The numbers of keys/items in the dictionary may vary. Ideally, the finished lists would look like:

label_1_list = [1,3,6,7]
label_2_list = [4,8,6,3]
label_3_list = [5,8,7,2]

From my reading, creating lists dynamically is error prone. So I'm wondering the best way of creating these lists?

Deskjokey
  • 568
  • 1
  • 7
  • 18
  • do you need each of them assigned a specific name or can it just be a list of lists? – gold_cy Jan 13 '22 at 04:10
  • 1
    Generally the python advice would be to just __use the dictionary__. Since you already have accessible separate lists _through_ the dictionary (_i.e._ `label_1_list` already "exists" via `values_dict["label_1"]`) making it (usually) anti-pattern to separate these out into different variables. – Henry Ecker Jan 13 '22 at 04:15

0 Answers0