Line 8: most_letters: if len(word) > Line 9: most_letters = len(word) Line 10: return most_letters Describe how to use the best-so-far pattern. In some situations, an additional variable is needed in the best-so-far pattern. That variable is needed to remember the most recent record holder. 1 def longest_word(words): 2 '''words is a list of strings 3 4 Returns the longest word. 5 ''' most_letters = 0 6 record_holder = '' 7 for in 8 word words: 9 if len(word) > most_letters: most_letters = len(word) 10 record_holder = word 11 return record_holder 12 Execute the code and call the function from the IPython session. How is this function different than the longest_word longest_word function in Step 11? Which line numbers match the following descriptions? Purpose Line number Initialize the record holder Set the record holder Use the record holder Conclusion Questions Describe a real life situation in which your thoughts follow the accumulator pattern. Many uses of the accumulator or aggregator patterns require a conditional if statement inside the loop. Values are only accumulated or aggregated if they meet some condition. For example, shopping uses the aggregator pattern: you look at a sequence of items on the shelf and add the item to your cart if the item
Line 8: if len(word) > most_letters: Line 9: most_letters = len(word) Line 10: return most_letters Describe how to use the best-so-far pattern. In some situations, an additional variable is needed in the best-so-far pattern. That variable is needed to remember the most recent record holder. 1 2 3 4 5 6 7 8 9 10 11 12 def longest_word(words): '''words is a list of strings Returns the longest word. ''' most_letters = 0 record_holder = '' for word in words: if len(word) > most_letters: most_letters = len(word) record_holder = word return record_holder Execute the code and call the function from the IPython session. How is this longest_word function different than the longest_word function in Step 11? Which line numbers match the following descriptions? Purpose Line number Initialize the record holder Set the record holder Use the record holder Conclusion Questions Describe a real life situation in which your thoughts follow the accumulator pattern. Many uses of the accumulator or aggregator patterns require a conditional if statement inside the loop. Values are only accumulated or aggregated if they meet some condition. For example, shopping uses the aggregator pattern: you look at a sequence of items on the shelf and add the item to your cart if the item