Skip to content
Advertisement

How to convert the string to a list of dictionary objects containing two keys with respective values?

I have an external file, and I have to convert the strings from the external file to a list of dictionary objects, containing keys and with respective values. The problem is I keep getting error on the code I already tried, such as “too many values to unpack”. I am really stuck in here.

Here is the code:

JavaScript

The content of the input.txt looks like this:

JavaScript

Advertisement

Answer

You need to split by , comma. Also you need a dictionary

Use:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement