def get_longest_page(shelf: shelve.DbfilenameShelf) -> (str, int): # To hold the longest page and its number of words longest_page = "" longest_page_count = 0 # Get all urls from the shelve and loop through them keys = shelf.keys() for key in keys: # Get the words for the current url and count its words words = re.split(r"[\s\-–]", shelf[key]) word_count = len(words) # If the amount of words for this url is more than the previous longest page, update the longest page and # word amount if word_count > longest_page_count: longest_page_count = word_count longest_page = key # Return the longest page and its word amount as a 2-tuple return longest_page, longest_page_count