I would like to invert for example this dictionary:
{1: {1: '[]', 2: '[1]'}, 2: {1: '[]', 3: '[1]'}, 3: {1: '[]'}}
Imagine that this is a directed graph with vertices 1, 2, 3
and labelled edges like 1 -> 1
with label '[]'
, represented in dictionary form by 1: {1: '[]'
. The labels don't have to be strings, they can just be lists.
I want to reverse the edges and keep the labels as they are. The output i want is:
{1: {1:'[]', 2:'[]', 3:'[]'}, 2: {1:'[1]'}, 3:{2:'[1]'}}
I saw some methods like Python reverse / invert a mapping but they all work for simpler dictionaries having no "labels".