Skip to content
Advertisement

Convert list of lists with strings into list of dictionaries

I’m trying to convert a list of lists with strings like:

JavaScript

Some lists can have multiple string elements, and some of the string elements can have multiple key:values separated by a , like "amenity=high_school,place=city".

My goal is to get a list of dicts, in which the key of each dict could append in list several values from the same key. Like this:

JavaScript

Advertisement

Answer

This code works for you. Just if you want any list with just one member to become converted to a simple String it needs to add one line code to it.

Good wishes

JavaScript

The output:

JavaScript

And this is an alternative way with the same output:

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