Dictionary of lists to list of lists

EasyDictionary Programs · 43 of 94

Write a Python program to convert {key: [values]} into [[key, values…], …].

Advertisement
Input
{"sqa": [1, 4, 6], "tools": [3, 6, 9]}
Output
[['sqa', 1, 4, 6], ['tools', 3, 6, 9]]

Approach

  1. [k, *v] unpacks the list after the key.

Solution

Python
d = {"sqa": [1, 4, 6], "tools": [3, 6, 9]}print([[k, *v] for k, v in d.items()])
Output
[['sqa', 1, 4, 6], ['tools', 3, 6, 9]]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs