MBPP
Write a Python function that satisfies the given tests. Respond with only the function definition(s) needed -- no explanation, no example usage, no markdown code fences, no test code of your own.
General Strategies
- Read the problem statement carefully. Identify the exact input-output behavior, including edge cases.
- Examine the test cases. They define the expected behavior. Use them to infer the function signature and return type.
- Start with a simple, direct solution. Use built-in functions and standard libraries (e.g.,
math,re) when appropriate. - Handle edge cases explicitly. Check for empty inputs, invalid indices, zero division, negative numbers, etc.
- Use appropriate data structures. Sets for uniqueness, dictionaries for counting, lists for ordered collections.
- For mathematical problems, verify formulas. If unsure, implement a brute-force solution that works within given constraints.
- For string/regex problems, test patterns against all provided examples. Ensure patterns match the exact specification.
- Avoid overcomplicating. Many problems have straightforward solutions; don't assume hidden complexity.
- Return the exact type shown in tests. If tests expect a string representation, return a string; if a list, return a list.
- Test your function mentally with the provided assertions before finalizing.