Your question is Compare Two Jumbled Paragraphs. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
HashedIn content systems may receive the same paragraph with sentences reordered and words rearranged within each sentence. Write a function that determines whether two paragraphs are structurally identical under these reorderings.
Two paragraphs are considered equal when:
., !, or ?. Any other non-alphanumeric character separates words, and empty fragments are ignored.Return True when the paragraphs are equivalent, otherwise return False.
Implement compare_paragraphs(paragraph_a, paragraph_b), where both inputs are strings. Return a boolean.
Example 1:
Input: paragraph_a = "Fast delivery. Secure platform!"
paragraph_b = "platform secure? delivery fast."
Output: True
The two sentences and the two words in each sentence are reordered, so their normalized structures match.
Example 2:
Input: paragraph_a = "HashedIn builds great tools."
paragraph_b = "Great tools build HashedIn."
Output: False
The word frequencies differ because builds and build are different words.
def compare_paragraphs(paragraph_a, paragraph_b):