Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringclasses
164 values
prompt
stringclasses
164 values
completion
stringlengths
32
6.93k
HumanEval/0
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: """ Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, ...
for i in range(len(numbers) - 1): if abs(numbers[i] - numbers[i + 1]) <= threshold: return True return False def find_close_elements(numbers: List[float], threshold: float) -> List[int]: """ Find all the indices of the numbers in the list that are closer to each other than the give...
HumanEval/0
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: """ Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, ...
for i in range(len(numbers) - 1): if abs(numbers[i] - numbers[i + 1]) <= threshold: return True return False
HumanEval/0
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: """ Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, ...
for i in range(len(numbers)): for j in range(i + 1, len(numbers)): if abs(numbers[i] - numbers[j]) <= threshold: return True return False if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/0
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: """ Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, ...
for i in range(len(numbers) - 1): if (numbers[i] - numbers[i + 1]) <= threshold: return True return False
HumanEval/0
from typing import List def has_close_elements(numbers: List[float], threshold: float) -> bool: """ Check if in given list of numbers, are any two numbers closer to each other than given threshold. >>> has_close_elements([1.0, 2.0, 3.0], 0.5) False >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, ...
for i in range(len(numbers)): for j in range(i + 1, len(numbers)): if abs(numbers[i] - numbers[j]) < threshold: return True return False
HumanEval/1
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. Separate groups are balanced (each open brace...
paren_list = [] for paren in paren_string: if paren == '(': paren_list.append('(') elif paren == ')': if paren_list[-1] == '(': paren_list.pop() else: paren_list.append(')') return paren_list if __name__ == '__main__': ...
HumanEval/1
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. Separate groups are balanced (each open brace...
paren_list = [] for char in paren_string: if char == '(': paren_list.append('(') elif char == ')': if len(paren_list) > 0: paren_list.pop() else: paren_list.append(')') return paren_list if __name__ == '__main__': impo...
HumanEval/1
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. Separate groups are balanced (each open brace...
paren_list = [] for char in paren_string: if char == '(': paren_list.append('(') elif char == ')': if len(paren_list) > 0 and paren_list[-1] == '(': paren_list.pop() else: paren_list.append(')') return paren_list
HumanEval/1
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. Separate groups are balanced (each open brace...
paren_list = paren_string.split() result = [] for p in paren_list: if p[0] == '(': result.append(p) else: result[-1] += p return result def remove_duplicate_letters(word: str) -> str: """ >>> remove_duplicate_letters('abcd') 'abcd' >>> remove_dup...
HumanEval/1
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. Separate groups are balanced (each open brace...
paren_stack = [] result = [] for char in paren_string: if char == '(': paren_stack.append('(') elif char == ')': if len(paren_stack) > 0: paren_stack.pop() else: paren_stack.append(')') elif char == ' ': ...
HumanEval/2
def truncate_number(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the decimal part of the number. >>> truncate_number(3.5) 0...
if number == 0: return 0 if number < 0: return -1 if number > 0: return 1 def truncate_decimal(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftov...
HumanEval/2
def truncate_number(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the decimal part of the number. >>> truncate_number(3.5) 0...
# TODO: Complete this function return 0 if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/2
def truncate_number(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the decimal part of the number. >>> truncate_number(3.5) 0...
return number - int(number) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/2
def truncate_number(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the decimal part of the number. >>> truncate_number(3.5) 0...
# TODO: complete this function if number < 1: return 0 else: return number - int(number) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/2
def truncate_number(number: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). Return the decimal part of the number. >>> truncate_number(3.5) 0...
if number == 0: return 0 else: return int(number * 10) / 10 def truncate_decimal(decimal: float) -> float: """ Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller th...
HumanEval/3
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...
for i in range(len(operations)): if operations[i] < 0: if i == len(operations) - 1: return True else: return False return False if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/3
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...
for i in range(1, len(operations)): if operations[i] < 0: return True return False if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/3
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...
for i in range(1, len(operations)): if operations[i] > 0: if operations[i - 1] + operations[i] < 0: return True return False if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/3
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...
for i in range(1, len(operations)): if operations[i] + operations[i-1] < 0: return True return False if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/3
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...
balance = 0 for op in operations: if op < 0: balance = balance + op else: balance = balance - op if balance < 0: return True else: return False def above_zero(operations: List[int]) -> bool: """ You're given a list of deposit and withdrawal o...
HumanEval/4
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 each element and a centerpoint (mean in this ...
return sum([abs(x - mean(numbers)) for x in numbers]) / len(numbers) def mean_absolute_deviation_2(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 betwee...
HumanEval/4
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 each element and a centerpoint (mean in this ...
mean = sum(numbers) / len(numbers) return sum( abs(x - mean) for x in numbers ) / len(numbers)
HumanEval/4
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 each element and a centerpoint (mean in this ...
# Calculate the mean mean = sum(numbers) / len(numbers) # Calculate the absolute difference absolute_differences = [] for number in numbers: absolute_difference = abs(number - mean) absolute_differences.append(absolute_difference) # Calculate the mean of the absolute difference...
HumanEval/4
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 each element and a centerpoint (mean in this ...
n = len(numbers) if n == 0: return 0 else: return sum([abs(x - sum(numbers)/n) for x in numbers]) / n
HumanEval/4
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 each element and a centerpoint (mean in this ...
# Calculate the mean mean = sum(numbers) / len(numbers) # Calculate the deviation deviations = [] for number in numbers: deviations.append(number - mean) # Calculate the mean of the deviations mean_deviation = sum(deviations) / len(deviations) # Calculate the absolute deviatio...
HumanEval/5
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if len(numbers) < 2: return numbers else: return numbers[:2] + [delimeter] + intersperse([delimeter] + numbers[2:-1], delimeter) + numbers[-1:] if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/5
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if len(numbers) == 0: return [] if len(numbers) == 1: return numbers if len(numbers) == 2: return [numbers[0]] + [delimeter] + [numbers[1]] if len(numbers) == 3: return [numbers[0]] + [delimeter] + [numbers[1]] + [delimeter] + [numbers[2]] if len(numbers) == 4: ...
HumanEval/5
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if len(numbers) < 2: return numbers else: result = [] for i in range(len(numbers)): if i == 0: result.append(numbers[0]) elif i == len(numbers) - 1: result.append(numbers[-1]) else: result.append(numbers[...
HumanEval/5
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if not numbers: return [] if len(numbers) == 1: return [numbers[0], delimeter] return [numbers[0]] + intersperse(numbers[1:], delimeter) + [numbers[-1]] if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/5
from typing import List def intersperse(numbers: List[int], delimeter: int) -> List[int]: """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers' >>> intersperse([], 4) [] >>> intersperse([1, 2, 3], 4) [1, 4, 2, 4, 3] """
if len(numbers) < 2: return numbers else: return numbers[:2] + [delimeter] + intersperse([delimeter] + numbers[2:-1], delimeter) + numbers[-1:]
HumanEval/6
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of n...
# Your code here return []
HumanEval/6
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of n...
# TODO: Write your code here return []
HumanEval/6
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of n...
# TODO: Write your code here return [] if __name__ == '__main__': # print("Example:") # print(parse_paren('((()()))')) # # Put three example test cases here (for your sanity, limit your inputs # to be only the ones below) # print("Example tests:") # print(parse_paren("((((((()))))))")...
HumanEval/6
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of n...
# TODO: Write your code here return []
HumanEval/6
from typing import List def parse_nested_parens(paren_string: str) -> List[int]: """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of n...
# your code here return []
HumanEval/7
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', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'...
return list(filter(lambda x: x.find(substring) != -1, strings)) def filter_by_substring_2(strings: List[str], substring: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> filter_by_substring_2([], 'a') [] >>> filter_by_substring_2(['abc', 'bacd',...
HumanEval/7
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', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'...
return list(filter(lambda x: x.find(substring) != -1, strings)) def filter_by_substring_2(strings: List[str], substring: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> filter_by_substring_2([], 'a') [] >>> filter_by_substring_2(['abc', 'bacd',...
HumanEval/7
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', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'...
return list(filter(lambda x: x.find(substring) != -1, strings)) def filter_by_substring_2(strings: List[str], substring: str) -> List[str]: """ Filter an input list of strings only for ones that contain given substring >>> filter_by_substring_2([], 'a') [] >>> filter_by_substring_2(['abc', 'bacd',...
HumanEval/7
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', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'...
return list(filter(lambda x: x.find(substring) != -1, strings)) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/7
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', 'cde', 'array'], 'a') ['abc', 'bacd', 'array'...
return list(filter(lambda x: substring in x, strings)) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/8
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. >>> sum_product([]) (0, 1) ...
sum = 0 product = 1 for i in numbers: sum += i product *= i return (sum, product)
HumanEval/8
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. >>> sum_product([]) (0, 1) ...
sum = 0 product = 1 for i in range(len(numbers)): sum += numbers[i] product *= numbers[i] return (sum, product) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/8
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. >>> sum_product([]) (0, 1) ...
if not numbers: return (0, 1) else: return (numbers[0], numbers[0] * sum(numbers[1:])) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/8
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. >>> sum_product([]) (0, 1) ...
if len(numbers) == 0: return (0, 1) else: return (sum(numbers), numbers[0] * sum(numbers[1:])) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/8
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. >>> sum_product([]) (0, 1) ...
sum = 0 product = 1 for i in range(len(numbers)): sum += numbers[i] product *= numbers[i] return (sum, product) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/9
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
max_list = [] for i in range(len(numbers)): max_list.append(max(numbers[i:])) return max_list def rolling_min(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling minimum element found until given moment in the sequence. >>> rolling_min([1, 2,...
HumanEval/9
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
max_list = [] for i in range(len(numbers)): max_list.append(max(numbers[i:])) return max_list def rolling_min(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling minimum element found until given moment in the sequence. >>> rolling_min([1, 2,...
HumanEval/9
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
max_list = [] for i in range(len(numbers)): max_list.append(max(numbers[i:])) return max_list def rolling_max_with_index(numbers: List[int]) -> Tuple[List[int], List[int]]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequenc...
HumanEval/9
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
max_list = [] for i in range(len(numbers)): max_list.append(max(numbers[i:])) return max_list def rolling_min(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling minimum element found until given moment in the sequence. >>> rolling_min([1, 2, ...
HumanEval/9
from typing import List, Tuple def rolling_max(numbers: List[int]) -> List[int]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) [1, 2, 3, 3, 3, 4, 4] """
max_list = [] for i in range(len(numbers)): max_list.append(max(numbers[i:])) return max_list def rolling_max_with_index(numbers: List[int]) -> List[Tuple[int, int]]: """ From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. ...
HumanEval/10
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] def make_palindrome(string: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string...
# if string is empty if not string: return '' # find the longest palindromic prefix # that is also a suffix # of the supplied string # and return the reversed # string # # if not a palindrome # return the original string # # if a palindrome # return the rever...
HumanEval/10
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] def make_palindrome(string: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string...
# Check if the input string is empty if not string: return '' # Find the longest palindromic prefix # of the string # (i.e., the longest prefix that is a palindrome) # and return the reversed string # (i.e., the prefix reversed) # # Note: This is a very simple and naive ...
HumanEval/10
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] def make_palindrome(string: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string...
if not is_palindrome(string): return None # Find the longest palindrome longest = '' for i in range(len(string)): suffix = string[i:] if is_palindrome(suffix): longest = suffix # Append the reversed prefix to the end of the string return string + reverse(longe...
HumanEval/10
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] def make_palindrome(string: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string...
if not is_palindrome(string): return string # Find the longest prefix of the string that is a palindrome # (i.e., the prefix of the string that is the same forwards and backwards) # and return the prefix + the reversed suffix # (i.e., the reversed prefix + the reversed suffix) # # N...
HumanEval/10
def is_palindrome(string: str) -> bool: """ Test if given string is a palindrome """ return string == string[::-1] def make_palindrome(string: str) -> str: """ Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string...
# Find the longest palindromic prefix # for example, for 'cat' the longest prefix is 'cat' # the longest prefix is 'cat' # the longest prefix is 'cat' # the longest prefix is 'cat' # the longest prefix is 'cat' # the longest prefix is 'cat' # the longest prefix is 'cat' # the longest...
HumanEval/11
from typing import List def string_xor(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> string_xor('010', '110') '100' """
return ''.join([str((int(a) + int(b)) % 2) for a, b in zip(a, b)]) def string_xor_pythonic(a: str, b: str) -> str: return ''.join(chr(ord(a) ^ ord(b)) for a, b in zip(*[iter(a), iter(b)])) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/11
from typing import List def string_xor(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> string_xor('010', '110') '100' """
return ''.join([str((int(x) + int(y)) % 2) for x, y in zip(a, b)]) def find_xor_key(cipher: str, key: str) -> int: """ Find the key by XORing the cipher with the key >>> find_xor_key('1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736', 'abc') 3 """ return sum([int(x) * i...
HumanEval/11
from typing import List def string_xor(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> string_xor('010', '110') '100' """
return "".join(["1" if a == b else "0" for a, b in zip(a, b)]) def string_xor_v2(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result as a string. >>> string_xor_v2('010', '110') '100' """ return "".joi...
HumanEval/11
from typing import List def string_xor(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> string_xor('010', '110') '100' """
return ''.join(['1' if a != b else '0' for a, b in zip(a, b)]) def find_strings(s: str, sub_strs: List[str]) -> List[str]: """ Input: - s: string - sub_strs: a list of strings Output: - a list of all the substrings of s """ # Your code here return [s[i:j] for i in range(len(s))...
HumanEval/11
from typing import List def string_xor(a: str, b: str) -> str: """ Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. >>> string_xor('010', '110') '100' """
return "".join([str((int(a) + int(b)) % 2) for a, b in zip(a, b)]) def find_strings(arr: List[str], sub_str: str) -> List[str]: """ Find all the substrings of the given string that are a permutation of the other strings >>> find_strings(["abcd", "abcd", "abcd"], "abcd") ['abcd', 'abcd', 'abcd'...
HumanEval/12
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest([]) >>> longest(['a', 'b', 'c']) 'a...
if len(strings) == 0: return None max_len = 0 max_str = None for string in strings: if len(string) > max_len: max_str = string max_len = len(string) return max_str if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/12
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest([]) >>> longest(['a', 'b', 'c']) 'a...
if len(strings) == 0: return None longest_string = strings[0] for string in strings: if len(string) > len(longest_string): longest_string = string return longest_string if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/12
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest([]) >>> longest(['a', 'b', 'c']) 'a...
if len(strings) == 0: return None longest_string = strings[0] for string in strings: if len(string) > len(longest_string): longest_string = string return longest_string
HumanEval/12
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest([]) >>> longest(['a', 'b', 'c']) 'a...
if len(strings) == 0: return None else: return max(strings, key=len) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/12
from typing import List, Optional def longest(strings: List[str]) -> Optional[str]: """ Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. >>> longest([]) >>> longest(['a', 'b', 'c']) 'a...
if len(strings) == 0: return None else: return max(strings, key=len) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/13
def greatest_common_divisor(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5 """
while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/13
def greatest_common_divisor(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5 """
while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b def least_common_multiple(a: int, b: int) -> int: """ Return the least common multiple of two integers >>> least_common_multiple(3, 5) 15 >>> least_common_multiple(25, 15) 75 ...
HumanEval/13
def greatest_common_divisor(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5 """
while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b def least_common_multiple(a: int, b: int) -> int: """ Return the least common multiple of two integers a and b >>> least_common_multiple(3, 5) 15 >>> least_common_multiple(25, 15) ...
HumanEval/13
def greatest_common_divisor(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5 """
while a != 0 and b != 0: if a > b: a = a % b else: b = b % a return a + b if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/13
def greatest_common_divisor(a: int, b: int) -> int: """ Return a greatest common divisor of two integers a and b >>> greatest_common_divisor(3, 5) 1 >>> greatest_common_divisor(25, 15) 5 """
# Base case if a == 0 or b == 0: return 0 # Check if a is the largest if a > b: return greatest_common_divisor(a-b, b) # Check if b is the largest return greatest_common_divisor(a, b-a) def smallest_common_divisor(a: int, b: int) -> int: """ Return the smallest common divis...
HumanEval/14
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'] """
prefix = [] for i in range(len(string)): prefix.append(string[:i+1]) return prefix def all_suffixes(string: str) -> List[str]: """ Return list of all suffixes from shortest to longest of the input string >>> all_suffixes('abc') ['bc', 'cab', 'cba'] """ suffix = [] for i in ...
HumanEval/14
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'] """
prefix = [] for i in range(len(string) + 1): prefix.append(string[:i]) return prefix def all_suffixes(string: str) -> List[str]: """ Return list of all suffixes from shortest to longest of the input string >>> all_suffixes('abc') ['bc', 'cba', 'cab', 'abc'] """ suffix = [] ...
HumanEval/14
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'] """
prefix = [] for i in range(len(string) + 1): prefix.append(string[:i]) return prefix def all_suffixes(string: str) -> List[str]: """ Return list of all suffixes from shortest to longest of the input string >>> all_suffixes('abc') ['bc', 'cab', 'cba'] """ suffix = [] for i in...
HumanEval/14
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'] """
prefix = [] for i in range(len(string) + 1): prefix.append(string[:i]) return prefix def all_suffixes(string: str) -> List[str]: """ Return list of all suffixes from longest to shortest of the input string >>> all_suffixes('abc') ['bc', 'cba'] """ suffix = [] for i in range...
HumanEval/14
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'] """
prefixes = [] for i in range(len(string) + 1): prefixes.append(string[:i]) return prefixes if __name__ == '__main__': import doctest doctest.testmod() # print(all_prefixes('abc')) # print(all_prefixes('abc')) # print(all_prefixes('abc')) # print(all_prefixes('abc')) # ...
HumanEval/15
def string_sequence(n: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5' """
return ' '.join(map(str, range(n + 1))) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/15
def string_sequence(n: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5' """
return ' '.join(map(str, range(n+1))) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/15
def string_sequence(n: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5' """
if n == 0: return '0' else: return f'{n} {string_sequence(n-1)}' if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/15
def string_sequence(n: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5' """
if n == 0: return '0' return f'{n} {string_sequence(n-1)}' if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/15
def string_sequence(n: int) -> str: """ Return a string containing space-delimited numbers starting from 0 upto n inclusive. >>> string_sequence(0) '0' >>> string_sequence(5) '0 1 2 3 4 5' """
if n < 0: raise ValueError if n == 0: return "0" return " ".join([str(i) for i in range(0, n + 1)]) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/16
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 """
if not isinstance(string, str): raise TypeError if len(string) == 0: return 0 if len(string) == 1: return 1 if len(string) == 2: return 2 if len(string) == 3: return 2 if len(string) == 4: return 3 if len(string) > 4: return 4 def...
HumanEval/16
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)) if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/16
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)) def count_distinct_characters_2(string: str) -> int: """ >>> count_distinct_characters('xyzXYZ') 3 >>> count_distinct_characters('Jerry') 4 """ return len(set([char.lower() for char in string])) if __name__ == '__main__': import doctest doctest.testmod...
HumanEval/16
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([char.lower() for char in string])) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/16
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 """
# Your code here return len(set(string)) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/17
from typing import List def parse_music(music_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: ...
return [4 if i == 4 else 2 if i == 2 else 1 for i in range(len(music_string))] if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/17
from typing import List def parse_music(music_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: ...
return [ 4 if i == 'o' else 2 if i == 'o|' else 1 for i in music_string ] if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/17
from typing import List def parse_music(music_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: ...
return [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
HumanEval/17
from typing import List def parse_music(music_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: ...
return [ 4 if c == 'o' else 2 if c == 'o|' else 1 if c == '.' else 1 for c in music_string ] def parse_notes(notes_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this ...
HumanEval/17
from typing import List def parse_music(music_string: str) -> List[int]: """ Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: ...
return [ 4 if c == 'o' else 2 if c == 'o|' else 1 if c == '.' else 2 for c in music_string ] if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/18
def how_many_times(string: str, substring: str) -> int: """ Find how many times a given substring can be found in the original string. Count overlaping cases. >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3 """
count = 0 for i in range(len(string) - len(substring) + 1): if string[i:i+len(substring)] == substring: count += 1 return count if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/18
def how_many_times(string: str, substring: str) -> int: """ Find how many times a given substring can be found in the original string. Count overlaping cases. >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3 """
count = 0 for i in range(len(string) - len(substring) + 1): if string[i:i+len(substring)] == substring: count += 1 return count if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/18
def how_many_times(string: str, substring: str) -> int: """ Find how many times a given substring can be found in the original string. Count overlaping cases. >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3 """
return len([i for i in range(len(string)-len(substring)+1) if string[i:i+len(substring)] == substring]) if __name__ == '__main__': import doctest doctest.testmod()
HumanEval/18
def how_many_times(string: str, substring: str) -> int: """ Find how many times a given substring can be found in the original string. Count overlaping cases. >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3 """
count = 0 for i in range(len(string) - len(substring) + 1): if string[i:i+len(substring)] == substring: count += 1 return count def find_longest_substring(string: str) -> str: """ Find the longest substring in a given string. >>> find_longest_substring('a') 'a' >>> find_...
HumanEval/18
def how_many_times(string: str, substring: str) -> int: """ Find how many times a given substring can be found in the original string. Count overlaping cases. >>> how_many_times('', 'a') 0 >>> how_many_times('aaa', 'a') 3 >>> how_many_times('aaaa', 'aa') 3 """
count = 0 for i in range(len(string) - len(substring) + 1): if string[i:i+len(substring)] == substring: count += 1 return count if __name__ == "__main__": import doctest doctest.testmod()
HumanEval/19
from typing import List def sort_numbers(numbers: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >...
numbers = numbers.split() numbers = list(map(int, numbers)) numbers.sort() numbers = list(map(str, numbers)) numbers = " ".join(numbers) return numbers if __name__ == '__main__': numbers = input("Enter a space-delimited list of numbers: ") print(sort_numbers(numbers))
HumanEval/19
from typing import List def sort_numbers(numbers: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >...
numbers = numbers.split() numbers.sort() return " ".join(numbers) def sort_strings(strings: str) -> str: """ Input is a space-delimited string of lowercase alphabetic strings. Valid choices are 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',...
HumanEval/19
from typing import List def sort_numbers(numbers: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >...
numbers = numbers.split() numbers = list(map(int, numbers)) numbers.sort() return ' '.join(map(str, numbers)) def sort_strings(strings: str) -> str: """ Input is a space-delimited string of lowercase alphabetic characters. Return the string sorted in alphabetical order >>> sort_strings('ab...
HumanEval/19
from typing import List def sort_numbers(numbers: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >...
numbers = numbers.split() numbers.sort() return ' '.join(numbers) def sort_strings(strings: str) -> str: """ Input is a space-delimited string of lower case alphabetic strings. Return the string with alphabetic strings sorted from smallest to largest >>> sort_strings('abc def') 'abc def' ...
HumanEval/19
from typing import List def sort_numbers(numbers: str) -> str: """ Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest >...
numbers_list = [] for i in range(len(numbers)): if numbers[i].isnumeric(): numbers_list.append(int(numbers[i])) numbers_list.sort() return ' '.join([str(i) for i in numbers_list]) if __name__ == '__main__': n = input() print(sort_numbers(n))
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
4