Skip to content
Advertisement

Create new list within dictionary of lists if the same keys are there in a string

My code is as follows : I have string that has header data and want create lists of dictionary with same keys values being created as a new list.

JavaScript

Output obtained :

JavaScript

Expected output:

JavaScript

Currently only last key value is obtained, its over-writing into only one list, while wanted 3 lists to be displayed.

Advertisement

Answer

You are repeatedly updating the same dictionary – you need to create a new dictionary at each iteration and append it to a list

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