I have the below list called My_list and want to convert it to a dictionary called My_dict
.
My_list=['I=113','PLAN=1','A=0PDFGB','B=23FGC','C=26TGFGD','D=19TGE','E=18TGA',
'I=120','PLAN=2','A=0PDFGB','B=23FGC','C=26TGFGD','D=19TGE','E=18TGA']
the output should be as below:
My_dict={'I=113': ['PLAN=1', 'A=0PDFGB', 'B=23FGC', 'C=26TGFGD','D=19TGE', 'E=18TGA'],
'I=120': ['PLAN=2', 'A=0PDFGB', 'B=23FGC',' C=26TGFGD','D=19TGE','E=18TGA']}
As you see, I want to make the strings starting with I=
become my dictionary’s keys and the ones between two strings that start with I=
to be my first keys values and so on.
I’ll appreciate your guidance on this matter.
We could use a loop:
Output: