ok, I feel stupid, but there must be a better way than this! (finding name of unique key in dict)

Jon Ribbens jon+usenet at unequivocal.eu
Fri Jan 20 11:46:03 EST 2023


On 2023-01-20, Dino <dino at no.spam.ar> wrote:
>
> let's say I have this list of nested dicts:
>
> [
>    { "some_key": {'a':1, 'b':2}},
>    { "some_other_key": {'a':3, 'b':4}}
> ]
>
> I need to turn this into:
>
> [
>    { "value": "some_key", 'a':1, 'b':2},
>    { "value": "some_other_key", 'a':3, 'b':4}
> ]

[{"value": key, **value} for d in input_data for key, value in d.items()]



More information about the Python-list mailing list