I am looking for the simplest general way to convert this python list:
x = [ {"foo":"A", "bar":"R", "baz":"X"}, {"foo":"A", "bar":"R", "baz":"Y"}, {"foo":"B", "bar":"S", "baz":"X"}, {"foo":"A", "bar":"S", "baz":"Y"}, {"foo":"C", "bar":"R", "baz":"Y"}, ]
in
foos = [ {"foo":"A", "bars":[ {"bar":"R", "bazs":[ {"baz":"X"},{"baz":"Y"} ] }, {"bar":"S", "bazs":[ {"baz":"Y"} ] }, ] }, {"foo":"B", "bars":[ {"bar":"S", "bazs":[ {"baz":"X"} ] }, ] }, {"foo":"C", "bars":[ {"bar":"R", "bazs":[ {"baz":"Y"} ] }, ] }, ]
The combination of "foo", "bar", "baz" is unique, and as you can see, the list is not necessarily ordered using this key.
Rickya
source share