Recap: Mission Log Analyzer
Combine built-in functions, problem decomposition, counter, accumulator, and flag patterns
Mission: Mission Log Analyzer
The mission log is a single string of words separated by spaces, stored in a variable named log. Break the work into three functions, each using a different pattern:
count_word(log, word): counter pattern: how many timeswordappears in the loglongest_word(log): accumulator pattern: the longest word in the log (the first one if several are equally long)has_duplicate(log): flag pattern: returnsTrueif any word appears more than once
In the main program, also use built-in functions: len() for the total word count and sorted() together with a set() for the unique words. Print:
Total words:then how many words there areCount of scan:then how many timesscanappearsLongest word:then the longest wordHas duplicate:thenTrueorFalseUnique words:then the sorted list of unique words
Output
Total words: 7
Count of scan: 3
Longest word: analyze
Has duplicate: True
Unique words: ['analyze', 'boot', 'probe', 'scan']