Maari Maari - 4 years ago 191
Python Question

Split single list into multiple list in python

I have a list which holds json objects like this

a =[{"User": "Ram","Product": "Soap","Price": "25"},
{"User": "Ramesh","Product": "Shampoo","Price": "5"},
{"User": "Ramesh","Product": "powder","Price": "35"}]

Now I want to split this single list into multiple list like this

a2 = [
[{"User": "Ram","Product": "Soap","Price": "25"}],
[{"User": "Ramesh","Product": "Shampoo","Price": "5"}],
[{"User": "Ramesh","Product": "powder","Price": "35"}]

Can anyone tell me how I can achieve this solution, I am new to python.

Answer Source

Just wrap each item in brackets:

a2 = [[item] for item in a]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download