Values of Dict A are dictionary Are key of dictionary B best way to convert python

I have a text file that look something of the sort:
mode1=1,2,3,4

mode2=5,3,6,8

mode3=a,t,5,6
etc.

END MODES

group1=mod1,mode2

group2=group1,mode3
etc.

END_GROUPS

I built a dictionary modes where the keys are the modes.
code looks something like this:

for line in mode_def_file:
    if "**END_MODES**" in line:
        break
    k, v = line.strip().split('=')
    modes_dict[k] = v.split(',')

Now to build group dict since values are keys of group_dict or modes_dict
i would like group_dict[group2] = [1,2,3,4,5,3,6,8,a,t,5,6].
I can think of the straightforward approach but is there a quick clean and efficient way to implement this?


Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.