I am looking for help on a problem that made me stop. I have a few lines that look like this:
line = '{2}*{3}^2'
The numbers in braces have a display in the dictionary, where the dictionary will look something like this:
factorseq_dict = [('2', 'NAME1'), ('3', 'NAME2')]
What I'm looking for is a script that will read every key (numbers in brackets) in a string and look for the corresponding value in the dictionary. This value will be used to create a new mylist, while preserving everything else in the original string constant. So my new content will change line to new line as follows.
line = '{2}*{3}^2'
newline = '{NAME1}*{NAME2}^2'
I have a dictionary created, but really struggling with the rest of the logic, because I cannot separate the elements that are in curly brackets with the usual numbers, so I am sorry that I can not provide an example code.
, ,
line='{2}*{3}^2'
elements = re.split('({[^}]*})', line)