Skip to content
Advertisement

Creating list of dictionaries from a dictionary using list comprehension

I have a dictionary of the format:

JavaScript

And I’m trying to create a list of dictionaries that separate the values, i.e., the result should be:

JavaScript

Is there a way I can do this with a one-line list comprehension?

What I have tried so far:

JavaScript

And my code using a normal “for” loop:

JavaScript

Advertisement

Answer

Here’s a list comprehension + dictionary comprehension version of one-liner to achieve this:

JavaScript

where new_list will hold:

JavaScript
Advertisement