repeat the correct number of times this will work in this case (there is more efficient approach after we introduce while statements (page )suggested in mad lib while exercise (page firsthow many times do we want to pull out key once for each embedded format so how do we count thosethe count method is obviously way to count however we must count fixed stringand the whole embedded formats varywith different keys in the middle common part is '{'and this should not appear in the regular text of the storyso it will serve our purposerepetitions formatstring count('{'for in range(repetitions)this is certainly the most challenging code to date before jumping into writing it all preciselywe can give an overall plan in pseudo-code for plan we need an idea of what quantities we are keeping track ofand name themand outline the sequence of operations with them think about data to namein this case we are trying to find list we will need to extract one element at time and add it to the listso we need listsay keylist the central task is to identifying the individual keys when we find key we can call it key think about identifying the text of individual keys this may be too hard to think of in the abstractso let us use as concrete exampleand let us keep it simple for the moment suppose the data in formatstring starts off as follows the lines with numbers are added to help us refer to the indices display of possible data 'blah {animalblah blah {foodstart of formatstring the first key is 'animalat formatstring[ : the next key is 'foodat formatstring[ : to identify each key as part of formatstring we need not only the variable formatstringbut also index variables to locate the start and end of the slices obvious names for the indices are start and end we want to keep them current so the next key slice will always be key formatstring[start endlet us now put this all in an overall plan we will have to continuously modify the start and end indicesthe keyand the list we have basic pattern for accumulating listinvolving initializing it and appending to it we can organize planpartly fleshed outwith couple of approximations still to be worked out the parts that are not yet in python are emphasizeddef getkeys(formatstring)keylist list(?other initializations ?repetitions formatstring count('{'for in range(repetitions)find the start and end of the next key key formatstring[start endkeylist append(keyreturn keylist we can see that the main piece left is to find the start and end indices for each key the important word is findthe method we consider is find as with the plan for using count abovethe beginnings of keys are identified by the specific string '{we can look first at mad libs revisited