python_code
stringlengths
0
869k
ENTRY_POINT = 'filter_integers' #[PROMPT] from typing import List, Any def filter_integers(values: List[Any]) -> List[int]: """ Filter given list of any python values only for integers >>> filter_integers(['a', 3.14, 5]) [5] >>> filter_integers([1, 2, 3, 'abc', {}, []]) [1, 2, 3] """ #[SOLUTIO...
ENTRY_POINT = 'filter_by_substring' #[PROMPT] from typing import List def filter_by_substring(strings: List[str], substring: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> filter_by_substring([], 'a') [] >>> filter_by_substring(['abc', 'bacd', 'cd...
ENTRY_POINT = 'f' #[PROMPT] def f(n): """ Implement the function f that takes n as a parameter, 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 or the sum of numbers from 1 to i otherwise. i starts from 1. the factorial of i is the mult...
ENTRY_POINT = 'fix_spaces' #[PROMPT] def fix_spaces(text): """ Given a string text, replace all spaces in it with underscores, and if a string has more than 2 consecutive spaces, then replace all consecutive spaces with - fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Ex...
ENTRY_POINT = 'derivative' #[PROMPT] def derivative(xs: list): """ xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> derivative([3, 1, 2, 4, 5]) [1, 4, 12, 20] >>> derivative([1, 2, 3]) [2, 6] "...
ENTRY_POINT = 'eat' #[PROMPT] def eat(number, need, remaining): """ You're a hungry rabbit, and you already have eaten a certain number of carrots, but now you need to eat more carrots to complete the day's meals. you should return an array of [ total number of eaten carrots after your meals, ...
ENTRY_POINT = 'minPath' #[PROMPT] def minPath(grid, k): """ Given a grid with N rows and N columns (N >= 2) and a positive integer k, each cell of the grid contains a value. Every integer in the range [1, N * N] inclusive appears exactly once on the cells of the grid. You have to find the minimum...
ENTRY_POINT = 'compare' #[PROMPT] def compare(game,guess): """I think we all remember that feeling when the result of some long-awaited event is finally known. The feelings and thoughts you have at that moment are definitely worth noting down and comparing. Your task is to determine if a person correct...
ENTRY_POINT = 'next_smallest' #[PROMPT] def next_smallest(lst): """ You are given a list of integers. Write a function next_smallest() that returns the 2nd smallest element of the list. Return None if there is no such element. next_smallest([1, 2, 3, 4, 5]) == 2 next_smallest([5, 1, 4, 3, ...
ENTRY_POINT = 'prime_fib' FIX = """ Update test to not call prime_fib """ #[PROMPT] def prime_fib(n: int): """ prime_fib returns n-th number that is a Fibonacci number and it's also prime. >>> prime_fib(1) 2 >>> prime_fib(2) 3 >>> prime_fib(3) 5 >>> prime_fib(4) 13 >>> pr...
ENTRY_POINT = 'match_parens' FIX = """ Fix the bug of in solution which considers )( )( as valid. Add test case for above. """ #[PROMPT] def match_parens(lst): ''' You are given a list of two strings, both strings consist of open parentheses '(' or close parentheses ')' only. Your job is to check if ...
ENTRY_POINT = 'right_angle_triangle' #[PROMPT] def right_angle_triangle(a, b, c): ''' Given the lengths of the three sides of a triangle. Return True if the three sides form a right-angled triangle, False otherwise. A right-angled triangle is a triangle in which one angle is right angle or 90 degr...
ENTRY_POINT = 'sum_product' #[PROMPT] from typing import List, Tuple def sum_product(numbers: List[int]) -> Tuple[int, int]: """ For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1. ...
ENTRY_POINT = 'get_row' #[PROMPT] def get_row(lst, x): """ You are given a 2 dimensional data, as a nested lists, which is similar to matrix, however, unlike matrices, each row may contain a different number of columns. Given lst, and integer x, find integers x in the list, and return list of t...
ENTRY_POINT = 'iscube' FIX = """ Rmove part of docstring which doesn't make sense. """ #[PROMPT] def iscube(a): ''' Write a function that takes an integer a and returns True if this ingeger is a cube of some integer number. Note: you may assume the input is always valid. Examples: iscube(1) ...
ENTRY_POINT = 'even_odd_count' #[PROMPT] def even_odd_count(num): """Given an integer. return a tuple that has the number of even and odd digits respectively. Example: even_odd_count(-12) ==> (1, 1) even_odd_count(123) ==> (1, 2) """ #[SOLUTION] even_count = 0 odd_count = 0 fo...
ENTRY_POINT = 'find_zero' #[PROMPT] import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): ""...
ENTRY_POINT = 'remove_vowels' FIX = """ Make vowel check case insensitive. """ #[PROMPT] def remove_vowels(text): """ remove_vowels is a function that takes string and returns string without vowels. >>> remove_vowels('') '' >>> remove_vowels("abcdef\nghijklm") 'bcdf\nghjklm' >>> remove_...
ENTRY_POINT = 'mean_absolute_deviation' #[PROMPT] from typing import List def mean_absolute_deviation(numbers: List[float]) -> float: """ For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between...
ENTRY_POINT = 'solution' #[PROMPT] def solution(lst): """Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. Examples solution([5, 8, 7, 1]) ==> 12 solution([3, 3, 3, 3, 3]) ==> 9 solution([30, 13, 24, 321]) ==>0 """ #[SOLUTION] re...
ENTRY_POINT = 'count_distinct_characters' #[PROMPT] def count_distinct_characters(string: str) -> int: """ Given a string, find out how many distinct characters (regardless of case) does it consist of >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4 """ #[SOLU...
ENTRY_POINT = 'double_the_difference' FIX = """ Fix the incorrect example. """ #[PROMPT] def double_the_difference(lst): ''' Given a list of numbers, return the sum of squares of the numbers in the list that are odd. Ignore numbers that are negative or not integers. double_the_difference([1, 3, ...
ENTRY_POINT = 'sum_squares' #[PROMPT] def sum_squares(lst): """" 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 multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. T...
ENTRY_POINT = 'get_odd_collatz' #[PROMPT] def get_odd_collatz(n): """ Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence. The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. The...
ENTRY_POINT = 'count_nums' #[PROMPT] def count_nums(arr): """ Write a function count_nums which takes an array of integers and returns the number of elements which has a sum of digits > 0. If a number is negative, then its first signed digit will be negative: e.g. -123 has signed digits -1, 2, and ...
ENTRY_POINT = 'unique_digits' #[PROMPT] def unique_digits(x): """Given a list of positive integers x. return a sorted list of all elements that hasn't any even digit. Note: Returned list should be sorted in increasing order. For example: >>> unique_digits([15, 33, 1422, 1]) [1, 15, 33] ...
ENTRY_POINT = 'count_up_to' #[PROMPT] def count_up_to(n): """Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: count_up_to(5) => [2,3] count_up_to(11) => [2,3,5,7] count_up_to(0) => [] co...
ENTRY_POINT = 'pairs_sum_to_zero' FIX = """ Fix the bug of allowing one element to be used multiple times. """ #[PROMPT] def pairs_sum_to_zero(l): """ pairs_sum_to_zero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False ot...
ENTRY_POINT = 'filter_by_prefix' #[PROMPT] from typing import List def filter_by_prefix(strings: List[str], prefix: str) -> List[str]: """ Filter an input list of strings only for ones that start with a given prefix. >>> filter_by_prefix([], 'a') [] >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'],...
ENTRY_POINT = 'bf' #[PROMPT] def bf(planet1, planet2): ''' There are eight planets in our solar system: the closerst to the Sun is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, Uranus, Neptune. Write a function that takes two planet names as strings planet1 and planet2. ...
ENTRY_POINT = 'triangle_area' #[PROMPT] def triangle_area(a, b, c): ''' Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1 Three sides make a valid triangle when the sum of an...
ENTRY_POINT = 'circular_shift' #[PROMPT] def circular_shift(x, shift): """Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. >>> circular_shift(12, 1) "21" >>> circular_shift(12, 2) ...
ENTRY_POINT = 'separate_paren_groups' #[PROMPT] from typing import List def separate_paren_groups(paren_string: str) -> List[str]: """ Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. ...
def my_func(): a = 0 # a = 0 # a += 1 # print(a===1) # Please write a corrected version of the commented line that has a syntax error # END OF CONTEXT print(a == 1) # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source....
from typing import List def below_zero(operations: List[int]) -> bool: """You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account falls below zero, and at that point the function should return Tr...
def my_func(): a = [] # append(a, 1) # print(a) # b=a # Please write a corrected version of the commented line that has a syntax error # END OF CONTEXT print(a.append(1)) # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = s...
def my_func(): a = 0 # a = 0 # a += 1 # print(a===1) # Please write a corrected version of the commented line that has a syntax error # END OF CONTEXT print(a == 1) # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source....
def my_func(): # Please create 3 empty lists named a, b, and c. # END OF CONTEXT a = [] b = [] c = [] # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source.strip().split("\n") # remove comments lines = [l for l in lines...
def my_func(): def g(a, b): return a - b x = 1 y = 2 g(x, y) # Please call g again with the argument order reversed # END OF CONTEXT g(y, x) # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source.strip().split...
def my_func(): a = 0 # Please print the name of this function # END OF CONTEXT print("my_func") # END OF SOLUTION def check(candidate): import io import sys captured = io.StringIO() sys.stdout = captured candidate([], 0) sys.stdout = sys.__stdout__ # get the stdout fr...
def solution(s): # The argument s is a string. # Please do the following in order: # 1. Check whether the string has exactly 3 "a"s. If so, return True. # 2. Reverse the string s. # 3. Check if the string now has exactly 3 "a"s. If so, return True. # END OF CONTEXT # 1. Check whether the str...
def my_func(): a = 0 a += 4 # Please copy the line above three times, then return a. # END OF CONTEXT a += 4 a += 4 a += 4 return a # END OF SOLUTION def check(candidate): assert candidate() == 16 if __name__ == "__main__": check(my_func)
def my_func(): a = [1, 2, 3] # Please copy the line above, but with the variable name 'b' instead of 'a'. # END OF CONTEXT b = [1, 2, 3] # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source.strip().split("\n") # remove comment...
def my_func(): a = 0 # a = 0 # a += 1 # print(a===1) # Please write a corrected version of the commented line that has a syntax error # END OF CONTEXT print(a == 1) # END OF SOLUTION def check(candidate): import inspect source = inspect.getsource(candidate) lines = source....
def below_threshold(l: list, t: int): """Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False """ # Print the current time # END OF CONTEXT import time print(time.time()) # EN...
def my_func(): # Please print a number that is divisible by 7 # END OF CONTEXT print(14) # END OF SOLUTION def check(candidate): import io import sys captured = io.StringIO() sys.stdout = captured candidate() sys.stdout = sys.__stdout__ # get the stdout from the captured ...
def correct_bracketing(brackets: str): """ brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. >>> correct_bracketing("(") False >>> correct_bracketing("()") True >>> correct_bracketing("(()())") True >>> correct_bracketing(...
def car_race_collision(n: int): """ Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same spe...
from typing import List def concatenate(strings: List[str]) -> str: """ Concatenate list of strings into a single string >>> concatenate([]) '' >>> concatenate(['a', 'b', 'c']) 'abc' """ return ''.join(strings) METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candid...
def count_distinct_characters(string: str) -> int: """ Given a string, find out how many distinct characters (regardless of case) does it consist of >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4 """ return len(set(string.lower())) METADATA = { 'au...
def bf(planet1, planet2): ''' There are eight planets in our solar system: the closerst to the Sun is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, Uranus, Neptune. Write a function that takes two planet names as strings planet1 and planet2. The function should return a t...
def check_if_last_char_is_a_letter(txt): ''' Create a function that returns True if the last character of a given string is an alphabetical character and is not a part of a word, and False otherwise. Note: "word" is a group of characters separated by space. Examples: check_if_last_char_is_a...
def add(lst): """Given a non-empty list of integers lst. add the even elements that are at odd indices.. Examples: add([4, 2, 6, 7]) ==> 2 """ return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0]) def check(candidate): # Check some simple cases assert candidate([4, 8...
def any_int(x, y, z): ''' Create a function that takes 3 numbers. Returns true if the sum of any two numbers is equal to the third number, and all numbers are integers. Returns false in any other cases. Examples any_int(5, 2, 7) ➞ True any_int(3, 2, 2) ➞ False any_int(3, -2, 1...
def circular_shift(x, shift): """Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. >>> circular_shift(12, 1) "21" >>> circular_shift(12, 2) "12" """ s = str(x) if sh...
def closest_integer(value): ''' Create a function that takes a value (string) representing a number and returns the closest integer to it. If the number is equidistant from two integers, round it away from zero. Examples >>> closest_integer("10") 10 >>> closest_integer("15.3") 15 ...
def cycpattern_check(a , b): """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 cycpattern_check("abcd","abd") => False cycpattern_check("hello","ell") => True cycpattern_check("whassup","psus") => False cycpattern_check("aba...
from typing import List def below_zero(operations: List[int]) -> bool: """ You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that point function should return Tru...
def count_nums(arr): """ Write a function count_nums which takes an array of integers and returns the number of elements which has a sum of digits > 0. >>> count_nums([]) == 0 >>> count_nums([-1, 11, -11]) == 1 >>> count_nums([1, 1, 2]) == 3 """ def digits_sum(n): neg = 1 ...
def count_up_to(n): """Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: count_up_to(5) => [2,3] count_up_to(11) => [2,3,5,7] count_up_to(0) => [] count_up_to(20) => [2,3,5,7,11,13,15,17,1...
def count_upper(s): """ Given a string s, count the number of uppercase vowels in even indices. For example: count_upper('aBCdEf') returns 1 count_upper('abcdefg') returns 0 count_upper('dBBE') returns 0 """ count = 0 for i in range(0,len(s),2): if s[i] in "AEIOU": ...
def choose_num(x, y): """This function takes two positive numbers x and y and returns the biggest even integer number that is in the range [x, y] inclusive. If there's no such number, then the function should return -1. For example: choose_num(12, 15) = 14 choose_num(13, 12) = -1 """ ...
def below_threshold(l: list, t: int): """Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False """ for e in l: if e >= t: return False return True METADATA = {} d...
def add_elements(arr, k): """ Given a non-empty array of integers arr and an integer k, return the sum of the first k element that has at most two digits. Example: Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4 Output: 24 # sum of 21 + 3 Constraints: 1. 1 <= len(arr) <= 100...
def compare_one(a, b): """ Create a function that takes integer, float or string, reprepresenting a real numbers, and returns the larger variable in a given variable type. Return None if the values are equal. Note: if float represented as a string, the floating point might be . or , compare_one...
def change_base(x: int, base: int): """Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10. >>> change_base(8, 3) '22' >>> change_base(8, 2) '1000' >>> change_base(7, 2) '111' """ ret = "" whil...
def common(l1: list, l2: list): """Return sorted unique common elements for two lists. >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) [1, 5, 653] >>> common([5, 3, 2, 8], [3, 2]) [2, 3] """ ret = set() for e1 in l1: for e2 in l2: if e1 == e2: ...
from typing import List def all_prefixes(string: str) -> List[str]: """ Return list of all prefixes from shortest to longest of the input string >>> all_prefixes('abc') ['a', 'ab', 'abc'] """ result = [] for i in range(len(string)): result.append(string[:i+1]) return result ME...
def can_arange(arr): """Create a function which returns the index of the element such that after removing that element the remaining array is itself sorted in ascending order. If the given array is already sorted in ascending order then return -1. Note: It is guaranteed that the array arr will either b...
def by_length(arr): """ Given an array of integers, if the number is an integer between 1 and 9 inclusive, replace it by its corresponding name from "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", otherwise remove it, then sort the array and return a reverse of sorted array. ...
def compare(game,guess): """I think we all remember that feeling when the result of some long-awaited event is finally known. The feelings and thoughts you have at that moment are definitely worth noting down and comparing. Your task is to compare if a person guessed correctly the results of the matches...
def anti_shuffle(s): """ Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where all the characters arranged in ascending order based on ascii value. Note: You should k...
def check_dict_case(dict): """ Given a dictionary, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given dictionary is empty. Examples: check_dict_case({"a":"apple", "b":"banana"}) should return T...
# [PROMPT] def correct_bracketing(brackets: str): """brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. >>> correct_bracketing("(") False >>> correct_bracketing("()") True >>> correct_bracketing("(()())") True >>> correct...
# [PROMPT] def car_race_collision(n: int): """ Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in...
# [PROMPT] from typing import List def concatenate(strings: List[str]) -> str: """Concatenate list of strings into a single string >>> concatenate([]) '' >>> concatenate(['a', 'b', 'c']) 'abc' """ # [SOLUTION] return ",".join(strings) # [CHECK] def check(candidate): assert cand...
# [PROMPT] def count_distinct_characters(string: str) -> int: """Given a string, find out how many distinct characters (regardless of case) does it consist of >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4 """ # [SOLUTION] return len(set(string).low...
# [PROMPT] def bf(planet1, planet2): """ There are eight planets in our solar system: the closerst to the Sun is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, Uranus, Neptune. Write a function that takes two planet names as strings planet1 and planet2. The function should ...
# [PROMPT] def check_if_last_char_is_a_letter(txt): """ Create a function that returns True if the last character of a given string is an alphabetical character and is not a part of a word, and False otherwise. Note: "word" is a group of characters separated by space. Examples: check_if_l...
# [PROMPT] def add(lst): """Given a non-empty list of integers lst. add the even elements that are at odd indices.. Examples: add([4, 2, 6, 7]) ==> 2 """ # [SOLUTION] return sum([lst[i] for i in range(1, len(lst) / 2, 2) if lst[i] % 2 == 0]) # [CHECK] def check(candidate): # Chec...
ENTRY_POINT = "any_int" # [PROMPT] def any_int(x, y, z): """ Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. Returns false in any other cases. Examples any_int(5, 2, 7) ➞ True any_int(3, 2, 2) ...
# [PROMPT] def circular_shift(x, shift): """Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. >>> circular_shift(12, 1) "21" >>> circular_shift(12, 2) "12" """ # [SOLUT...
# [PROMPT] def closest_integer(value): """ Create a function that takes a value (string) representing a number and returns the closest integer to it. If the number is equidistant from two integers, round it away from zero. Examples >>> closest_integer("10") 10 >>> closest_integer("15....
# [PROMPT] def cycpattern_check(a, b): """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 cycpattern_check("abcd","abd") => False cycpattern_check("hello","ell") => True cycpattern_check("whassup","psus") => False cycpatter...
# [PROMPT] from typing import List def below_zero(operations: List[int]) -> bool: """You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that point function should...
ENTRY_POINT = "count_nums" # [PROMPT] def count_nums(arr): """ Write a function count_nums which takes an array of integers and returns the number of elements which has a sum of digits > 0. If a number is negative, then its first signed digit will be negative: e.g. -123 has signed digits -1, 2, an...
# [PROMPT] def count_up_to(n): """Implement a function that takes an non-negative integer and returns an array of the first n integers that are prime numbers and less than n. for example: count_up_to(5) => [2,3] count_up_to(11) => [2,3,5,7] count_up_to(0) => [] count_up_to(20) => [2,3,5,7,1...
# [PROMPT] def count_upper(s): """ Given a string s, count the number of uppercase vowels in even indices. For example: count_upper('aBCdEf') returns 1 count_upper('abcdefg') returns 0 count_upper('dBBE') returns 0 """ # [SOLUTION] count = 0 for i in range(0, len(s), 2): ...
# [PROMPT] def choose_num(x, y): """This function takes two positive numbers x and y and returns the biggest even integer number that is in the range [x, y] inclusive. If there's no such number, then the function should return -1. For example: choose_num(12, 15) = 14 choose_num(13, 12) = -1 ...
# [PROMPT] def below_threshold(l: list, t: int): """Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False """ # [SOLUTION] for e in l: if e >= t: break return Tr...
# [PROMPT] def add_elements(arr, k): """ Given a non-empty array of integers arr and an integer k, return the sum of the first k element that has at most two digits. Example: Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4 Output: 24 # sum of 21 + 3 Constraints: 1. 1 <= len(...
ENTRY_POINT = "compare_one" # [PROMPT] def compare_one(a, b): """ Create a function that takes integers, floats, or strings representing real numbers, and returns the larger variable in its given variable type. Return None if the values are equal. Note: If a real number is represented as a string,...
# [PROMPT] def change_base(x: int, base: int): """Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10. >>> change_base(8, 3) '22' >>> change_base(8, 2) '1000' >>> change_base(7, 2) '111' """ # [SO...
# [PROMPT] def common(l1: list, l2: list): """Return sorted unique common elements for two lists. >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) [1, 5, 653] >>> common([5, 3, 2, 8], [3, 2]) [2, 3] """ # [SOLUTION] ret = set() for e1 in l1: for e2 in l1: ...
# [PROMPT] from typing import List def all_prefixes(string: str) -> List[str]: """Return list of all prefixes from shortest to longest of the input string >>> all_prefixes('abc') ['a', 'ab', 'abc'] """ # [SOLUTION] result = [] for i in range(len(string)): result.append(string[:i...
ENTRY_POINT = "can_arrange" FIX = """ Fixed typo arange -> arrange Remove semicolon from solution """ # [PROMPT] def can_arrange(arr): """Create a function which returns the index of the element such that after removing that element the remaining array is itself sorted in ascending order. If the given ar...
# [PROMPT] def by_length(arr): """ Given an array of integers, if the number is an integer between 1 and 9 inclusive, replace it by its corresponding name from "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", otherwise remove it, then sort the array and return a reverse of sorte...
ENTRY_POINT = "compare" # [PROMPT] def compare(game, guess): """I think we all remember that feeling when the result of some long-awaited event is finally known. The feelings and thoughts you have at that moment are definitely worth noting down and comparing. Your task is to determine if a person corr...
# [PROMPT] def anti_shuffle(s): """ Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where all the characters arranged in ascending order based on ascii value. Note:...
# [PROMPT] def check_dict_case(dict): """ Given a dictionary, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given dictionary is empty. Examples: check_dict_case({"a":"apple", "b":"banana"}) sh...