Your question is Normalize Mobile Error Messages. 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.
At Acme Mobile, different app layers emit inconsistent error strings for the same failure. Implement a reusable error normalization function that groups similar raw error messages under a canonical error key.
Write a function group_errors(errors, rules) that takes a list of raw error strings and a list of normalization rules. Each rule is a pair [pattern, canonical]. For every error string, first normalize it by converting to lowercase and replacing every maximal sequence of digits with #. Then, if the normalized string contains one or more rule patterns, assign the error to the canonical value of the longest matching pattern. If no pattern matches, use the normalized string itself as the key. Return a dictionary mapping each final key to its frequency.
def group_errors(errors, rules):