{"in": "\n\ndef fib(n: int):\n \"\"\"Return n-th Fibonacci number.\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21\n \"\"\"\n", "out": "\ndef fib(n: int):\n if n == 0:\n return 0\n if n == 1:\n return 1\n return fib(n - 1) + fib(n - 2)\n", "pred": "if n < 0: return n - 1 return n"} {"in": "\ndef is_equal_to_sum_even(n):\n \"\"\"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n Example\n is_equal_to_sum_even(4) == False\n is_equal_to_sum_even(6) == False\n is_equal_to_sum_even(8) == True\n \"\"\"\n", "out": "\ndef is_equal_to_sum_even(n):\n return n%2 == 0 and n >= 8\n", "pred": "if n == 0: return False if n == 0: return False return False"} {"in": "\n\ndef truncate_number(number: float) -> float:\n \"\"\" Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n >>> truncate_number(3.5)\n 0.5\n \"\"\"\n", "out": "\ndef truncate_number(number: float) -> float:\n return number % 1.0\n", "pred": "if number == 0: return float(number) return float(number)"} {"in": "from typing import List\n\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n \"\"\" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parse_nested_parens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n \"\"\"\n", "out": "from typing import List\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n def parse_paren_group(s):\n depth = 0\n max_depth = 0\n for c in s:\n if c == '(':\n depth += 1\n max_depth = max(depth, max_depth)\n else:\n depth -= 1\n return max_depth\n return [parse_paren_group(x) for x in paren_string.split(' ') if x]\n", "pred": "if not paren_string: return list(paren_string) return list(paren_string)"} {"in": "\ndef search(lst):\n '''\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than \n zero, and has a frequency greater than or equal to the value of the integer itself. \n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n Examples:\n search([4, 1, 2, 2, 3, 1]) == 2\n search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3\n search([5, 5, 4, 4, 4]) == -1\n '''\n", "out": "\ndef search(lst):\n frq = [0] * (max(lst) + 1)\n for i in lst:\n frq[i] += 1;\n ans = -1\n for i in range(1, len(frq)):\n if frq[i] >= i:\n ans = i\n \n return ans\n", "pred": "if not isinstance(lst, str): return -1 if not isinstance(lst, str): return -1 return -1"} {"in": "\ndef get_odd_collatz(n):\n \"\"\"\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n\n For example:\n get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.\n \"\"\"\n", "out": "\ndef get_odd_collatz(n):\n if n%2==0:\n odd_collatz = [] \n else:\n odd_collatz = [n]\n while n > 1:\n if n % 2 == 0:\n n = n/2\n else:\n n = n*3 + 1\n \n if n%2 == 1:\n odd_collatz.append(int(n))\n return sorted(odd_collatz)\n", "pred": "if not n: return n = n while n < 0: return n else: return n"} {"in": "\ndef add(lst):\n \"\"\"Given a non-empty list of integers lst. add the even elements that are at odd indices..\n\n\n Examples:\n add([4, 2, 6, 7]) ==> 2 \n \"\"\"\n", "out": "\ndef add(lst):\n return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0])\n", "pred": "if not isinstance(lst, list): raise TypeError(\"Lst must be a list\") if not isinstance(lst, list): raise TypeError(\"Lst must be a list\") if not isinstance(lst, list): raise TypeError(\"Lst must be a list\") if not isinstance(lst, list): raise TypeError(\"Lst must be a list\") if not isinstance(lst, list): raise TypeError(\"Lst must be a list\") if not isinstance(lst, list): raise"} {"in": "\ndef count_nums(arr):\n \"\"\"\n Write a function count_nums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n >>> count_nums([]) == 0\n >>> count_nums([-1, 11, -11]) == 1\n >>> count_nums([1, 1, 2]) == 3\n \"\"\"\n", "out": "\ndef count_nums(arr):\n def digits_sum(n):\n neg = 1\n if n < 0: n, neg = -1 * n, -1 \n n = [int(i) for i in str(n)]\n n[0] = n[0] * neg\n return sum(n)\n return len(list(filter(lambda x: x > 0, [digits_sum(i) for i in arr])))\n", "pred": "if arr.startswith('-'): return [] for element in arr: element = element.split('-', 1) if element.startswith('-'): element = element.split('-', 1) element = element.split('-') element = element.split('-') element = element.split('-') element = element.split('-') element = element.split('-') element = element.split('-') element = element.split('-') element = element.split('-') element = element."} {"in": "\ndef compare_one(a, b):\n \"\"\"\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return None if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compare_one(1, 2.5) ➞ 2.5\n compare_one(1, \"2,3\") ➞ \"2,3\"\n compare_one(\"5,1\", \"6\") ➞ \"6\"\n compare_one(\"1\", 1) ➞ None\n \"\"\"\n", "out": "\ndef compare_one(a, b):\n temp_a, temp_b = a, b\n if isinstance(temp_a, str): temp_a = temp_a.replace(',','.')\n if isinstance(temp_b, str): temp_b = temp_b.replace(',','.')\n if float(temp_a) == float(temp_b): return None\n return a if float(temp_a) > float(temp_b) else b \n", "pred": "if a == b: return None return None return None return None"} {"in": "\ndef count_up_to(n):\n \"\"\"Implement a function that takes an non-negative integer and returns an array of the first n\n integers that are prime numbers and less than n.\n for example:\n count_up_to(5) => [2,3]\n count_up_to(11) => [2,3,5,7]\n count_up_to(0) => []\n count_up_to(20) => [2,3,5,7,11,13,17,19]\n count_up_to(1) => []\n count_up_to(18) => [2,3,5,7,11,13,17]\n \"\"\"\n", "out": "\ndef count_up_to(n):\n primes = []\n for i in range(2, n):\n is_prime = True\n for j in range(2, i):\n if i % j == 0:\n is_prime = False\n break\n if is_prime:\n primes.append(i)\n return primes\n", "pred": "if n == 0: return False if n == 0: return False return False return False"} {"in": "\n\ndef is_palindrome(string: str) -> bool:\n \"\"\" Test if given string is a palindrome \"\"\"\n return string == string[::-1]\n\n\ndef make_palindrome(string: str) -> str:\n \"\"\" Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n >>> make_palindrome('')\n ''\n >>> make_palindrome('cat')\n 'catac'\n >>> make_palindrome('cata')\n 'catac'\n \"\"\"\n", "out": "\n\ndef is_palindrome(string: str) -> bool:\n \"\"\" Test if given string is a palindrome \"\"\"\n return string == string[::-1]\n\n\ndef make_palindrome(string: str) -> str:\n if not string:\n return ''\n\n beginning_of_suffix = 0\n\n while not is_palindrome(string[beginning_of_suffix:]):\n beginning_of_suffix += 1\n\n return string + string[:beginning_of_suffix][::-1]\n", "pred": "if string == '-': return False return False return False"} {"in": "\ndef iscube(a):\n '''\n Write a function that takes an integer a and returns True \n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n Examples:\n iscube(1) ==> True\n iscube(2) ==> False\n iscube(-1) ==> True\n iscube(64) ==> True\n iscube(0) ==> True\n iscube(180) ==> False\n '''\n", "out": "\ndef iscube(a):\n a = abs(a)\n return int(round(a ** (1. / 3))) ** 3 == a\n", "pred": "if iscube(a): return False if iscube(a): return False return False return False"} {"in": "\ndef x_or_y(n, x, y):\n \"\"\"A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n\n Examples:\n for x_or_y(7, 34, 12) == 34\n for x_or_y(15, 8, 5) == 5\n \n \"\"\"\n", "out": "\ndef x_or_y(n, x, y):\n if n == 1:\n return y\n for i in range(2, n):\n if n % i == 0:\n return y\n break\n else:\n return x\n", "pred": "if x == 0: return False if x == 0: return False return False return False"} {"in": "\ndef get_row(lst, x):\n \"\"\"\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \n Examples:\n get_row([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n get_row([], 1) == []\n get_row([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n \"\"\"\n", "out": "\ndef get_row(lst, x):\n coords = [(i, j) for i in range(len(lst)) for j in range(len(lst[i])) if lst[i][j] == x]\n return sorted(sorted(coords, key=lambda x: x[1], reverse=True), key=lambda x: x[0])\n", "pred": "row = [] for row in x.items(): if x.startswith('-'): row = row.split('-', 1) if x.startswith('-'): row = row.split('-') if x.startswith('-'): row = row.split('-') if x.startswith('-'): row = row.split('-') if x.startswith('-'): row = row.split('-')"} {"in": "\n\ndef sort_even(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n >>> sort_even([1, 2, 3])\n [1, 2, 3]\n >>> sort_even([5, 6, 3, 4])\n [3, 6, 5, 4]\n \"\"\"\n", "out": "\ndef sort_even(l: list):\n evens = l[::2]\n odds = l[1::2]\n evens.sort()\n ans = []\n for e, o in zip(evens, odds):\n ans.extend([e, o])\n if len(evens) > len(odds):\n ans.append(evens[-1])\n return ans\n", "pred": "if not list: return list(list) return list(list)"} {"in": "\ndef check_if_last_char_is_a_letter(txt):\n '''\n Create a function that returns True if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and False otherwise.\n Note: \"word\" is a group of characters separated by space.\n\n Examples:\n check_if_last_char_is_a_letter(\"apple pie\") ➞ False\n check_if_last_char_is_a_letter(\"apple pi e\") ➞ True\n check_if_last_char_is_a_letter(\"apple pi e \") ➞ False\n check_if_last_char_is_a_letter(\"\") ➞ False \n '''\n", "out": "\ndef check_if_last_char_is_a_letter(txt):\n \n check = txt.split(' ')[-1]\n return True if len(check) == 1 and (97 <= ord(check.lower()) <= 122) else False\n", "pred": "if not isinstance(txt, txt): return False if not isinstance(txt, txt): return False if not isinstance(txt, txt): return False return True"} {"in": "import math\n\n\ndef poly(xs: list, x: float):\n \"\"\"\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n \"\"\"\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\n\n\ndef find_zero(xs: list):\n \"\"\" xs are coefficients of a polynomial.\n find_zero find x such that poly(x) = 0.\n find_zero returns only only zero point, even if there are many.\n Moreover, find_zero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x\n -0.5\n >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3\n 1.0\n \"\"\"\n", "out": "import math\n\n\ndef poly(xs: list, x: float):\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\n\n\ndef find_zero(xs: list):\n begin, end = -1., 1.\n while poly(xs, begin) * poly(xs, end) > 0:\n begin *= 2.0\n end *= 2.0\n while end - begin > 1e-10:\n center = (begin + end) / 2.0\n if poly(xs, center) * poly(xs, begin) > 0:\n begin = center\n else:\n end = center\n return begin", "pred": "if xs is None: return np.zeros(xs) return np.zeros(xs)"} {"in": "\ndef is_multiply_prime(a):\n \"\"\"Write a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100. \n Example:\n is_multiply_prime(30) == True\n 30 = 2 * 3 * 5\n \"\"\"\n", "out": "\ndef is_multiply_prime(a):\n def is_prime(n):\n for j in range(2,n):\n if n%j == 0:\n return False\n return True\n for i in range(2,101):\n if not is_prime(i): continue\n for j in range(2,101):\n if not is_prime(j): continue\n for k in range(2,101):\n if not is_prime(k): continue\n if i*j*k == a: return True\n return False\n", "pred": "if a == 0: return False if a == 0: return False return False"} {"in": "\n\ndef largest_divisor(n: int) -> int:\n \"\"\" For a given number n, find the largest number that divides n evenly, smaller than n\n >>> largest_divisor(15)\n 5\n \"\"\"\n", "out": "\ndef largest_divisor(n: int) -> int:\n for i in reversed(range(n)):\n if n % i == 0:\n return i\n", "pred": "if n < 0: return n - 1 return n"} {"in": "from typing import List, Optional\n\n\ndef longest(strings: List[str]) -> Optional[str]:\n \"\"\" Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n >>> longest([])\n\n >>> longest(['a', 'b', 'c'])\n 'a'\n >>> longest(['a', 'bb', 'ccc'])\n 'ccc'\n \"\"\"\n", "out": "from typing import List, Optional\n\ndef longest(strings: List[str]) -> Optional[str]:\n if not strings:\n return None\n maxlen = max(len(x) for x in strings)\n for s in strings:\n if len(s) == maxlen:\n return s\n", "pred": "if strings is None: return None return None return None"} {"in": "\ndef simplify(x, n):\n \"\"\"Your task is to implement a function that will simplify the expression\n x * n. The function returns True if x * n evaluates to a whole number and False\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n / where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n\n simplify(\"1/5\", \"5/1\") = True\n simplify(\"1/6\", \"2/1\") = False\n simplify(\"7/10\", \"10/2\") = False\n \"\"\"\n", "out": "\ndef simplify(x, n):\n a, b = x.split(\"/\")\n c, d = n.split(\"/\")\n numerator = int(a) * int(c)\n denom = int(b) * int(d)\n if (numerator/denom == int(numerator/denom)):\n return True\n return False\n", "pred": "if n == 0: return False return False return True"} {"in": "from typing import List\n\n\ndef all_prefixes(string: str) -> List[str]:\n \"\"\" Return list of all prefixes from shortest to longest of the input string\n >>> all_prefixes('abc')\n ['a', 'ab', 'abc']\n \"\"\"\n", "out": "from typing import List\n\ndef all_prefixes(string: str) -> List[str]:\n result = []\n for i in range(len(string)):\n result.append(string[:i+1])\n return result\n", "pred": "if string is None: return str(str) return str(str)"} {"in": "\n\ndef modp(n: int, p: int):\n \"\"\"Return 2^n modulo p (be aware of numerics).\n >>> modp(3, 5)\n 3\n >>> modp(1101, 101)\n 2\n >>> modp(0, 101)\n 1\n >>> modp(3, 11)\n 8\n >>> modp(100, 101)\n 1\n \"\"\"\n", "out": "\ndef modp(n: int, p: int):\n ret = 1\n for i in range(n):\n ret = (2 * ret) % p\n return ret\n", "pred": "if p == 0: return n = p.split(',') if p == 0: return n"} {"in": "\ndef select_words(s, n):\n \"\"\"Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n select_words(\"Mary had a little lamb\", 4) ==> [\"little\"]\n select_words(\"Mary had a little lamb\", 3) ==> [\"Mary\", \"lamb\"]\n select_words(\"simple white space\", 2) ==> []\n select_words(\"Hello world\", 4) ==> [\"world\"]\n select_words(\"Uncle sam\", 3) ==> [\"Uncle\"]\n \"\"\"\n", "out": "\ndef select_words(s, n):\n result = []\n for word in s.split():\n n_consonants = 0\n for i in range(0, len(word)):\n if word[i].lower() not in [\"a\",\"e\",\"i\",\"o\",\"u\"]:\n n_consonants += 1 \n if n_consonants == n:\n result.append(word)\n return result\n", "pred": "if s is None: s = [] for i in range(len(s)): if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0: s = i + 1 if i == 0:"} {"in": "from typing import List\n\n\ndef filter_by_prefix(strings: List[str], prefix: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that start with a given prefix.\n >>> filter_by_prefix([], 'a')\n []\n >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')\n ['abc', 'array']\n \"\"\"\n", "out": "from typing import List\n\ndef filter_by_prefix(strings: List[str], prefix: str) -> List[str]:\n return [x for x in strings if x.startswith(prefix)]\n", "pred": "if strings is None: strings = [] for prefix in strings: if strings[-1] == 'a': strings[-1] = strings[-1] if strings[-1] == 'cde': strings[-1] = strings[-1] return strings"} {"in": "\ndef unique_digits(x):\n \"\"\"Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \n For example:\n >>> unique_digits([15, 33, 1422, 1])\n [1, 15, 33]\n >>> unique_digits([152, 323, 1422, 10])\n []\n \"\"\"\n", "out": "\ndef unique_digits(x):\n odd_digit_elements = []\n for i in x:\n if all (int(c) % 2 == 1 for c in str(i)):\n odd_digit_elements.append(i)\n return sorted(odd_digit_elements)\n", "pred": "if not isinstance(x, six.string_types): return [] for i in range(len(x)): if i == 0: return [] for i in range(len(x)): if i == 0: return [] return [] for i in range(len(x)): if i == 0: return [] return []"} {"in": "\ndef minSubArraySum(nums):\n \"\"\"\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n Example\n minSubArraySum([2, 3, 4, 1, 2, 4]) == 1\n minSubArraySum([-1, -2, -3]) == -6\n \"\"\"\n", "out": "\ndef minSubArraySum(nums):\n max_sum = 0\n s = 0\n for num in nums:\n s += -num\n if (s < 0):\n s = 0\n max_sum = max(s, max_sum)\n if max_sum == 0:\n max_sum = max(-i for i in nums)\n min_sum = -max_sum\n return min_sum\n", "pred": "if nums == 0: return -1 return -1 return -1"} {"in": "\n\ndef median(l: list):\n \"\"\"Return median of elements in the list l.\n >>> median([3, 1, 2, 4, 5])\n 3\n >>> median([-10, 4, 6, 1000, 10, 20])\n 15.0\n \"\"\"\n", "out": "\ndef median(l: list):\n l = sorted(l)\n if len(l) % 2 == 1:\n return l[len(l) // 2]\n else:\n return (l[len(l) // 2 - 1] + l[len(l) // 2]) / 2.0\n", "pred": "if len(list) == 0: return list(list) return list(list)"} {"in": "\n\ndef largest_prime_factor(n: int):\n \"\"\"Return the largest prime factor of n. Assume n > 1 and is not a prime.\n >>> largest_prime_factor(13195)\n 29\n >>> largest_prime_factor(2048)\n 2\n \"\"\"\n", "out": "\ndef largest_prime_factor(n: int):\n def is_prime(k):\n if k < 2:\n return False\n for i in range(2, k - 1):\n if k % i == 0:\n return False\n return True\n largest = 1\n for j in range(2, n + 1):\n if n % j == 0 and is_prime(j):\n largest = max(largest, j)\n return largest\n", "pred": "if n < 0: return n - 1 return n"} {"in": "\n\ndef fibfib(n: int):\n \"\"\"The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n >>> fibfib(1)\n 0\n >>> fibfib(5)\n 4\n >>> fibfib(8)\n 24\n \"\"\"\n", "out": "\ndef fibfib(n: int):\n if n == 0:\n return 0\n if n == 1:\n return 0\n if n == 2:\n return 1\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3)\n", "pred": "if n == 0: return fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n) fibfib(n, n)"} {"in": "\ndef odd_count(lst):\n \"\"\"Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> odd_count(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> odd_count(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n \"\"\"\n", "out": "\ndef odd_count(lst):\n res = []\n for arr in lst:\n n = sum(int(d)%2==1 for d in arr)\n res.append(\"the number of odd elements \" + str(n) + \"n the str\"+ str(n) +\"ng \"+ str(n) +\" of the \"+ str(n) +\"nput.\")\n return res\n", "pred": "if len(lst) == 0: return [] for i in range(len(lst)): if i == 0: return i return i"} {"in": "\ndef find_max(words):\n \"\"\"Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n find_max([\"name\", \"of\", \"string\"]) == \"string\"\n find_max([\"name\", \"enam\", \"game\"]) == \"enam\"\n find_max([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"\"aaaaaaa\"\n \"\"\"\n", "out": "\ndef find_max(words):\n return sorted(words, key = lambda x: (-len(set(x)), x))[0]\n", "pred": "if len(words) == 0: return \"\" return \"\" return \"\""} {"in": "\ndef circular_shift(x, shift):\n \"\"\"Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n >>> circular_shift(12, 1)\n \"21\"\n >>> circular_shift(12, 2)\n \"12\"\n \"\"\"\n", "out": "\ndef circular_shift(x, shift):\n s = str(x)\n if shift > len(s):\n return s[::-1]\n else:\n return s[len(s) - shift:] + s[:len(s) - shift]\n", "pred": "if shift == 0: return shift return shift"} {"in": "\n\ndef add(x: int, y: int):\n \"\"\"Add two numbers x and y\n >>> add(2, 3)\n 5\n >>> add(5, 7)\n 12\n \"\"\"\n", "out": "\ndef add(x: int, y: int):\n return x + y\n", "pred": "if x is None: return False return False return False"} {"in": "\ndef right_angle_triangle(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return True if the three\n sides form a right-angled triangle, False otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or \n 90 degree.\n Example:\n right_angle_triangle(3, 4, 5) == True\n right_angle_triangle(1, 2, 3) == False\n '''\n", "out": "\ndef right_angle_triangle(a, b, c):\n return a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b\n", "pred": "if not isinstance(a, (i, (i, (i, (i), (i), (i, (i), (i), (i, (i), (i), (i, (i), (i), (i, (i), (i), (i), (i), (i, (i), (i), (i), (i), (i), (i, (i), (i), (i), (i), (i), (i), (i), (i), (i), (i, (i), (i), (i), (i),"} {"in": "\ndef valid_date(date):\n \"\"\"You have to write a function which validates a given date string and\n returns True if the date is valid otherwise False.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n\n for example: \n valid_date('03-11-2000') => True\n\n valid_date('15-01-2012') => False\n\n valid_date('04-0-2040') => False\n\n valid_date('06-04-2020') => True\n\n valid_date('06/04/2020') => False\n \"\"\"\n", "out": "\ndef valid_date(date):\n try:\n date = date.strip()\n month, day, year = date.split('-')\n month, day, year = int(month), int(day), int(year)\n if month < 1 or month > 12:\n return False\n if month in [1,3,5,7,8,10,12] and day < 1 or day > 31:\n return False\n if month in [4,6,9,11] and day < 1 or day > 30:\n return False\n if month == 2 and day < 1 or day > 29:\n return False\n except:\n return False\n return True\n", "pred": "if date is None: return None try: return None except Exception as e: return None except Exception as e: return None except Exception as e: return None return None except Exception as e: return None return None"} {"in": "from typing import List\n\n\ndef parse_music(music_string: str) -> List[int]:\n \"\"\" Input to this function is a string representing musical notes in a special ASCII format.\n Your task is to parse this string and return list of integers corresponding to how many beats does each\n not last.\n\n Here is a legend:\n 'o' - whole note, lasts four beats\n 'o|' - half note, lasts two beats\n '.|' - quater note, lasts one beat\n\n >>> parse_music('o o| .| o| o| .| .| .| .| o o')\n [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]\n \"\"\"\n", "out": "from typing import List\n\ndef parse_music(music_string: str) -> List[int]:\n note_map = {'o': 4, 'o|': 2, '.|': 1}\n return [note_map[x] for x in music_string.split(' ') if x]\n", "pred": "if not isinstance(music_string, str): raise TypeError('Can only parse a string') if not isinstance(music_string, str): raise TypeError('Can only parse a string') if not isinstance(music_string, str): raise TypeError('Can only parse a string') if not isinstance(music_string, str): raise TypeError('Can only parse a string') if not isinstance(music_string, str): raise TypeError('Can only parse a string') if not isinstance(music_"} {"in": "\ndef is_bored(S):\n \"\"\"\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \n For example:\n >>> is_bored(\"Hello world\")\n 0\n >>> is_bored(\"The sky is blue. The sun is shining. I love this weather\")\n 1\n \"\"\"\n", "out": "\ndef is_bored(S):\n import re\n sentences = re.split(r'[.?!]\\s*', S)\n return sum(sentence[0:2] == 'I ' for sentence in sentences)\n", "pred": "if S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif S.is_bored(S): return False elif"} {"in": "\ndef prod_signs(arr):\n \"\"\"\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n\n Example:\n >>> prod_signs([1, 2, 2, -4]) == -9\n >>> prod_signs([0, 1]) == 0\n >>> prod_signs([]) == None\n \"\"\"\n", "out": "\ndef prod_signs(arr):\n if not arr: return None\n prod = 0 if 0 in arr else (-1) ** len(list(filter(lambda x: x < 0, arr)))\n return prod * sum([abs(i) for i in arr])\n", "pred": "if arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('"} {"in": "\ndef bf(planet1, planet2):\n '''\n There are eight planets in our solar system: the closerst to the Sun \n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2. \n The function should return a tuple containing all planets whose orbits are \n located between the orbit of planet1 and the orbit of planet2, sorted by \n the proximity to the sun. \n The function should return an empty tuple if planet1 or planet2\n are not correct planet names. \n Examples\n bf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\n bf(\"Earth\", \"Mercury\") ==> (\"Venus\")\n bf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")\n '''\n", "out": "\ndef bf(planet1, planet2):\n planet_names = (\"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\")\n if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2:\n return ()\n planet1_index = planet_names.index(planet1)\n planet2_index = planet_names.index(planet2)\n if planet1_index < planet2_index:\n return (planet_names[planet1_index + 1: planet2_index])\n else:\n return (planet_names[planet2_index + 1 : planet1_index])\n", "pred": "if not isinstance(planet1, basestring): raise TypeError('planet1 must be an array of basestring') if not isinstance(planet1, basestring): raise TypeError('planet1 must be an array of basestring') if not isinstance(planet1, basestring): raise TypeError('planet1 must be an array of basestring') if not isinstance(planet1, basestring): raise TypeError('planet1 must be an array of basestring') if not isinstance(planet1, basestring): raise TypeError('planet1 must be an array of"} {"in": "\ndef strange_sort_list(lst):\n '''\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]\n strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]\n strange_sort_list([]) == []\n '''\n", "out": "\ndef strange_sort_list(lst):\n res, switch = [], True\n while lst:\n res.append(min(lst) if switch else max(lst))\n lst.remove(res[-1])\n switch = not switch\n return res\n", "pred": "if len(lst) == 0: return [] for i in range(len(lst)): if i == 0: return [] return []"} {"in": "\ndef compare(game,guess):\n \"\"\"I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n \"\"\"\n", "out": "\ndef compare(game,guess):\n return [abs(x-y) for x,y in zip(game,guess)]\n", "pred": "if not isinstance(game,group): raise TypeError(\"game must be a group of matches\") if not isinstance(game,group): raise TypeError(\"game must be a group of matches\") if not isinstance(game,group): raise TypeError(\"game must be a group of matches\") if not isinstance(game,group): raise TypeError(\"game must be a group of matches\") if not isinstance(game,group): raise TypeError(\"game must be a group of matches\") if not isinstance(game,"} {"in": "\ndef total_match(lst1, lst2):\n '''\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n\n Examples\n total_match([], []) ➞ []\n total_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi']\n total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin']\n total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi']\n total_match(['4'], ['1', '2', '3', '4', '5']) ➞ ['4']\n '''\n", "out": "\ndef total_match(lst1, lst2):\n l1 = 0\n for st in lst1:\n l1 += len(st)\n \n l2 = 0\n for st in lst2:\n l2 += len(st)\n \n if l1 <= l2:\n return lst1\n else:\n return lst2\n", "pred": "if lst1 == lst2: return [] for char in lst1: if char in lst1: return [] return []"} {"in": "\ndef f(n):\n \"\"\" Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n Example:\n f(5) == [1, 2, 6, 24, 15]\n \"\"\"\n", "out": "\ndef f(n):\n ret = []\n for i in range(1,n+1):\n if i%2 == 0:\n x = 1\n for j in range(1,i+1): x *= j\n ret += [x]\n else:\n x = 0\n for j in range(1,i+1): x += j\n ret += [x]\n return ret\n", "pred": "if n == 0: return n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n ="} {"in": "\ndef Strongest_Extension(class_name, extensions):\n \"\"\"You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters \n in the extension's name, the strength is given by the fraction CAP - SM. \n You should find the strongest extension and return a string in this \n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension \n (its strength is -1).\n Example:\n for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n \"\"\"\n", "out": "\ndef Strongest_Extension(class_name, extensions):\n strong = extensions[0]\n my_val = len([x for x in extensions[0] if x.isalpha() and x.isupper()]) - len([x for x in extensions[0] if x.isalpha() and x.islower()])\n for s in extensions:\n val = len([x for x in s if x.isalpha() and x.isupper()]) - len([x for x in s if x.isalpha() and x.islower()])\n if val > my_val:\n strong = s\n my_val = val\n ans = class_name + \".\" + strong\n return ans\n", "pred": "if not extensions: return extensions.lower() return extensions"} {"in": "\ndef match_parens(lst):\n '''\n You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n\n Examples:\n match_parens(['()(', ')']) == 'Yes'\n match_parens([')', ')']) == 'No'\n '''\n", "out": "\ndef match_parens(lst):\n def check(s):\n val = 0\n for i in s:\n if i == '(':\n val = val + 1\n else:\n val = val - 1\n if val < 0:\n return False\n return True if val == 0 else False\n S1 = lst[0] + lst[1]\n S2 = lst[1] + lst[0]\n return 'Yes' if check(S1) or check(S2) else 'No'\n", "pred": "if not isinstance(lst, str): raise TypeError('Lst must be a string') if not isinstance(lst, str): raise TypeError('Lst must be a string') if not isinstance(lst, str): raise TypeError('Lst must be a string') if not isinstance(lst, str): raise TypeError('Lst must be a string') if not isinstance(lst, str): raise TypeError('Lst must be a string') if not isinstance(lst, str): raise"} {"in": "\ndef words_in_sentence(sentence):\n \"\"\"\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n \"\"\"\n", "out": "\ndef words_in_sentence(sentence):\n new_lst = []\n for word in sentence.split():\n flg = 0\n if len(word) == 1:\n flg = 1\n for i in range(2, len(word)):\n if len(word)%i == 0:\n flg = 1\n if flg == 0 or len(word) == 2:\n new_lst.append(word)\n return \" \".join(new_lst)\n", "pred": "if not sentence: return [] for sentence in sentence: if sentence.startswith('-'): return sentence"} {"in": "\ndef numerical_letter_grade(grades):\n \"\"\"It is the last week of the semester and the teacher has to give the grades\n to students. The teacher has been making her own algorithm for grading.\n The only problem is, she has lost the code she used for grading.\n She has given you a list of GPAs for some students and you have to write \n a function that can output a list of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A \n > 3.3 A- \n > 3.0 B+\n > 2.7 B \n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+ \n > 0.7 D \n > 0.0 D-\n 0.0 E\n \n\n Example:\n grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-']\n \"\"\"\n", "out": "\ndef numerical_letter_grade(grades):\n\n \n letter_grade = []\n for gpa in grades:\n if gpa == 4.0:\n letter_grade.append(\"A+\")\n elif gpa > 3.7:\n letter_grade.append(\"A\")\n elif gpa > 3.3:\n letter_grade.append(\"A-\")\n elif gpa > 3.0:\n letter_grade.append(\"B+\")\n elif gpa > 2.7:\n letter_grade.append(\"B\")\n elif gpa > 2.3:\n letter_grade.append(\"B-\")\n elif gpa > 2.0:\n letter_grade.append(\"C+\")\n elif gpa > 1.7:\n letter_grade.append(\"C\")\n elif gpa > 1.3:\n letter_grade.append(\"C-\")\n elif gpa > 1.0:\n letter_grade.append(\"D+\")\n elif gpa > 0.7:\n letter_grade.append(\"D\")\n elif gpa > 0.0:\n letter_grade.append(\"D-\")\n else:\n letter_grade.append(\"E\")\n return letter_grade\n", "pred": "if classes is None: classes = [] for i in enumerate(classes): if i == 0: classes[i] = i + 1 if i == 0: classes[i] = i + 1 if i == 0: classes[i] = i + 1 if i == 0: classes[i] = i + 1 if i == 0: classes[i] = i + 1 if i == 0: classes[i] = i + 1 if"} {"in": "\n\ndef below_threshold(l: list, t: int):\n \"\"\"Return True if all numbers in the list l are below threshold t.\n >>> below_threshold([1, 2, 4, 10], 100)\n True\n >>> below_threshold([1, 20, 4, 10], 5)\n False\n \"\"\"\n", "out": "\ndef below_threshold(l: list, t: int):\n for e in l:\n if e >= t:\n return False\n return True\n", "pred": "if l == 0: return True return True return True"} {"in": "from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n \"\"\" Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True\n \"\"\"\n", "out": "from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n for idx, elem in enumerate(numbers):\n for idx2, elem2 in enumerate(numbers):\n if idx != idx2:\n distance = abs(elem - elem2)\n if distance < threshold:\n return True\n return False\n", "pred": "if threshold == 0: return False return False"} {"in": "\n\ndef change_base(x: int, base: int):\n \"\"\"Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n >>> change_base(8, 3)\n '22'\n >>> change_base(8, 2)\n '1000'\n >>> change_base(7, 2)\n '111'\n \"\"\"\n", "out": "\ndef change_base(x: int, base: int):\n ret = \"\"\n while x > 0:\n ret = str(x % base) + ret\n x //= base\n return ret\n", "pred": "if base == 0: return base else: return base else: return base"} {"in": "\ndef do_algebra(operator, operand):\n \"\"\"\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Example:\n operator['+', '*', '-']\n array = [2, 3, 4, 5]\n result = 2 + 3 * 4 - 5\n => result = 9\n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n \"\"\"\n", "out": "\ndef do_algebra(operator, operand):\n expression = str(operand[0])\n for oprt, oprn in zip(operator, operand[1:]):\n expression+= oprt + str(oprn)\n return eval(expression)\n", "pred": "if operator == operator: return operator.get('-', operator) if operator == operator: return operator.get('-', operator) else: return operator.get('-', operator)"} {"in": "\ndef multiply(a, b):\n \"\"\"Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n Examples:\n multiply(148, 412) should return 16.\n multiply(19, 28) should return 72.\n multiply(2020, 1851) should return 0.\n multiply(14,-15) should return 20.\n \"\"\"\n", "out": "\ndef multiply(a, b):\n return abs(a % 10) * abs(b % 10)\n", "pred": "if b == 0: return a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b"} {"in": "\ndef is_simple_power(x, n):\n \"\"\"Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n For example:\n is_simple_power(1, 4) => true\n is_simple_power(2, 2) => true\n is_simple_power(8, 2) => true\n is_simple_power(3, 2) => false\n is_simple_power(3, 1) => false\n is_simple_power(5, 3) => false\n \"\"\"\n", "out": "\ndef is_simple_power(x, n):\n if (n == 1): \n return (x == 1) \n power = 1\n while (power < x): \n power = power * n \n return (power == x) \n", "pred": "if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False if n == 0: return False return False return False"} {"in": "\ndef encode(message):\n \"\"\"\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n \"\"\"\n", "out": "\ndef encode(message):\n vowels = \"aeiouAEIOU\"\n vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels])\n message = message.swapcase()\n return ''.join([vowels_replace[i] if i in vowels else i for i in message])\n", "pred": "if not isinstance(message, str): raise TypeError('message must be a string') if not isinstance(message, str): raise TypeError('message must be a string') if not isinstance(message, str): raise TypeError('message must be a string') if not isinstance(message, str): raise TypeError('message must be a string') if not isinstance(message, str): raise TypeError('message must be a string') if not isinstance(message, str): raise TypeError('message must be a string') if"} {"in": "\ndef sort_array(array):\n \"\"\"\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sort_array([]) => []\n * sort_array([5]) => [5]\n * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n \"\"\"\n", "out": "\ndef sort_array(array):\n return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0) \n", "pred": "if not array: return [] return [] return [] return []"} {"in": "\ndef double_the_difference(lst):\n '''\n Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n \n double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10\n double_the_difference([-1, -2, 0]) == 0\n double_the_difference([9, -2]) == 81\n double_the_difference([0]) == 0 \n \n If the input list is empty, return 0.\n '''\n", "out": "\ndef double_the_difference(lst):\n return sum([i**2 for i in lst if i > 0 and i%2!=0 and \".\" not in str(i)])\n", "pred": "if not lst.isdigit(): return False if not lst.isdigit(): return False return False"} {"in": "\n\ndef remove_vowels(text):\n \"\"\"\n remove_vowels is a function that takes string and returns string without vowels.\n >>> remove_vowels('')\n ''\n >>> remove_vowels(\"abcdef\\nghijklm\")\n 'bcdf\\nghjklm'\n >>> remove_vowels('abcdef')\n 'bcdf'\n >>> remove_vowels('aaaaa')\n ''\n >>> remove_vowels('aaBAA')\n 'B'\n >>> remove_vowels('zbcd')\n 'zbcd'\n \"\"\"\n", "out": "\ndef remove_vowels(text):\n return \"\".join([s for s in text if s.lower() not in [\"a\", \"e\", \"i\", \"o\", \"u\"]])\n", "pred": "if not text: return text.lower() return text.lower()"} {"in": "\ndef move_one_ball(arr):\n \"\"\"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return True else return False.\n If the given array is empty then return True.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n move_one_ball([3, 4, 5, 1, 2])==>True\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n move_one_ball([3, 5, 4, 1, 2])==>False\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n \"\"\"\n", "out": "\ndef move_one_ball(arr):\n if len(arr)==0:\n return True\n sorted_array=sorted(arr)\n my_arr=[]\n \n min_value=min(arr)\n min_index=arr.index(min_value)\n my_arr=arr[min_index:]+arr[0:min_index]\n for i in range(len(arr)):\n if my_arr[i]!=sorted_array[i]:\n return False\n return True\n", "pred": "if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False if arr == 0: return False return False return False"} {"in": "\ndef histogram(test):\n \"\"\"Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \n Example:\n histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}\n histogram('a b b a') == {'a': 2, 'b': 2}\n histogram('a b c a b') == {'a': 2, 'b': 2}\n histogram('b b b b a') == {'b': 4}\n histogram('') == {}\n\n \"\"\"\n", "out": "\ndef histogram(test):\n dict1={}\n list1=test.split(\" \")\n t=0\n for i in list1:\n if(list1.count(i)>t) and i!='':\n t=list1.count(i)\n if t>0:\n for i in list1:\n if(list1.count(i)==t):\n \n dict1[i]=t\n return dict1\n", "pred": "if not isinstance(test, six.string_types): return [] for letter in enumerate(test): if not isinstance(letter, six.string_types): return [] return []"} {"in": "\n\ndef correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"<\" and \">\".\n return True if every opening bracket has a corresponding closing bracket.\n\n >>> correct_bracketing(\"<\")\n False\n >>> correct_bracketing(\"<>\")\n True\n >>> correct_bracketing(\"<<><>>\")\n True\n >>> correct_bracketing(\"><<>\")\n False\n \"\"\"\n", "out": "\ndef correct_bracketing(brackets: str):\n depth = 0\n for b in brackets:\n if b == \"<\":\n depth += 1\n else:\n depth -= 1\n if depth < 0:\n return False\n return depth == 0\n", "pred": "if brackets is None: return None return None return None return None"} {"in": "\n\ndef strlen(string: str) -> int:\n \"\"\" Return length of given string\n >>> strlen('')\n 0\n >>> strlen('abc')\n 3\n \"\"\"\n", "out": "\ndef strlen(string: str) -> int:\n return len(string)\n", "pred": "if string == 0: return ' ' + str(string) return ' ' + str(string)"} {"in": "from typing import List\n\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that contain given substring\n >>> filter_by_substring([], 'a')\n []\n >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n \"\"\"\n", "out": "from typing import List\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n return [x for x in strings if substring in x]\n", "pred": "if strings is None: strings = [] for i in strings: if i == 0: strings[i] = [] for i in strings: if i == 0: strings[i] = [] for i in strings: strings[i] = [] for i in strings: strings[i] = [] for i in strings: strings[i] = strings[i] if strings[i] == i: strings[i] = strings"} {"in": "\n\ndef max_element(l: list):\n \"\"\"Return maximum element in the list.\n >>> max_element([1, 2, 3])\n 3\n >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n \"\"\"\n", "out": "\ndef max_element(l: list):\n m = l[0]\n for e in l:\n if e > m:\n m = e\n return m\n", "pred": "if l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty: return l elif l.is_empty"} {"in": "\n\n\ndef sum_squares(lst):\n \"\"\"\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n \"\"\"\n", "out": "\n\ndef sum_squares(lst):\n result =[]\n for i in range(len(lst)):\n if i %3 == 0:\n result.append(lst[i]**2)\n elif i % 4 == 0 and i%3 != 0:\n result.append(lst[i]**3)\n else:\n result.append(lst[i])\n return sum(result)\n", "pred": "if not isinstance(lst, list): raise ValueError('Lst must be multiple of 3') if not isinstance(lst, list): raise ValueError('Lst must be multiple of 3') if not isinstance(lst, list): raise ValueError('Lst must be multiple of 3') if not isinstance(lst, list): raise ValueError('Lst must be multiple of 3') if not isinstance(lst, list): raise ValueError('Lst must be multiple of 3') if not isinstance(lst, list): raise"} {"in": "\ndef any_int(x, y, z):\n '''\n Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n \n Examples\n any_int(5, 2, 7) ➞ True\n \n any_int(3, 2, 2) ➞ False\n\n any_int(3, -2, 1) ➞ True\n \n any_int(3.6, -2.2, 2) ➞ False\n \n\n \n '''\n", "out": "\ndef any_int(x, y, z):\n \n if isinstance(x,int) and isinstance(y,int) and isinstance(z,int):\n if (x+y==z) or (x+z==y) or (y+z==x):\n return True\n return False\n return False\n", "pred": "if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True if x == 0: return True else: return True return True"} {"in": "from typing import List\n\n\ndef factorize(n: int) -> List[int]:\n \"\"\" Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n \"\"\"\n", "out": "from typing import List\n\ndef factorize(n: int) -> List[int]:\n import math\n fact = []\n i = 2\n while i <= int(math.sqrt(n) + 1):\n if n % i == 0:\n fact.append(i)\n n //= i\n else:\n i += 1\n if n > 1:\n fact.append(n)\n return fact\n", "pred": "if n < 0: return [] for factor in enumerate(factor): factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor.groupdict() factor = factor."} {"in": "\ndef largest_smallest_integers(lst):\n '''\n Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as None.\n\n Examples:\n largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)\n largest_smallest_integers([]) == (None, None)\n largest_smallest_integers([0]) == (None, None)\n '''\n", "out": "\ndef largest_smallest_integers(lst):\n smallest = list(filter(lambda x: x < 0, lst))\n largest = list(filter(lambda x: x > 0, lst))\n return (max(smallest) if smallest else None, min(largest) if largest else None)\n", "pred": "if lst.is_empty: return None if lst.is_empty: return None return None"} {"in": "\ndef cycpattern_check(a , b):\n \"\"\"You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word\n cycpattern_check(\"abcd\",\"abd\") => False\n cycpattern_check(\"hello\",\"ell\") => True\n cycpattern_check(\"whassup\",\"psus\") => False\n cycpattern_check(\"abab\",\"baa\") => True\n cycpattern_check(\"efef\",\"eeff\") => False\n cycpattern_check(\"himenss\",\"simen\") => True\n\n \"\"\"\n", "out": "\ndef cycpattern_check(a , b):\n l = len(b)\n pat = b + b\n for i in range(len(a) - l + 1):\n for j in range(l + 1):\n if a[i:i+l] == pat[j:j+l]:\n return True\n return False\n", "pred": "if b == b: return True return True return True"} {"in": "\ndef even_odd_count(num):\n \"\"\"Given an integer. return a tuple that has the number of even and odd digits respectively.\n\n Example:\n even_odd_count(-12) ==> (1, 1)\n even_odd_count(123) ==> (1, 2)\n \"\"\"\n", "out": "\ndef even_odd_count(num):\n even_count = 0\n odd_count = 0\n for i in str(abs(num)):\n if int(i)%2==0:\n even_count +=1\n else:\n odd_count +=1\n return (even_count, odd_count)\n", "pred": "if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 if num < 0: return -1 else: return -1 if num < 0: return -1 if num < 0: return -1 else: return -1"} {"in": "\ndef solve(N):\n \"\"\"Given a positive integer N, return the total sum of its digits in binary.\n \n Example\n For N = 1000, the sum of digits will be 1 the output should be \"1\".\n For N = 150, the sum of digits will be 6 the output should be \"110\".\n For N = 147, the sum of digits will be 12 the output should be \"1100\".\n \n Variables:\n @N integer\n Constraints: 0 ≤ N ≤ 10000.\n Output:\n a string of binary number\n \"\"\"\n", "out": "\ndef solve(N):\n return bin(sum(int(i) for i in str(N)))[2:]\n", "pred": "if N == 0: return False if N == 0: return False return False"} {"in": "\n\ndef string_sequence(n: int) -> str:\n \"\"\" Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n >>> string_sequence(0)\n '0'\n >>> string_sequence(5)\n '0 1 2 3 4 5'\n \"\"\"\n", "out": "\ndef string_sequence(n: int) -> str:\n return ' '.join([str(x) for x in range(n + 1)])\n", "pred": "if n < 0: return n = 0 while n < 0: return n"} {"in": "\ndef check_dict_case(dict):\n \"\"\"\n Given a dictionary, return True if all keys are strings in lower \n case or all keys are strings in upper case, else return False.\n The function should return False is the given dictionary is empty.\n Examples:\n check_dict_case({\"a\":\"apple\", \"b\":\"banana\"}) should return True.\n check_dict_case({\"a\":\"apple\", \"A\":\"banana\", \"B\":\"banana\"}) should return False.\n check_dict_case({\"a\":\"apple\", 8:\"banana\", \"a\":\"apple\"}) should return False.\n check_dict_case({\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}) should return False.\n check_dict_case({\"STATE\":\"NC\", \"ZIP\":\"12345\" }) should return True.\n \"\"\"\n", "out": "\ndef check_dict_case(dict):\n if len(dict.keys()) == 0:\n return False\n else:\n state = \"start\"\n for key in dict.keys():\n if isinstance(key, str) == False:\n state = \"mixed\"\n break\n if state == \"start\":\n if key.isupper():\n state = \"upper\"\n elif key.islower():\n state = \"lower\"\n else:\n break\n elif (state == \"upper\" and not key.isupper()) or (state == \"lower\" and not key.islower()):\n state = \"mixed\"\n break\n else:\n break\n return state == \"upper\" or state == \"lower\" \n", "pred": "if not isinstance(dict, dict): return False return False return False"} {"in": "\n\ndef incr_list(l: list):\n \"\"\"Return list with elements incremented by 1.\n >>> incr_list([1, 2, 3])\n [2, 3, 4]\n >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [6, 4, 6, 3, 4, 4, 10, 1, 124]\n \"\"\"\n", "out": "\ndef incr_list(l: list):\n return [(e + 1) for e in l]\n", "pred": "# TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO:"} {"in": "\n\ndef get_positive(l: list):\n \"\"\"Return only positive numbers in the list.\n >>> get_positive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n \"\"\"\n", "out": "\ndef get_positive(l: list):\n return [e for e in l if e > 0]\n", "pred": "# TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO:"} {"in": "\ndef anti_shuffle(s):\n \"\"\"\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n\n For example:\n anti_shuffle('Hi') returns 'Hi'\n anti_shuffle('hello') returns 'ehllo'\n anti_shuffle('Hello World!!!') returns 'Hello !!!Wdlor'\n \"\"\"\n", "out": "\ndef anti_shuffle(s):\n return ' '.join([''.join(sorted(list(i))) for i in s.split(' ')])\n", "pred": "if s.startswith('-'): return s.startswith('-'): return s.startswith('-'): return s.startswith('-'): return s.startswith('-'): return s"} {"in": "\n\ndef fib4(n: int):\n \"\"\"The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fib4(0) -> 0\n fib4(1) -> 0\n fib4(2) -> 2\n fib4(3) -> 0\n fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\n Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n >>> fib4(5)\n 4\n >>> fib4(6)\n 8\n >>> fib4(7)\n 14\n \"\"\"\n", "out": "\ndef fib4(n: int):\n results = [0, 0, 2, 0]\n if n < 4:\n return results[n]\n for _ in range(4, n + 1):\n results.append(results[-1] + results[-2] + results[-3] + results[-4])\n results.pop(0)\n return results[-1]\n", "pred": "if n == 0: return fib4(n, n) return fib4(n, n)"} {"in": "\ndef triangle_area(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle. \n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater \n than the third side.\n Example:\n triangle_area(3, 4, 5) == 6.00\n triangle_area(1, 2, 10) == -1\n '''\n", "out": "\ndef triangle_area(a, b, c):\n if a + b <= c or a + c <= b or b + c <= a:\n return -1 \n s = (a + b + c)/2 \n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5\n area = round(area, 2)\n return area\n", "pred": "if a < b: return a - b return a"} {"in": "\ndef file_name_check(file_name):\n \"\"\"Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n Examples:\n file_name_check(\"example.txt\") # => 'Yes'\n file_name_check(\"1example.dll\") # => 'No' (the name should start with a latin alphapet letter)\n \"\"\"\n", "out": "\ndef file_name_check(file_name):\n suf = ['txt', 'exe', 'dll']\n lst = file_name.split(sep='.')\n if len(lst) != 2:\n return 'No'\n if not lst[1] in suf:\n return 'No'\n if len(lst[0]) == 0:\n return 'No'\n if not lst[0][0].isalpha():\n return 'No'\n t = len([x for x in lst[0] if x.isdigit()])\n if t > 3:\n return 'No'\n return 'Yes'\n", "pred": "if not file_name: return None return None return None"} {"in": "\ndef fruit_distribution(s,n):\n \"\"\"\n In this task, you will be given a string that represents a number of apples and oranges \n that are distributed in a basket of fruit this basket contains \n apples, oranges, and mango fruits. Given the string that represents the total number of \n the oranges and apples and an integer that represent the total number of the fruits \n in the basket return the number of the mango fruits in the basket.\n for examble:\n fruit_distribution(\"5 apples and 6 oranges\", 19) ->19 - 5 - 6 = 8\n fruit_distribution(\"0 apples and 1 oranges\",3) -> 3 - 0 - 1 = 2\n fruit_distribution(\"2 apples and 3 oranges\", 100) -> 100 - 2 - 3 = 95\n fruit_distribution(\"100 apples and 1 oranges\",120) -> 120 - 100 - 1 = 19\n \"\"\"\n", "out": "\ndef fruit_distribution(s,n):\n lis = list()\n for i in s.split(' '):\n if i.isdigit():\n lis.append(int(i))\n return n - sum(lis)\n", "pred": "if not s: raise ValueError('The following a dictionary of the bread tree is a multiple of the bread tree') if not s: raise ValueError('The bread tree is a multiple of the bread tree') if not s: raise ValueError('The bread tree is a multiple of the bread tree') if not s: raise ValueError('The bread tree is a multiple of the bread tree') if not s: raise ValueError('The bread tree is a multiple of the bread tree"} {"in": "\ndef even_odd_palindrome(n):\n \"\"\"\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Example 1:\n\n Input: 3\n Output: (1, 2)\n Explanation:\n Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.\n\n Example 2:\n\n Input: 12\n Output: (4, 6)\n Explanation:\n Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n \"\"\"\n", "out": "\ndef even_odd_palindrome(n):\n def is_palindrome(n):\n return str(n) == str(n)[::-1]\n even_palindrome_count = 0\n odd_palindrome_count = 0\n for i in range(1, n+1):\n if i%2 == 1 and is_palindrome(i):\n odd_palindrome_count += 1\n elif i%2 == 0 and is_palindrome(i):\n even_palindrome_count += 1\n return (even_palindrome_count, odd_palindrome_count)\n", "pred": "if not n: return n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n n = n"} {"in": "from typing import List, Tuple\n\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n \"\"\" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sum_product([])\n (0, 1)\n >>> sum_product([1, 2, 3, 4])\n (10, 24)\n \"\"\"\n", "out": "from typing import List, Tuple\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n sum_value = 0\n prod_value = 1\n for n in numbers:\n sum_value += n\n prod_value *= n\n return sum_value, prod_value\n", "pred": "if not numbers: return [] for i in range(len(numbers)): if i == 0: return [] return []"} {"in": "\ndef by_length(arr):\n \"\"\"\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n\n For example:\n arr = [2, 1, 1, 4, 5, 8, 2, 3] \n -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8] \n -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]\n return [\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]\n \n If the array is empty, return an empty array:\n arr = []\n return []\n \n If the array has any strange number ignore it:\n arr = [1, -1 , 55] \n -> sort arr -> [-1, 1, 55]\n -> reverse arr -> [55, 1, -1]\n return = ['One']\n \"\"\"\n", "out": "\ndef by_length(arr):\n dic = {\n 1: \"One\",\n 2: \"Two\",\n 3: \"Three\",\n 4: \"Four\",\n 5: \"Five\",\n 6: \"Six\",\n 7: \"Seven\",\n 8: \"Eight\",\n 9: \"Nine\",\n }\n sorted_arr = sorted(arr, reverse=True)\n new_arr = []\n for var in sorted_arr:\n try:\n new_arr.append(dic[var])\n except:\n pass\n return new_arr\n", "pred": "if arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('-'): arr = arr.startswith('"} {"in": "\ndef special_factorial(n):\n \"\"\"The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> special_factorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n \"\"\"\n", "out": "\ndef special_factorial(n):\n fact_i = 1\n special_fact = 1\n for i in range(1, n+1):\n fact_i *= i\n special_fact *= fact_i\n return special_fact\n", "pred": "if n == 0: return n = n - 1 if n == 0: return n"} {"in": "\ndef exchange(lst1, lst2):\n \"\"\"In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n For example:\n exchange([1, 2, 3, 4], [1, 2, 3, 4]) => \"YES\"\n exchange([1, 2, 3, 4], [1, 5, 3, 4]) => \"NO\"\n It is assumed that the input lists will be non-empty.\n \"\"\"\n", "out": "\ndef exchange(lst1, lst2):\n odd = 0\n even = 0\n for i in lst1:\n if i%2 == 1:\n odd += 1\n for i in lst2:\n if i%2 == 0:\n even += 1\n if even >= odd:\n return \"YES\"\n return \"NO\"\n \n", "pred": "if lst1 == 0: return False return False return False"} {"in": "\ndef make_a_pile(n):\n \"\"\"\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n\n Examples:\n >>> make_a_pile(3)\n [3, 5, 7]\n \"\"\"\n", "out": "\ndef make_a_pile(n):\n return [n + 2*i for i in range(n)]\n", "pred": "if n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return n elif n < 0: return"} {"in": "\n\ndef same_chars(s0: str, s1: str):\n \"\"\"\n Check if two words have the same characters.\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n True\n >>> same_chars('abcd', 'dddddddabc')\n True\n >>> same_chars('dddddddabc', 'abcd')\n True\n >>> same_chars('eabcd', 'dddddddabc')\n False\n >>> same_chars('abcd', 'dddddddabce')\n False\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')\n False\n \"\"\"\n", "out": "\ndef same_chars(s0: str, s1: str):\n return set(s0) == set(s1)\n", "pred": "if s1 == 'eabcd': return False return False"} {"in": "\ndef solution(lst):\n \"\"\"Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \n\n Examples\n solution([5, 8, 7, 1]) ==> 12\n solution([3, 3, 3, 3, 3]) ==> 9\n solution([30, 13, 24, 321]) ==>0\n \"\"\"\n", "out": "\ndef solution(lst):\n return sum([x for idx, x in enumerate(lst) if idx%2==0 and x%2==1])\n", "pred": "if not isinstance(lst, list): raise ValueError('Lst must be a list of integers') if not isinstance(lst, list): raise ValueError('Lst must be a list of integers') if not isinstance(lst, list): raise ValueError('Lst must be a list of integers') if isinstance(lst, list): raise ValueError('Lst must be a list of integers') if isinstance(lst, list): raise ValueError('Lst must be a"} {"in": "\ndef minPath(grid, k):\n \"\"\"\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n \"\"\"\n", "out": "\ndef minPath(grid, k):\n n = len(grid)\n val = n * n + 1\n for i in range(n):\n for j in range(n):\n if grid[i][j] == 1:\n temp = []\n if i != 0:\n temp.append(grid[i - 1][j])\n if j != 0:\n temp.append(grid[i][j - 1])\n if i != n - 1:\n temp.append(grid[i + 1][j])\n if j != n - 1:\n temp.append(grid[i][j + 1])\n val = min(temp)\n ans = []\n for i in range(k):\n if i % 2 == 0:\n ans.append(1)\n else:\n ans.append(val)\n return ans\n", "pred": "if k == 0: return grid.shape[0] if k == 0: return grid.shape[0] if k == 0: return grid.shape[0] if k == 0: return grid.shape[0] if k == 0: return grid.shape[0] elif k == 0: return grid.shape[0] elif k == 0: return grid.shape[0] elif k == 0: return grid.shape[0] elif k == 0: return grid.shape[0] elif k == 0: return grid.shape[0] elif k == 0: return grid.shape[0]"} {"in": "\ndef tri(n):\n \"\"\"Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n Examples:\n tri(3) = [1, 3, 2, 8]\n \"\"\"\n", "out": "\ndef tri(n):\n if n == 0:\n return [1]\n my_tri = [1, 3]\n for i in range(2, n + 1):\n if i % 2 == 0:\n my_tri.append(i / 2 + 1)\n else:\n my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2)\n return my_tri\n", "pred": "if n < 1: return n = n - 1 if n < 1: return n - 1 return n"} {"in": "\n\ndef flip_case(string: str) -> str:\n \"\"\" For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n >>> flip_case('Hello')\n 'hELLO'\n \"\"\"\n", "out": "\ndef flip_case(string: str) -> str:\n return string.swapcase()\n", "pred": "# TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO:"} {"in": "\ndef intersection(interval1, interval2):\n \"\"\"You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n \"\"\"\n", "out": "\ndef intersection(interval1, interval2):\n def is_prime(num):\n if num == 1 or num == 0:\n return False\n if num == 2:\n return True\n for i in range(2, num):\n if num%i == 0:\n return False\n return True\n l = max(interval1[0], interval2[0])\n r = min(interval1[1], interval2[1])\n length = r - l\n if length > 0 and is_prime(length):\n return \"YES\"\n return \"NO\"\n", "pred": "if interval1 == 0: return interval1 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return interval2 elif interval1 == 0: return"} {"in": "\ndef is_sorted(lst):\n '''\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return False. Assume no negative numbers and only integers.\n\n Examples\n is_sorted([5]) ➞ True\n is_sorted([1, 2, 3, 4, 5]) ➞ True\n is_sorted([1, 3, 2, 4, 5]) ➞ False\n is_sorted([1, 2, 3, 4, 5, 6]) ➞ True\n is_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True\n is_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False\n is_sorted([1, 2, 2, 3, 3, 4]) ➞ True\n is_sorted([1, 2, 2, 2, 3, 4]) ➞ False\n '''\n", "out": "\ndef is_sorted(lst):\n count_digit = dict([(i, 0) for i in lst])\n for i in lst:\n count_digit[i]+=1 \n if any(count_digit[i] > 2 for i in lst):\n return False\n if all(lst[i-1] <= lst[i] for i in range(1, len(lst))):\n return True\n else:\n return False\n \n \n", "pred": "if not isinstance(lst, integers): return False return False return False"} {"in": "from typing import List\n\n\ndef concatenate(strings: List[str]) -> str:\n \"\"\" Concatenate list of strings into a single string\n >>> concatenate([])\n ''\n >>> concatenate(['a', 'b', 'c'])\n 'abc'\n \"\"\"\n", "out": "from typing import List\n\ndef concatenate(strings: List[str]) -> str:\n return ''.join(strings)\n", "pred": "if strings is None: strings = [] for string in strings: if string.startswith('a'): strings.append(string) return strings"} {"in": "\n\ndef sum_to_n(n: int):\n \"\"\"sum_to_n is a function that sums numbers from 1 to n.\n >>> sum_to_n(30)\n 465\n >>> sum_to_n(100)\n 5050\n >>> sum_to_n(5)\n 15\n >>> sum_to_n(10)\n 55\n >>> sum_to_n(1)\n 1\n \"\"\"\n", "out": "\ndef sum_to_n(n: int):\n return sum(range(n + 1))\n", "pred": "if n == 0: return sum_to_n(n) return sum_to_n(n)"} {"in": "\ndef maximum(arr, k):\n \"\"\"\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Example 1:\n\n Input: arr = [-3, -4, 5], k = 3\n Output: [-4, -3, 5]\n\n Example 2:\n\n Input: arr = [4, -4, 4], k = 2\n Output: [4, 4]\n\n Example 3:\n\n Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1\n Output: [2]\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n \"\"\"\n", "out": "\ndef maximum(arr, k):\n if k == 0:\n return []\n arr.sort()\n ans = arr[-k:]\n return ans\n", "pred": "if arr is None: arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr = arr.split('\\n') arr"} {"in": "\ndef smallest_change(arr):\n \"\"\"\n Given an array arr of integers, find the minimum number of elements that\n need to be changed to make the array palindromic. A palindromic array is an array that\n is read the same backwards and forwards. In one change, you can change one element to any other element.\n\n For example:\n smallest_change([1,2,3,5,4,7,9,6]) == 4\n smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1\n smallest_change([1, 2, 3, 2, 1]) == 0\n \"\"\"\n", "out": "\ndef smallest_change(arr):\n ans = 0\n for i in range(len(arr) // 2):\n if arr[i] != arr[len(arr) - i - 1]:\n ans += 1\n return ans\n", "pred": "if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr.lower() if arr.isdigit(): arr = arr"} {"in": "\ndef prime_length(string):\n \"\"\"Write a function that takes a string and returns True if the string\n length is a prime number or False otherwise\n Examples\n prime_length('Hello') == True\n prime_length('abcdcba') == True\n prime_length('kittens') == True\n prime_length('orange') == False\n \"\"\"\n", "out": "\ndef prime_length(string):\n l = len(string)\n if l == 0 or l == 1:\n return False\n for i in range(2, l):\n if l % i == 0:\n return False\n return True\n", "pred": "if string == 'abcdcb': return False return False return False"} {"in": "\ndef rounded_avg(n, m):\n \"\"\"You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n Example:\n rounded_avg(1, 5) => \"0b11\"\n rounded_avg(7, 5) => -1\n rounded_avg(10, 20) => \"0b1111\"\n rounded_avg(20, 33) => \"0b11010\"\n \"\"\"\n", "out": "\ndef rounded_avg(n, m):\n if m < n:\n return -1\n summation = 0\n for i in range(n, m+1):\n summation += i\n return bin(round(summation/(m - n + 1)))\n", "pred": "if n < 0: return -1 return -1 return -1"} {"in": "from typing import List\n\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n \"\"\" From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n >>> remove_duplicates([1, 2, 3, 2, 4])\n [1, 3, 4]\n \"\"\"\n", "out": "from typing import List\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n import collections\n c = collections.Counter(numbers)\n return [n for n in numbers if c[n] <= 1]\n", "pred": "if len(numbers) == 0: return list(list) return list(list)"} {"in": "\ndef generate_integers(a, b):\n \"\"\"\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generate_integers(2, 8) => [2, 4, 6, 8]\n generate_integers(8, 2) => [2, 4, 6, 8]\n generate_integers(10, 14) => []\n \"\"\"\n", "out": "\ndef generate_integers(a, b):\n lower = max(2, min(a, b))\n upper = min(8, max(a, b))\n return [i for i in range(lower, upper+1) if i % 2 == 0]\n", "pred": "if a == b: return [] for i in range(a): if i == b: return [] if i == b: return [] return [] return []"} {"in": "\ndef is_nested(string):\n '''\n Create a function that takes a string as input which contains only square brackets.\n The function should return True if and only if there is a valid subsequence of brackets \n where at least one bracket in the subsequence is nested.\n\n is_nested('[[]]') ➞ True\n is_nested('[]]]]]]][[[[[]') ➞ False\n is_nested('[][]') ➞ False\n is_nested('[]') ➞ False\n is_nested('[[][]]') ➞ True\n is_nested('[[]][[') ➞ True\n '''\n", "out": "\ndef is_nested(string):\n opening_bracket_index = []\n closing_bracket_index = []\n for i in range(len(string)):\n if string[i] == '[':\n opening_bracket_index.append(i)\n else:\n closing_bracket_index.append(i)\n closing_bracket_index.reverse()\n cnt = 0\n i = 0\n l = len(closing_bracket_index)\n for idx in opening_bracket_index:\n if i < l and idx < closing_bracket_index[i]:\n cnt += 1\n i += 1\n return cnt >= 2\n \n", "pred": "if string is None: return None return None return None return None"} {"in": "\ndef can_arrange(arr):\n \"\"\"Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n\n Examples:\n can_arrange([1,2,4,3,5]) = 3\n can_arrange([1,2,3]) = -1\n \"\"\"\n", "out": "\ndef can_arrange(arr):\n ind=-1\n i=1\n while i>> is_palindrome('')\n True\n >>> is_palindrome('aba')\n True\n >>> is_palindrome('aaaaa')\n True\n >>> is_palindrome('zbcd')\n False\n \"\"\"\n", "out": "\ndef is_palindrome(text: str):\n for i in range(len(text)):\n if text[i] != text[len(text) - 1 - i]:\n return False\n return True\n", "pred": "if not text: return False return False return False"} {"in": "from typing import List, Tuple\n\n\ndef rolling_max(numbers: List[int]) -> List[int]:\n \"\"\" From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n >>> rolling_max([1, 2, 3, 2, 3, 4, 2])\n [1, 2, 3, 3, 3, 4, 4]\n \"\"\"\n", "out": "from typing import List, Tuple\n\ndef rolling_max(numbers: List[int]) -> List[int]:\n running_max = None\n result = []\n for n in numbers:\n if running_max is None:\n running_max = n\n else:\n running_max = max(running_max, n)\n result.append(running_max)\n return result\n", "pred": "if not numbers: return [] for i in range(len(numbers)): if i == 0: return [] return []"} {"in": "from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n >>> separate_paren_groups('( ) (( )) (( )( ))')\n ['()', '(())', '(()())']\n \"\"\"\n", "out": "from typing import List\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n result = []\n current_string = []\n current_depth = 0\n for c in paren_string:\n if c == '(':\n current_depth += 1\n current_string.append(c)\n elif c == ')':\n current_depth -= 1\n current_string.append(c)\n if current_depth == 0:\n result.append(''.join(current_string))\n current_string.clear()\n return result\n", "pred": "if paren_string is None: paren_groups = [] for group in paren_string: group = group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group.group"} {"in": "\ndef eat(number, need, remaining):\n \"\"\"\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n \"\"\"\n", "out": "\ndef eat(number, need, remaining):\n if(need <= remaining):\n return [ number + need , remaining-need ]\n else:\n return [ number + remaining , 0]\n", "pred": "if not isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number, basestring): return number elif isinstance(number,"} {"in": "\ndef get_closest_vowel(word):\n \"\"\"You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n\n Example:\n get_closest_vowel(\"yogurt\") ==> \"u\"\n get_closest_vowel(\"FULL\") ==> \"U\"\n get_closest_vowel(\"quick\") ==> \"\"\n get_closest_vowel(\"ab\") ==> \"\"\n \"\"\"\n", "out": "\ndef get_closest_vowel(word):\n if len(word) < 3:\n return \"\"\n vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", 'O', 'U', 'I'}\n for i in range(len(word)-2, 0, -1):\n if word[i] in vowels:\n if (word[i+1] not in vowels) and (word[i-1] not in vowels):\n return word[i]\n return \"\"\n", "pred": "if word.startswith('u'): return False return False"} {"in": "\n\ndef derivative(xs: list):\n \"\"\" xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n >>> derivative([3, 1, 2, 4, 5])\n [1, 4, 12, 20]\n >>> derivative([1, 2, 3])\n [2, 6]\n \"\"\"\n", "out": "\ndef derivative(xs: list):\n return [(i * x) for i, x in enumerate(xs)][1:]\n", "pred": "if xs[0] == 0: return False return False return False"} {"in": "\ndef fix_spaces(text):\n \"\"\"\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \n fix_spaces(\"Example\") == \"Example\"\n fix_spaces(\"Example 1\") == \"Example_1\"\n fix_spaces(\" Example 2\") == \"_Example_2\"\n fix_spaces(\" Example 3\") == \"_Example-3\"\n \"\"\"\n", "out": "\ndef fix_spaces(text):\n new_text = \"\"\n i = 0\n start, end = 0, 0\n while i < len(text):\n if text[i] == \" \":\n end += 1\n else:\n if end - start > 2:\n new_text += \"-\"+text[i]\n elif end - start > 0:\n new_text += \"_\"*(end - start)+text[i]\n else:\n new_text += text[i]\n start, end = i+1, i+1\n i+=1\n if end - start > 2:\n new_text += \"-\"\n elif end - start > 0:\n new_text += \"_\"\n return new_text\n", "pred": "if not text: return text.lower() return text.lower()"} {"in": "\n\ndef count_distinct_characters(string: str) -> int:\n \"\"\" Given a string, find out how many distinct characters (regardless of case) does it consist of\n >>> count_distinct_characters('xyzXYZ')\n 3\n >>> count_distinct_characters('Jerry')\n 4\n \"\"\"\n", "out": "\ndef count_distinct_characters(string: str) -> int:\n return len(set(string.lower()))\n", "pred": "if string is None: string = string.split('\\n') if string.lower() == 0: return string.lower() return string"} {"in": "\ndef get_max_triples(n):\n \"\"\"\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n\n Example :\n Input: n = 5\n Output: 1\n Explanation: \n a = [1, 3, 7, 13, 21]\n The only valid triple is (1, 7, 13).\n \"\"\"\n", "out": "\ndef get_max_triples(n):\n A = [i*i - i + 1 for i in range(1,n+1)]\n ans = []\n for i in range(n):\n for j in range(i+1,n):\n for k in range(j+1,n):\n if (A[i]+A[j]+A[k])%3 == 0:\n ans += [(A[i],A[j],A[k])]\n return len(ans)\n", "pred": "if n < 1: return n = n i = n i = n i = n i = i * i i = i * i i = i * i i = i * i i = i * i i = i * i i = i * i i = i * i i = i * i i = i * i i = i *"} {"in": "\ndef specialFilter(nums):\n \"\"\"Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n For example:\n specialFilter([15, -73, 14, -15]) => 1 \n specialFilter([33, -2, -3, 45, 21, 109]) => 2\n \"\"\"\n", "out": "\ndef specialFilter(nums):\n \n count = 0\n for num in nums:\n if num > 10:\n odd_digits = (1, 3, 5, 7, 9)\n number_as_string = str(num)\n if int(number_as_string[0]) in odd_digits and int(number_as_string[-1]) in odd_digits:\n count += 1\n \n return count \n", "pred": "if nums == 0: return [] for i in range(nums): if i == 0: return i return i"} {"in": "\n\ndef triangle_area(a, h):\n \"\"\"Given length of a side and high return area for a triangle.\n >>> triangle_area(5, 3)\n 7.5\n \"\"\"\n", "out": "\ndef triangle_area(a, h):\n return a * h / 2.0\n", "pred": "if h < 0: a = h[:2] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a = h[:3] a"} {"in": "\ndef int_to_mini_roman(number):\n \"\"\"\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> int_to_mini_roman(19) == 'xix'\n >>> int_to_mini_roman(152) == 'clii'\n >>> int_to_mini_roman(426) == 'cdxxvi'\n \"\"\"\n", "out": "\ndef int_to_mini_roman(number):\n num = [1, 4, 5, 9, 10, 40, 50, 90, \n 100, 400, 500, 900, 1000] \n sym = [\"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \n \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\"] \n i = 12\n res = ''\n while number: \n div = number // num[i] \n number %= num[i] \n while div: \n res += sym[i] \n div -= 1\n i -= 1\n return res.lower()\n", "pred": "if num < 0: return -1 return -1 return -1"} {"in": "\n\ndef fizz_buzz(n: int):\n \"\"\"Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n >>> fizz_buzz(50)\n 0\n >>> fizz_buzz(78)\n 2\n >>> fizz_buzz(79)\n 3\n \"\"\"\n", "out": "\ndef fizz_buzz(n: int):\n ns = []\n for i in range(n):\n if i % 11 == 0 or i % 13 == 0:\n ns.append(i)\n s = ''.join(list(map(str, ns)))\n ans = 0\n for c in s:\n ans += (c == '7')\n return ans\n", "pred": "# Initialize the number of digits which are equal to 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = n * 8 digits = digits"} {"in": "\n\ndef is_prime(n):\n \"\"\"Return true if a given number is prime, and false otherwise.\n >>> is_prime(6)\n False\n >>> is_prime(101)\n True\n >>> is_prime(11)\n True\n >>> is_prime(13441)\n True\n >>> is_prime(61)\n True\n >>> is_prime(4)\n False\n >>> is_prime(1)\n False\n \"\"\"\n", "out": "\ndef is_prime(n):\n if n < 2:\n return False\n for k in range(2, n - 1):\n if n % k == 0:\n return False\n return True\n", "pred": "if n == 0: return False if n == 0: return False return False"} {"in": "from typing import List\n\n\ndef sort_numbers(numbers: str) -> str:\n \"\"\" Input is a space-delimited string of numberals from 'zero' to 'nine'.\n Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\n Return the string with numbers sorted from smallest to largest\n >>> sort_numbers('three one five')\n 'one three five'\n \"\"\"\n", "out": "from typing import List\n\ndef sort_numbers(numbers: str) -> str:\n value_map = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9\n }\n return ' '.join(sorted([x for x in numbers.split(' ') if x], key=lambda x: value_map[x]))\n", "pred": "if numbers is None: return str(numbers) return str(numbers)"} {"in": "\n\ndef greatest_common_divisor(a: int, b: int) -> int:\n \"\"\" Return a greatest common divisor of two integers a and b\n >>> greatest_common_divisor(3, 5)\n 1\n >>> greatest_common_divisor(25, 15)\n 5\n \"\"\"\n", "out": "\ndef greatest_common_divisor(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n", "pred": "if b < b: return a - b return a"} {"in": "from typing import List, Tuple\n\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n \"\"\" From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])\n (2.0, 2.2)\n >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])\n (2.0, 2.0)\n \"\"\"\n", "out": "from typing import List, Tuple\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n closest_pair = None\n distance = None\n for idx, elem in enumerate(numbers):\n for idx2, elem2 in enumerate(numbers):\n if idx != idx2:\n if distance is None:\n distance = abs(elem - elem2)\n closest_pair = tuple(sorted([elem, elem2]))\n else:\n new_distance = abs(elem - elem2)\n if new_distance < distance:\n distance = new_distance\n closest_pair = tuple(sorted([elem, elem2]))\n return closest_pair\n", "pred": "if numbers is None: return [] for i in range(float): if i == 0: return i + 1 return i + 1"} {"in": "\nFIX = \"\"\"\nAdd more test cases.\n\"\"\"\n\ndef vowels_count(s):\n \"\"\"Write a function vowels_count which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n\n Example:\n >>> vowels_count(\"abcde\")\n 2\n >>> vowels_count(\"ACEDY\")\n 3\n \"\"\"\n", "out": "\nFIX = \"\"\"\nテストケースを増やす。\n\"\"\"\n\ndef vowels_count(s):\n vowels = \"aeiouAEIOU\"\n n_vowels = sum(c in vowels for c in s)\n if s[-1] == 'y' or s[-1] == 'Y':\n n_vowels += 1\n return n_vowels\n", "pred": "if not isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s, dict): return s elif isinstance(s,"} {"in": "\n\ndef car_race_collision(n: int):\n \"\"\"\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n \"\"\"\n", "out": "\ndef car_race_collision(n: int):\n return n**2\n", "pred": "if n < 0: return n = int(n) if n < 0: return n"} {"in": "\ndef order_by_points(nums):\n \"\"\"\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n\n For example:\n >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]\n >>> order_by_points([]) == []\n \"\"\"\n", "out": "\ndef order_by_points(nums):\n def digits_sum(n):\n neg = 1\n if n < 0: n, neg = -1 * n, -1 \n n = [int(i) for i in str(n)]\n n[0] = n[0] * neg\n return sum(n)\n return sorted(nums, key=digits_sum)\n", "pred": "if nums == 0: return ['order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order_by_points', 'order"} {"in": "\ndef choose_num(x, y):\n \"\"\"This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n choose_num(12, 15) = 14\n choose_num(13, 12) = -1\n \"\"\"\n", "out": "\ndef choose_num(x, y):\n if x > y:\n return -1\n if y % 2 == 0:\n return y\n if x == y:\n return -1\n return y - 1\n", "pred": "if x == 0: return -1 return -1 return -1"} {"in": "\ndef next_smallest(lst):\n \"\"\"\n You are given a list of integers.\n Write a function next_smallest() that returns the 2nd smallest element of the list.\n Return None if there is no such element.\n \n next_smallest([1, 2, 3, 4, 5]) == 2\n next_smallest([5, 1, 4, 3, 2]) == 2\n next_smallest([]) == None\n next_smallest([1, 1]) == None\n \"\"\"\n", "out": "\ndef next_smallest(lst):\n lst = sorted(set(lst))\n return None if len(lst) < 2 else lst[1]\n", "pred": "if not isinstance(lst, list): raise ValueError('Invalid integers.') if not isinstance(lst, list): raise ValueError('Invalid integers.') if isinstance(lst, list): raise ValueError('Invalid integers.') if isinstance(lst, list): raise ValueError('Invalid integers.') if isinstance(lst, list): raise ValueError('Invalid integers.') if isinstance(lst, list): raise ValueError('Invalid integers.') if isinstance(l"} {"in": "\ndef is_happy(s):\n \"\"\"You are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n For example:\n is_happy(a) => False\n is_happy(aa) => False\n is_happy(abcd) => True\n is_happy(aabb) => False\n is_happy(adb) => True\n is_happy(xyy) => False\n \"\"\"\n", "out": "\ndef is_happy(s):\n if len(s) < 3:\n return False\n for i in range(len(s) - 2):\n \n if s[i] == s[i+1] or s[i+1] == s[i+2] or s[i] == s[i+2]:\n return False\n return True\n", "pred": "if not is_happy(s): return False if not is_happy(s): return False return False return True"} {"in": "\n\ndef encode_shift(s: str):\n \"\"\"\n returns encoded string by shifting every character by 5 in the alphabet.\n \"\"\"\n return \"\".join([chr(((ord(ch) + 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\n\ndef decode_shift(s: str):\n \"\"\"\n takes as input string encoded with encode_shift function. Returns decoded string.\n \"\"\"\n", "out": "\n\ndef encode_shift(s: str):\n return \"\".join([chr(((ord(ch) + 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\n\ndef decode_shift(s: str):\n return \"\".join([chr(((ord(ch) - 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])", "pred": "if not isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s, str): return s elif isinstance(s,"} {"in": "\ndef sort_array(arr):\n \"\"\"\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n \"\"\"\n", "out": "\ndef sort_array(arr):\n return sorted(sorted(arr), key=lambda x: bin(x)[2:].count('1'))\n", "pred": "if arr.startswith('-'): raise ValueError('Input array must be a multiple of integers') if arr.startswith('-'): raise ValueError('Input array must be a multiple of integers') if arr.startswith('-'): raise ValueError('Input array must be a multiple of integers') if arr.startswith('-'): raise ValueError('Input array must be a multiple of integers') if arr.startswith('-'): raise ValueError('Input array must be"} {"in": "\ndef solve(s):\n \"\"\"You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n Examples\n solve(\"1234\") = \"4321\"\n solve(\"ab\") = \"AB\"\n solve(\"#a@C\") = \"#A@c\"\n \"\"\"\n", "out": "\ndef solve(s):\n flg = 0\n idx = 0\n new_str = list(s)\n for i in s:\n if i.isalpha():\n new_str[idx] = i.swapcase()\n flg = 1\n idx += 1\n s = \"\"\n for i in new_str:\n s += i\n if flg == 0:\n return s[len(s)::-1]\n return s\n", "pred": "if s[i] == 'a': return s[i] return s"} {"in": "\n\ndef triples_sum_to_zero(l: list):\n \"\"\"\n triples_sum_to_zero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triples_sum_to_zero([1, 3, 5, 0])\n False\n >>> triples_sum_to_zero([1, 3, -2, 1])\n True\n >>> triples_sum_to_zero([1, 2, 3, 7])\n False\n >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7])\n True\n >>> triples_sum_to_zero([1])\n False\n \"\"\"\n", "out": "\ndef triples_sum_to_zero(l: list):\n for i in range(len(l)):\n for j in range(i + 1, len(l)):\n for k in range(j + 1, len(l)):\n if l[i] + l[j] + l[k] == 0:\n return True\n return False\n", "pred": "if len(l) == 0: return True return True"} {"in": "\n\ndef common(l1: list, l2: list):\n \"\"\"Return sorted unique common elements for two lists.\n >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])\n [1, 5, 653]\n >>> common([5, 3, 2, 8], [3, 2])\n [2, 3]\n\n \"\"\"\n", "out": "\ndef common(l1: list, l2: list):\n ret = set()\n for e1 in l1:\n for e2 in l2:\n if e1 == e2:\n ret.add(e1)\n return sorted(list(ret))\n", "pred": "l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list(l1, list) l1 = list("} {"in": "\ndef will_it_fly(q,w):\n '''\n Write a function that returns True if the object q will fly, and False otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n\n Example:\n will_it_fly([1, 2], 5) ➞ False \n # 1+2 is less than the maximum possible weight, but it's unbalanced.\n\n will_it_fly([3, 2, 3], 1) ➞ False\n # it's balanced, but 3+2+3 is more than the maximum possible weight.\n\n will_it_fly([3, 2, 3], 9) ➞ True\n # 3+2+3 is less than the maximum possible weight, and it's balanced.\n\n will_it_fly([3], 5) ➞ True\n # 3 is less than the maximum possible weight, and it's balanced.\n '''\n", "out": "\ndef will_it_fly(q,w):\n if sum(q) > w:\n return False\n i, j = 0, len(q)-1\n while i bool:\n \"\"\" You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True\n \"\"\"\n", "out": "from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n balance = 0\n for op in operations:\n balance += op\n if balance < 0:\n return True\n return False\n", "pred": "if not operations: return False return False return False"} {"in": "\ndef closest_integer(value):\n '''\n Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n\n Examples\n >>> closest_integer(\"10\")\n 10\n >>> closest_integer(\"15.3\")\n 15\n\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closest_integer(\"14.5\") should\n return 15 and closest_integer(\"-14.5\") should return -15.\n '''\n", "out": "\ndef closest_integer(value):\n from math import floor, ceil\n if value.count('.') == 1:\n # remove trailing zeros\n while (value[-1] == '0'):\n value = value[:-1]\n num = float(value)\n if value[-2:] == '.5':\n if num > 0:\n res = ceil(num)\n else:\n res = floor(num)\n elif len(value) > 0:\n res = int(round(num))\n else:\n res = 0\n return res\n", "pred": "if value == 0: return closest_integer(value) return closest_integer(value)"} {"in": "\n\ndef correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"(\" and \")\".\n return True if every opening bracket has a corresponding closing bracket.\n\n >>> correct_bracketing(\"(\")\n False\n >>> correct_bracketing(\"()\")\n True\n >>> correct_bracketing(\"(()())\")\n True\n >>> correct_bracketing(\")(()\")\n False\n \"\"\"\n", "out": "\ndef correct_bracketing(brackets: str):\n depth = 0\n for b in brackets:\n if b == \"(\":\n depth += 1\n else:\n depth -= 1\n if depth < 0:\n return False\n return depth == 0\n", "pred": "if brackets is None: return None return None return None"} {"in": "\ndef encrypt(s):\n \"\"\"Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n \"\"\"\n", "out": "\ndef encrypt(s):\n d = 'abcdefghijklmnopqrstuvwxyz'\n out = ''\n for c in s:\n if c in d:\n out += d[(d.index(c)+2*2) % 26]\n else:\n out += c\n return out\n", "pred": "if s.startswith('u'): return s.startswith('u'): return s.startswith('u'): return s.startswith('u'): return s.startswith('u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', '"} {"in": "\ndef digits(n):\n \"\"\"Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n For example:\n digits(1) == 1\n digits(4) == 0\n digits(235) == 15\n \"\"\"\n", "out": "\ndef digits(n):\n product = 1\n odd_count = 0\n for digit in str(n):\n int_digit = int(digit)\n if int_digit%2 == 1:\n product= product*int_digit\n odd_count+=1\n if odd_count ==0:\n return 0\n else:\n return product\n", "pred": "if n == 0: return 0 return 0 return 0"} {"in": "\ndef decimal_to_binary(decimal):\n \"\"\"You will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n\n Examples:\n decimal_to_binary(15) # returns \"db1111db\"\n decimal_to_binary(32) # returns \"db100000db\"\n \"\"\"\n", "out": "\ndef decimal_to_binary(decimal):\n return \"db\" + bin(decimal)[2:] + \"db\"\n", "pred": "if decimal == 0: return decimal.to_binary(decimal) return decimal"} {"in": "\ndef hex_key(num):\n \"\"\"You have been tasked to write a function that receives \n a hexadecimal number as a string and counts the number of hexadecimal \n digits that are primes (prime number, or a prime, is a natural number \n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\n Prime numbers are 2, 3, 5, 7, 11, 13, 17,...\n So you have to determine a number of the following digits: 2, 3, 5, 7, \n B (=decimal 11), D (=decimal 13).\n Note: you may assume the input is always correct or empty string, \n and symbols A,B,C,D,E,F are always uppercase.\n Examples:\n For num = \"AB\" the output should be 1.\n For num = \"1077E\" the output should be 2.\n For num = \"ABED1A33\" the output should be 4.\n For num = \"123456789ABCDEF0\" the output should be 6.\n For num = \"2020\" the output should be 2.\n \"\"\"\n", "out": "\ndef hex_key(num):\n primes = ('2', '3', '5', '7', 'B', 'D')\n total = 0\n for i in range(0, len(num)):\n if num[i] in primes:\n total += 1\n return total\n", "pred": "if num < 0: return hex_key(num) return hex_key(num)"} {"in": "\ndef sorted_list_sum(lst):\n \"\"\"Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n For example:\n assert list_sort([\"aa\", \"a\", \"aaa\"]) => [\"aa\"]\n assert list_sort([\"ab\", \"a\", \"aaa\", \"cd\"]) => [\"ab\", \"cd\"]\n \"\"\"\n", "out": "\ndef sorted_list_sum(lst):\n lst.sort()\n new_lst = []\n for i in lst:\n if len(i)%2 == 0:\n new_lst.append(i)\n return sorted(new_lst, key=len)\n", "pred": "if len(lst) == 0: return False return False return False"} {"in": "from typing import List\n\n\ndef string_xor(a: str, b: str) -> str:\n \"\"\" Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> string_xor('010', '110')\n '100'\n \"\"\"\n", "out": "from typing import List\n\ndef string_xor(a: str, b: str) -> str:\n def xor(i, j):\n if i == j:\n return '0'\n else:\n return '1'\n return ''.join(xor(x, y) for x, y in zip(a, b))\n", "pred": "if b == 0: return a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b a = b"} {"in": "\ndef max_fill(grid, capacity):\n import math\n \"\"\"\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Example 1:\n Input: \n grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]]\n bucket_capacity : 1\n Output: 6\n\n Example 2:\n Input: \n grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]]\n bucket_capacity : 2\n Output: 5\n \n Example 3:\n Input: \n grid : [[0,0,0], [0,0,0]]\n bucket_capacity : 5\n Output: 0\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n \"\"\"\n", "out": "\ndef max_fill(grid, capacity):\n import math\n return sum([math.ceil(sum(arr)/capacity) for arr in grid])\n", "pred": "if capacity == 0: return math.load(grid) if capacity == 0: return math.load(grid) return math.load(grid)"} {"in": "\n\ndef unique(l: list):\n \"\"\"Return sorted unique elements in a list\n >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])\n [0, 2, 3, 5, 9, 123]\n \"\"\"\n", "out": "\ndef unique(l: list):\n return sorted(list(set(l)))\n", "pred": "# TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO: TODO:"} {"in": "\n\ndef sort_third(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n >>> sort_third([1, 2, 3])\n [1, 2, 3]\n >>> sort_third([5, 6, 3, 4, 8, 9, 2])\n [2, 6, 3, 4, 8, 9, 5]\n \"\"\"\n", "out": "\ndef sort_third(l: list):\n l = list(l)\n l[::3] = sorted(l[::3])\n return l\n", "pred": "if len(list) == 3: return sorted(list) return sorted(list)"} {"in": "\n\ndef encode_cyclic(s: str):\n \"\"\"\n returns encoded string by cycling groups of three characters.\n \"\"\"\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n # cycle elements in each group. Unless group has fewer elements than 3.\n groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups]\n return \"\".join(groups)\n\n\ndef decode_cyclic(s: str):\n \"\"\"\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n \"\"\"\n", "out": "\n\ndef encode_cyclic(s: str):\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n # cycle elements in each group. Unless group has fewer elements than 3.\n groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups]\n return \"\".join(groups)\n\n\ndef decode_cyclic(s: str):\n return encode_cyclic(encode_cyclic(s))", "pred": "if len(s) == 3: return [] for group in s: if group.group == 3: return group"} {"in": "\n\ndef monotonic(l: list):\n \"\"\"Return True is list elements are monotonically increasing or decreasing.\n >>> monotonic([1, 2, 4, 20])\n True\n >>> monotonic([1, 20, 4, 10])\n False\n >>> monotonic([4, 1, 0, -10])\n True\n \"\"\"\n", "out": "\ndef monotonic(l: list):\n if l == sorted(l) or l == sorted(l, reverse=True):\n return True\n return False\n", "pred": "if not isinstance(l, list): raise TypeError('L must be a list') if not isinstance(l, list): raise TypeError('L must be a list') if isinstance(l, list): raise TypeError('L must be a list') if isinstance(l, list): raise TypeError('L must be a list') if isinstance(l, list): raise TypeError('L must be a list') if isinstance(l, list): raise TypeError('L must be a list') if isinstance(l"} {"in": "\n\ndef skjkasdkd(lst):\n \"\"\"You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n\n Examples:\n For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10\n For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25\n For lst = [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] the output should be 13\n For lst = [0,724,32,71,99,32,6,0,5,91,83,0,5,6] the output should be 11\n For lst = [0,81,12,3,1,21] the output should be 3\n For lst = [0,8,1,2,1,7] the output should be 7\n \"\"\"\n", "out": "\ndef skjkasdkd(lst):\n def isPrime(n):\n for i in range(2,int(n**0.5)+1):\n if n%i==0:\n return False\n return True\n maxx = 0\n i = 0\n while i < len(lst):\n if(lst[i] > maxx and isPrime(lst[i])):\n maxx = lst[i]\n i+=1\n result = sum(int(digit) for digit in str(maxx))\n return result\n", "pred": "if lst.isdigit(): return False if lst.isdigit(): return False return False"} {"in": "\ndef starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n", "out": "\ndef starts_one_ends(n):\n if n == 1: return 1\n return 18 * (10 ** (n - 2))\n", "pred": "if n == 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0 while n < 0: return 0"} {"in": "\n\ndef prime_fib(n: int):\n \"\"\"\n prime_fib returns n-th number that is a Fibonacci number and it's also prime.\n >>> prime_fib(1)\n 2\n >>> prime_fib(2)\n 3\n >>> prime_fib(3)\n 5\n >>> prime_fib(4)\n 13\n >>> prime_fib(5)\n 89\n \"\"\"\n", "out": "\ndef prime_fib(n: int):\n import math\n def is_prime(p):\n if p < 2:\n return False\n for k in range(2, min(int(math.sqrt(p)) + 1, p - 1)):\n if p % k == 0:\n return False\n return True\n f = [0, 1]\n while True:\n f.append(f[-1] + f[-2])\n if is_prime(f[-1]):\n n -= 1\n if n == 0:\n return f[-1]\n", "pred": "if n < 0: return n = int(n) if n < 0: return n"} {"in": "\n\ndef how_many_times(string: str, substring: str) -> int:\n \"\"\" Find how many times a given substring can be found in the original string. Count overlaping cases.\n >>> how_many_times('', 'a')\n 0\n >>> how_many_times('aaa', 'a')\n 3\n >>> how_many_times('aaaa', 'aa')\n 3\n \"\"\"\n", "out": "\ndef how_many_times(string: str, substring: str) -> int:\n times = 0\n for i in range(len(string) - len(substring) + 1):\n if string[i:i+len(substring)] == substring:\n times += 1\n return times\n", "pred": "if string.startswith('a'): return 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',"} {"in": "from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n \"\"\" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n >>> intersperse([], 4)\n []\n >>> intersperse([1, 2, 3], 4)\n [1, 4, 2, 4, 3]\n \"\"\"\n", "out": "from typing import List\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n if not numbers:\n return []\n result = []\n for n in numbers[:-1]:\n result.append(n)\n result.append(delimeter)\n result.append(numbers[-1])\n return result\n", "pred": "if numbers == 0: return [] for i in range(len(numbers)): if i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return [] elif i == 0: return"} {"in": "\n\ndef sum_squares(lst):\n \"\"\"You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n Examples:\n For lst = [1,2,3] the output should be 14\n For lst = [1,4,9] the output should be 98\n For lst = [1,3,5,7] the output should be 84\n For lst = [1.4,4.2,0] the output should be 29\n For lst = [-2.4,1,1] the output should be 6\n \n\n \"\"\"\n", "out": "\ndef sum_squares(lst):\n import math\n squared = 0\n for i in lst:\n squared += math.ceil(i)**2\n return squared\n", "pred": "if lst == 0: return [] for i in range(len(lst)): if i == 0: return [] for i in range(len(lst)): if i == 0: return [] for i in range(len(lst): if i == 0: return i"} {"in": "\ndef split_words(txt):\n '''\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n Examples\n split_words(\"Hello world!\") ➞ [\"Hello\", \"world!\"]\n split_words(\"Hello,world!\") ➞ [\"Hello\", \"world!\"]\n split_words(\"abcdef\") == 3 \n '''\n", "out": "\ndef split_words(txt):\n if \" \" in txt:\n return txt.split()\n elif \",\" in txt:\n return txt.replace(',',' ').split()\n else:\n return len([i for i in txt if i.islower() and ord(i)%2 == 0])\n", "pred": "if not isinstance(txt, str): raise TypeError('txt must be a string') if not isinstance(txt, str): raise TypeError('txt must be a string') if not isinstance(txt, str): raise TypeError('txt must be a string') if not isinstance(txt, str): raise TypeError('txt must be a string') if not isinstance(txt, str): raise TypeError('txt must be a string') if not isinstance(txt, str): raise TypeError('txt must be a string') if"} {"in": "from typing import List\n\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n \"\"\" Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n \"\"\"\n", "out": "from typing import List\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n min_number = min(numbers)\n max_number = max(numbers)\n return [(x - min_number) / (max_number - min_number) for x in numbers]\n", "pred": "if not numbers: return list(numbers) return list(numbers)"} {"in": "from typing import List, Any\n\n\ndef filter_integers(values: List[Any]) -> List[int]:\n \"\"\" Filter given list of any python values only for integers\n >>> filter_integers(['a', 3.14, 5])\n [5]\n >>> filter_integers([1, 2, 3, 'abc', {}, []])\n [1, 2, 3]\n \"\"\"\n", "out": "from typing import List, Any\n\ndef filter_integers(values: List[Any]) -> List[int]:\n return [x for x in values if isinstance(x, int)]\n", "pred": "if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None: return None if values is None:"} {"in": "\ndef digitSum(s):\n \"\"\"Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n\n Examples:\n digitSum(\"\") => 0\n digitSum(\"abAB\") => 131\n digitSum(\"abcCd\") => 67\n digitSum(\"helloE\") => 69\n digitSum(\"woArBld\") => 131\n digitSum(\"aAaaaXa\") => 153\n \"\"\"\n", "out": "\ndef digitSum(s):\n if s == \"\": return 0\n return sum(ord(char) if char.isupper() else 0 for char in s)\n", "pred": "if s.startswith('a'): return s.startswith('a'): return s.startswith('a'): return s.startswith('a'): return s.startswith('a'): return s.startswith('a'): return s"} {"in": "\n\ndef pairs_sum_to_zero(l):\n \"\"\"\n pairs_sum_to_zero takes a list of integers as an input.\n it returns True if there are two distinct elements in the list that\n sum to zero, and False otherwise.\n >>> pairs_sum_to_zero([1, 3, 5, 0])\n False\n >>> pairs_sum_to_zero([1, 3, -2, 1])\n False\n >>> pairs_sum_to_zero([1, 2, 3, 7])\n False\n >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7])\n True\n >>> pairs_sum_to_zero([1])\n False\n \"\"\"\n", "out": "\ndef pairs_sum_to_zero(l):\n for i, l1 in enumerate(l):\n for j in range(i + 1, len(l)):\n if l1 + l[j] == 0:\n return True\n return False\n", "pred": "if l == 0: return False return True"} {"in": "from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\" For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])\n 1.0\n \"\"\"\n", "out": "from typing import List\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n mean = sum(numbers) / len(numbers)\n return sum(abs(x - mean) for x in numbers) / len(numbers)\n", "pred": "if numbers == 0: return float(numbers) return float(numbers)"} {"in": "\ndef reverse_delete(s,c):\n \"\"\"Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and True/False for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',False)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',False)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',True)\n \"\"\"\n", "out": "\ndef reverse_delete(s,c):\n s = ''.join([char for char in s if char not in c])\n return (s,s[::-1] == s)\n", "pred": "if c == 'ae': return True return True"} {"in": "\ndef string_to_md5(text):\n \"\"\"\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n\n >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n \"\"\"\n", "out": "\ndef string_to_md5(text):\n import hashlib\n return hashlib.md5(text.encode('ascii')).hexdigest() if text else None\n", "pred": "if not text: return None return None return None"} {"in": "\ndef words_string(s):\n \"\"\"\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \n For example:\n words_string(\"Hi, my name is John\") == [\"Hi\", \"my\", \"name\", \"is\", \"John\"]\n words_string(\"One, two, three, four, five, six\") == [\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n \"\"\"\n", "out": "\ndef words_string(s):\n if not s:\n return []\n s_list = []\n for letter in s:\n if letter == ',':\n s_list.append(' ')\n else:\n s_list.append(letter)\n s_list = \"\".join(s_list)\n return s_list.split()\n", "pred": "if not s: return s.split(',') if not s: return s"} {"in": "\ndef add_elements(arr, k):\n \"\"\"\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n \"\"\"\n", "out": "\ndef add_elements(arr, k):\n return sum(elem for elem in arr[:k] if len(str(elem)) <= 2)\n", "pred": "if arr.isdigit(): raise ValueError('Invalid arr {}'.format(arr)) if arr.isdigit(): raise ValueError('Invalid arr {}'.format(arr)) if arr.isdigit(): raise ValueError('Invalid arr {}'.format(arr)) return False"} {"in": "\ndef count_upper(s):\n \"\"\"\n Given a string s, count the number of uppercase vowels in even indices.\n \n For example:\n count_upper('aBCdEf') returns 1\n count_upper('abcdefg') returns 0\n count_upper('dBBE') returns 0\n \"\"\"\n", "out": "\ndef count_upper(s):\n count = 0\n for i in range(0,len(s),2):\n if s[i] in \"AEIOU\":\n count += 1\n return count\n", "pred": "if len(s) == 0: return s return s"} {"in": "\ndef pluck(arr):\n \"\"\"\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Example 1:\n Input: [4,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index.\n\n Example 2:\n Input: [1,2,3]\n Output: [2, 1]\n Explanation: 2 has the smallest even value, and 2 has the smallest index. \n\n Example 3:\n Input: []\n Output: []\n \n Example 4:\n Input: [5, 0, 3, 0, 4, 2]\n Output: [0, 1]\n Explanation: 0 is the smallest value, but there are two zeros,\n so we will choose the first zero, which has the smallest index.\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n \"\"\"\n", "out": "\ndef pluck(arr):\n if(len(arr) == 0): return []\n evens = list(filter(lambda x: x%2 == 0, arr))\n if(evens == []): return []\n return [min(evens), arr.index(min(evens))]\n", "pred": "if arr.is_smallest_value: raise ValueError(\"Must be negative integers\") if arr.is_smallest_value: raise ValueError(\"Must be negative integers\") if arr.is_smallest_value: raise ValueError(\"Must be negative integers\") if arr.is_smallest_value: raise ValueError(\"Must be negative integers\") if arr.is_smallest_value: raise ValueError(\"Must be negative integers\") if arr.is_smallest_value: raise"}