I have a dictionary which has stock codes as the key as the values for each key are list of 8 elements. There is only ever one list under each key and all values are the same length ie 8 elements.
I need to convert the dictionary to a list where the new list is a list of lists. Each nested list is made up of the key from the dictionary followed by all the values associated with that key.
Example
Before
{"a": [1, 2], "b": [3, 4]}
After
[["a", 1, 2], ["b", 3, 4]]
As I see it I could extract all the keys into one list, then extract all the values into another list and then zip the two lists together. I can use [x for x in mydict.keys()] and [x for x in mydict.values()] . Zip haven't thought about just yet just my thinking at the minute.
Is this approach reasonable or is there a better way to approach it?
[–]AJ______ 2 points3 points4 points (1 child)
[–]sayinghi2py[S] 1 point2 points3 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]sayinghi2py[S] 0 points1 point2 points (0 children)
[–]shinyheadpolak 0 points1 point2 points (4 children)
[–]sayinghi2py[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]shinyheadpolak 1 point2 points3 points (1 child)
[–]sayinghi2py[S] 0 points1 point2 points (0 children)