I am struggling to come up with some code that does all of the following, wondering if anyone with a bit more knowledge of python can help :)!
It should:
- Removes duplicates from an inputted list - combining the 'account' property into a 'accounts' list - but only if all the other properties are the same.
- If anything except from 'account' differs - have it in its own property of the list.
Perhaps better as example input and output:
input = [
{
"name":"core",
"account":"foo-bar",
"options": {
"foo": "bar"
},
},
{
"name":"core",
"account":"zed-bar",
"options": {
"foo": "bar"
},
},
{
"name":"core",
"account":"tup-bar",
"options": {
"foo": "zed"
},
},
]
Note: How the 3rd properties 'options>foo' is different from the other two.
output = [
{
"name":"core",
"accounts":[
"foo-bar",
"zed-bar"
],
"options": {
"foo": "bar"
},
},
{
"name":"core",
"accounts":[
"tup-bar"
],
"options": {
"foo": "zed"
},
},
]
Notice how it combines the first two elements -- as name and options are the same. But does not combine the 3rd element as its options are different.
Thanks for any help with this, I have been rattling my brain for the past two days trying various combinations.