formatstring find('{'but that is not the full solution if we look at our concrete examplethe value returned is not how in general would we locate the beginning of the slice we wantwe do not want the position of the '{'but the position just after the '{since the length of '{is the correct position is + we can generalize this to start formatstring find('{' okwhat about endclearly it is at the '}in this exampleformatstring find('}'gives us exactly the right place for the end of the slice (one place past the actual endthere is subtle issue here that will be even more important laterwe will keep wanting to find the next braceand not keep finding the first brace how do we fix thatrecall there was an alternate syntax for findspecifying the first place to searchthat is what we need where should we startwellthe end must come after the start of the keyour variable startstart formatstring find('{' end formatstring find('}'startfiguring out how to find the first key is importantbut we are not home free yet we need to come up with code that works in loop for the later keys this code will not work for the next one whyas writtenthe search for '{will again start from the beginning of the format stringand will find the first key again so what code will work for the second searchwe search for the start of the next key going from the end of the last onestart formatstring find('{'end end formatstring find('}'startthis code will also work for later times through the loopeach time uses the end from the previous time through the loop so now what do we do for finding the first keywe could separate the treatment of the first key from all the othersbut an easier approach would be to see if we can use the same code that already works for the later repetitionsand initialize variables right to make it work if we are to find the first key with start formatstring find('{'end then what do we needclearly end needs to have value (there will not be previous loop to give it value what value should we initialize it tothe first search starts from the beginning of the string at index the initialization goes before the loopso the full code for this function is def getkeys(formatstring)'''formatstring is format string with embedded dictionary keys return list containing all the keys from the format string ''keylist list(end repetitions formatstring count('{'for in range(repetitions)start formatstring find('{'end end formatstring find('}'startkey formatstring[start endkeylist append(key objects and methods