conversations
listlengths
2
2
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `two_sum` that finds two numbers in a list that add up to a target and returns their indices.", "role": "user" }, { "content": "def two_sum(nums, target...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `two_sum` that finds two numbers in a list that add up to a target and returns their indices.", "role": "user" }, { "content": "def two_sum(nums, target...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `two_sum` that finds two numbers in a list that add up to a target and returns their indices.", "role": "user" }, { "content": "def two_sum(nums, target...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `two_sum` that finds two numbers in a list that add up to a target and returns their indices.", "role": "user" }, { "content": "def two_sum(nums, target...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(matrix):\n if not matrix:\n return []\n result = []\n while matrix:\n result += matrix.pop(0)\n matrix = list(zip(*matrix))[::-1]\n retu...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more efficient:\n\ndef get_primes(n):\n primes = []\n for num in range(2, n + 1):\n is_prime = True\n for i in range(2, num):\n if num % i == 0:\n ...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this binary search:\n\ndef binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mi...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `two_sum` that finds two numbers in a list that add up to a target and returns their indices.", "role": "user" }, { "content": "def two_sum(nums, target...
[ { "content": "You are a code analysis expert. Explain what the code does clearly and concisely.\n\nExplain what this code does:\n\ndef mystery(n):\n if n < 2:\n return n\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n dp[i] = dp[i-1] + dp[i-2]\n return dp[n]", "ro...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `fibonacci` that returns the nth Fibonacci number using iteration. Handle n=0 and n=1.", "role": "user" }, { "content": "def fibonacci(n):\n \"\"\"Re...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `group_anagrams` that takes a list of strings and groups anagrams together.", "role": "user" }, { "content": "def group_anagrams(strs):\n \"\"\"Group...
[ { "content": "You are a Python debugging expert. Fix the bug. Return ONLY the corrected code.\n\nFix the bug in this max subarray (Kadane's algorithm):\n\ndef max_subarray(nums):\n max_sum = 0\n current = 0\n for num in nums:\n current += num\n if current > max_sum:\n max_sum =...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `merge_intervals` that takes a list of intervals [start, end] and merges overlapping intervals.", "role": "user" }, { "content": "def merge_intervals(in...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `is_palindrome` that checks if a string is a palindrome, ignoring case and non-alphanumeric characters.", "role": "user" }, { "content": "def is_palindr...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a code quality expert. Refactor to be more Pythonic and efficient. Return ONLY the code.\n\nRefactor this to be more Pythonic:\n\ndef count_words(text):\n words = text.split(' ')\n counts = {}\n for i in range(len(words)):\n word = words[i].lower()\n if word in count...
[ { "content": "You are a Python coding expert. Write clean, efficient code. Return ONLY the code, no explanations.\n\nWrite a Python function called `flatten_list` that takes a nested list of arbitrary depth and returns a flat list.", "role": "user" }, { "content": "def flatten_list(lst):\n \"\"\"...