INSTRUCTION stringlengths 78 1.13k | RESPONSE stringlengths 36 906 | SOURCE stringclasses 2
values |
|---|---|---|
Write a Python function which follows this instruction: Given a positive integer n, you have to make a pile of n levels of stones. The first level has n stones. The number of stones in the next level is: - the next odd number if n is odd. - the next even number if n is even. Return the number of stones in each level i... |
def make_a_pile(n):
return [n + 2*i for i in range(n)] | HumanEval |
Write a Python function which follows this instruction: You will be given a string of words separated by commas or spaces. Your task is to split the string into words and return an array of the words. |
def words_string(s):
if not s:
return []
s_list = []
for letter in s:
if letter == ',':
s_list.append(' ')
else:
s_list.append(letter)
s_list = "".join(s_list)
return s_list.split() | HumanEval |
Write a Python function which follows this instruction: 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. |
def choose_num(x, y):
if x > y:
return -1
if y % 2 == 0:
return y
if x == y:
return -1
return y - 1 | HumanEval |
Write a Python function which follows this instruction: You are given two positive integers n and m, and your task is to compute the average of the integers from n through m (including n and m). Round the answer to the nearest integer and convert that to binary. If n is greater than m, return -1. |
def rounded_avg(n, m):
if m < n:
return -1
summation = 0
for i in range(n, m+1):
summation += i
return bin(round(summation/(m - n + 1))) | HumanEval |
Write a Python function which follows this instruction: 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. |
def unique_digits(x):
odd_digit_elements = []
for i in x:
if all (int(c) % 2 == 1 for c in str(i)):
odd_digit_elements.append(i)
return sorted(odd_digit_elements) | HumanEval |
Write a Python function which follows this instruction: Given an array of integers, sort the integers that are between 1 and 9 inclusive, reverse the resulting array, and then replace each digit by its corresponding name from "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine". |
def by_length(arr):
dic = {
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Nine",
}
sorted_arr = sorted(arr, reverse=True)
new_arr = []
for var in sorted_arr:
try:
... | HumanEval |
Write a Python function which follows this instruction: 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 multiplicat... |
def f(n):
ret = []
for i in range(1,n+1):
if i%2 == 0:
x = 1
for j in range(1,i+1): x *= j
ret += [x]
else:
x = 0
for j in range(1,i+1): x += j
ret += [x]
return ret | HumanEval |
Write a Python function which follows this instruction: Given a positive integer n, return a tuple that has the number of even and odd integer palindromes that fall within the range(1, n), inclusive. Note: 1. 1 <= n <= 10^3 2. returned tuple has the number of even and odd integer palindromes respectively. |
def even_odd_palindrome(n):
def is_palindrome(n):
return str(n) == str(n)[::-1]
even_palindrome_count = 0
odd_palindrome_count = 0
for i in range(1, n+1):
if i%2 == 1 and is_palindrome(i):
odd_palindrome_count += 1
elif i%2 == 0 and is_palindrome(i):
... | HumanEval |
Write a Python function which follows this instruction: 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 3. |
def count_nums(arr):
def digits_sum(n):
neg = 1
if n < 0: n, neg = -1 * n, -1
n = [int(i) for i in str(n)]
n[0] = n[0] * neg
return sum(n)
return len(list(filter(lambda x: x > 0, [digits_sum(i) for i in arr]))) | HumanEval |
Write a Python function which follows this instruction: We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The numbers in the array will be randomly ordered. Your task is to determine if it is possible to get an array sorted in non-decreasing order by performing the following operation on the given array:... |
def move_one_ball(arr):
if len(arr)==0:
return True
sorted_array=sorted(arr)
my_arr=[]
min_value=min(arr)
min_index=arr.index(min_value)
my_arr=arr[min_index:]+arr[0:min_index]
for i in range(len(arr)):
if my_arr[i]!=sorted_array[i]:
return False
return True | HumanEval |
Write a Python function which follows this instruction: In this problem, you will implement a function that takes two lists of numbers, and determines whether it is possible to perform an exchange of elements between them to make lst1 a list of only even numbers. There is no limit on the number of exchanged elements be... |
def exchange(lst1, lst2):
odd = 0
even = 0
for i in lst1:
if i%2 == 1:
odd += 1
for i in lst2:
if i%2 == 0:
even += 1
if even >= odd:
return "YES"
return "NO"
| HumanEval |
Write a Python function which follows this instruction: Given a string representing a space separated lowercase letters, return a dictionary of the letter with the most repetition and containing the corresponding count. If several letters have the same occurrence, return all of them. |
def histogram(test):
dict1={}
list1=test.split(" ")
t=0
for i in list1:
if(list1.count(i)>t) and i!='':
t=list1.count(i)
if t>0:
for i in list1:
if(list1.count(i)==t):
dict1[i]=t
return dict1 | HumanEval |
Write a Python function which follows this instruction: Task 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 then check if the result string is palindrome. A string is called palindrome if it reads the same backward as forward. You should return a tuple... |
def reverse_delete(s,c):
s = ''.join([char for char in s if char not in c])
return (s,s[::-1] == s) | HumanEval |
Write a Python function which follows this instruction: Given a list of strings, where each string consists of only digits, return a list. Each element i of the output should be "the number of odd elements in the string i of the input." where all the i's should be replaced by the number of odd digits in the i'th string... |
def odd_count(lst):
res = []
for arr in lst:
n = sum(int(d)%2==1 for d in arr)
res.append("the number of odd elements " + str(n) + "n the str"+ str(n) +"ng "+ str(n) +" of the "+ str(n) +"nput.")
return res | HumanEval |
Write a Python function which follows this instruction: Given an array of integers nums, find the minimum sum of any non-empty sub-array of nums. |
def minSubArraySum(nums):
max_sum = 0
s = 0
for num in nums:
s += -num
if (s < 0):
s = 0
max_sum = max(s, max_sum)
if max_sum == 0:
max_sum = max(-i for i in nums)
min_sum = -max_sum
return min_sum | HumanEval |
Write a Python function which follows this instruction: You are given a rectangular grid of wells. Each row represents a single well, and each 1 in a row represents a single unit of water. Each well has a corresponding bucket that can be used to extract water from it, and all buckets have the same capacity. Your task ... |
def max_fill(grid, capacity):
import math
return sum([math.ceil(sum(arr)/capacity) for arr in grid]) | HumanEval |
Write a Python function which follows this instruction: In this Kata, you have to sort an array of non-negative integers according to number of ones in their binary representation in ascending order. For similar number of ones, sort based on decimal value. |
def sort_array(arr):
return sorted(sorted(arr), key=lambda x: bin(x)[2:].count('1')) | HumanEval |
Write a Python function which follows this instruction: Given a string s and a natural number n, you have been tasked to implement a function that returns a list of all words from string s that contain exactly n consonants, in order these words appear in the string s. If the string s is empty then the function should r... | def select_words(s, n):
result = []
for word in s.split():
n_consonants = 0
for i in range(0, len(word)):
if word[i].lower() not in ["a","e","i","o","u"]:
n_consonants += 1
if n_consonants == n:
result.append(word)
return result
| HumanEval |
Write a Python function which follows this instruction: You are given a word. Your task is to find the closest vowel that stands between two consonants from the right side of the word (case sensitive). Vowels in the beginning and ending doesn't count. Return empty string if you didn't find any vowel met the above cond... |
def get_closest_vowel(word):
if len(word) < 3:
return ""
vowels = {"a", "e", "i", "o", "u", "A", "E", 'O', 'U', 'I'}
for i in range(len(word)-2, 0, -1):
if word[i] in vowels:
if (word[i+1] not in vowels) and (word[i-1] not in vowels):
return word[i]
return "... | HumanEval |
Write a Python function which follows this instruction: You are given a list of two strings, both strings consist of open parentheses '(' or close parentheses ')' only. Your job is to check if it is possible to concatenate the two strings in some order, that the resulting string will be good. A string S is considered ... |
def match_parens(lst):
def check(s):
val = 0
for i in s:
if i == '(':
val = val + 1
else:
val = val - 1
if val < 0:
return False
return True if val == 0 else False
S1 = lst[0] + lst[1]
S2 = lst[1] +... | HumanEval |
Write a Python function which follows this instruction: Given an array arr of integers and a positive integer k, return a sorted list of length k with the maximum k numbers in arr. Note: 1. The length of the array will be in the range of [1, 1000]. 2. The elements in the array will be in the range of [-1000, 1000]. 3... |
def maximum(arr, k):
if k == 0:
return []
arr.sort()
ans = arr[-k:]
return ans | HumanEval |
Write a Python function which follows this instruction: Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. |
def solution(lst):
return sum([x for idx, x in enumerate(lst) if idx%2==0 and x%2==1]) | HumanEval |
Write a Python function which follows this instruction: Given a non-empty array of integers arr and an integer k, return the sum of the elements with at most two digits from the first k elements of arr. Constraints: 1. 1 <= len(arr) <= 100 2. 1 <= k <= len(arr) |
def add_elements(arr, k):
return sum(elem for elem in arr[:k] if len(str(elem)) <= 2) | HumanEval |
Write a Python function which follows this instruction: 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. Then each term is obtained from t... |
def get_odd_collatz(n):
if n%2==0:
odd_collatz = []
else:
odd_collatz = [n]
while n > 1:
if n % 2 == 0:
n = n/2
else:
n = n*3 + 1
if n%2 == 1:
odd_collatz.append(int(n))
return sorted(odd_collatz) | HumanEval |
Write a Python function which follows this instruction: You have to write a function which validates a given date string and returns True if the date is valid otherwise False. The date is valid if all of the following rules are satisfied: 1. The date string is not empty. 2. The number of days is not less than 1 or high... |
def valid_date(date):
try:
date = date.strip()
month, day, year = date.split('-')
month, day, year = int(month), int(day), int(year)
if month < 1 or month > 12:
return False
if month in [1,3,5,7,8,10,12] and day < 1 or day > 31:
return False
i... | HumanEval |
Write a Python function which follows this instruction: Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the alphabet, ord('a') = 0, ord('b') ... |
def split_words(txt):
if " " in txt:
return txt.split()
elif "," in txt:
return txt.replace(',',' ').split()
else:
return len([i for i in txt if i.islower() and ord(i)%2 == 0]) | HumanEval |
Write a Python function which follows this instruction: Given a list of numbers, return whether or not they are sorted in ascending order. If list has more than 1 duplicate of the same number, return False. Assume no negative numbers and only integers. |
def is_sorted(lst):
count_digit = dict([(i, 0) for i in lst])
for i in lst:
count_digit[i]+=1
if any(count_digit[i] > 2 for i in lst):
return False
if all(lst[i-1] <= lst[i] for i in range(1, len(lst))):
return True
else:
return False
| HumanEval |
Write a Python function which follows this instruction: You are given two intervals, where each interval is a pair of integers. For example, interval = (start, end) = (1, 2). The given intervals are closed which means that the interval (start, end) includes both start and end. For each given interval, it is assumed tha... |
def intersection(interval1, interval2):
def is_prime(num):
if num == 1 or num == 0:
return False
if num == 2:
return True
for i in range(2, num):
if num%i == 0:
return False
return True
l = max(interval1[0], interval2[0])
... | HumanEval |
Write a Python function which follows this instruction: You are given an array arr of integers and you need to return sum of magnitudes of integers multiplied by product of all signs of each number in the array, represented by 1, -1 or 0. Note: return None for empty arr. |
def prod_signs(arr):
if not arr: return None
prod = 0 if 0 in arr else (-1) ** len(list(filter(lambda x: x < 0, arr)))
return prod * sum([abs(i) for i in arr]) | HumanEval |
Write a Python function which follows this instruction: 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 path of length k in the ... |
def minPath(grid, k):
n = len(grid)
val = n * n + 1
for i in range(n):
for j in range(n):
if grid[i][j] == 1:
temp = []
if i != 0:
temp.append(grid[i - 1][j])
if j != 0:
temp.append(grid[i][j - 1])
... | HumanEval |
Write a Python function which follows this instruction: Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in the last couple centuries. However, what people don't know is Tribonacci sequence. Tribonacci sequence is defined by the recurrence: tri(1) = 3 tri(n) = 1 + n / 2, if n is even. tri(n) =... |
def tri(n):
if n == 0:
return [1]
my_tri = [1, 3]
for i in range(2, n + 1):
if i % 2 == 0:
my_tri.append(i / 2 + 1)
else:
my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2)
return my_tri | HumanEval |
Write a Python function which follows this instruction: Given a positive integer n, return the product of the odd digits. Return 0 if all digits are even. |
def digits(n):
product = 1
odd_count = 0
for digit in str(n):
int_digit = int(digit)
if int_digit%2 == 1:
product= product*int_digit
odd_count+=1
if odd_count ==0:
return 0
else:
return product | HumanEval |
Write a Python function which follows this instruction: Create a function that takes a string as input which contains only square brackets. The function should return True if and only if there is a valid subsequence of brackets where at least one bracket in the subsequence is nested. |
def is_nested(string):
opening_bracket_index = []
closing_bracket_index = []
for i in range(len(string)):
if string[i] == '[':
opening_bracket_index.append(i)
else:
closing_bracket_index.append(i)
closing_bracket_index.reverse()
cnt = 0
i = 0
l = len(... | HumanEval |
Write a Python function which follows this instruction: You are given a list of numbers. You need to return the sum of squared numbers in the given list, round each element in the list to the upper int(Ceiling) first. |
def sum_squares(lst):
import math
squared = 0
for i in lst:
squared += math.ceil(i)**2
return squared | HumanEval |
Write a Python function which follows this instruction: 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. |
def check_if_last_char_is_a_letter(txt):
check = txt.split(' ')[-1]
return True if len(check) == 1 and (97 <= ord(check.lower()) <= 122) else False | HumanEval |
Write a Python function which follows this instruction: Create a function which returns the largest index of an element which is not greater than or equal to the element immediately preceding it. If no such element exists then return -1. The given array will not contain duplicate values. |
def can_arrange(arr):
ind=-1
i=1
while i<len(arr):
if arr[i]<arr[i-1]:
ind=i
i+=1
return ind | HumanEval |
Write a Python function which follows this instruction: Create a function that returns a tuple (a, b), where 'a' is the largest of negative integers, and 'b' is the smallest of positive integers in a list. If there is no negative or positive integers, return them as None. |
def largest_smallest_integers(lst):
smallest = list(filter(lambda x: x < 0, lst))
largest = list(filter(lambda x: x > 0, lst))
return (max(smallest) if smallest else None, min(largest) if largest else None) | HumanEval |
Write a Python function which follows this instruction: 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, the floating point might be . ... |
def compare_one(a, b):
temp_a, temp_b = a, b
if isinstance(temp_a, str): temp_a = temp_a.replace(',','.')
if isinstance(temp_b, str): temp_b = temp_b.replace(',','.')
if float(temp_a) == float(temp_b): return None
return a if float(temp_a) > float(temp_b) else b | HumanEval |
Write a Python function which follows this instruction: Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers |
def is_equal_to_sum_even(n):
return n%2 == 0 and n >= 8 | HumanEval |
Write a Python function which follows this instruction: The Brazilian factorial is defined as: brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! where n > 0 The function will receive an integer as input and should return the special factorial of this integer. |
def special_factorial(n):
fact_i = 1
special_fact = 1
for i in range(1, n+1):
fact_i *= i
special_fact *= fact_i
return special_fact | HumanEval |
Write a Python function which follows this instruction: 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 - |
def fix_spaces(text):
new_text = ""
i = 0
start, end = 0, 0
while i < len(text):
if text[i] == " ":
end += 1
else:
if end - start > 2:
new_text += "-"+text[i]
elif end - start > 0:
new_text += "_"*(end - start)+text[i]
... | HumanEval |
Write a Python function which follows this instruction: Create a function which takes a string representing a file's name, and returns 'Yes' if the the file's name is valid, and returns 'No' otherwise. A file's name is considered to be valid if and only if all the following conditions are met: - There should not be mor... |
def file_name_check(file_name):
suf = ['txt', 'exe', 'dll']
lst = file_name.split(sep='.')
if len(lst) != 2:
return 'No'
if not lst[1] in suf:
return 'No'
if len(lst[0]) == 0:
return 'No'
if not lst[0][0].isalpha():
return 'No'
t = len([x for x in lst[0] if x... | HumanEval |
Write a Python function which follows this instruction: " 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. The function will not ch... |
def sum_squares(lst):
result =[]
for i in range(len(lst)):
if i %3 == 0:
result.append(lst[i]**2)
elif i % 4 == 0 and i%3 != 0:
result.append(lst[i]**3)
else:
result.append(lst[i])
return sum(result) | HumanEval |
Write a Python function which follows this instruction: You are given a string representing a sentence, the sentence contains some words separated by a space, and you have to return a string that contains the words from the original sentence, whose lengths are prime numbers, the order of the words in the new string sh... |
def words_in_sentence(sentence):
new_lst = []
for word in sentence.split():
flg = 0
if len(word) == 1:
flg = 1
for i in range(2, len(word)):
if len(word)%i == 0:
flg = 1
if flg == 0 or len(word) == 2:
new_lst.append(word)
r... | HumanEval |
Write a Python function which follows this instruction: Your task is to implement a function that will simplify the expression x * n. The function returns True if x * n evaluates to a whole number and False otherwise. Both x and n, are string representation of a fraction, and have the following format, <numerator>/<den... |
def simplify(x, n):
a, b = x.split("/")
c, d = n.split("/")
numerator = int(a) * int(c)
denom = int(b) * int(d)
if (numerator/denom == int(numerator/denom)):
return True
return False | HumanEval |
Write a Python function which follows this instruction: Write a function which sorts the given list of integers in ascending order according to the sum of their digits. Note: if there are several items with similar sum of their digits, order them based on their index in original list. |
def order_by_points(nums):
def digits_sum(n):
neg = 1
if n < 0: n, neg = -1 * n, -1
n = [int(i) for i in str(n)]
n[0] = n[0] * neg
return sum(n)
return sorted(nums, key=digits_sum) | HumanEval |
Write a Python function which follows this instruction: Write a function that takes an array of numbers as input and returns the number of elements in the array that are greater than 10 and both first and last digits of a number are odd (1, 3, 5, 7, 9). |
def specialFilter(nums):
count = 0
for num in nums:
if num > 10:
odd_digits = (1, 3, 5, 7, 9)
number_as_string = str(num)
if int(number_as_string[0]) in odd_digits and int(number_as_string[-1]) in odd_digits:
count += 1
return count | HumanEval |
Write a Python function which follows this instruction: You are given a positive integer n. You have to create an integer array a of length n. For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1. Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, and a[i] + a[j] + a[k] is a multiple of 3. |
def get_max_triples(n):
A = [i*i - i + 1 for i in range(1,n+1)]
ans = []
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if (A[i]+A[j]+A[k])%3 == 0:
ans += [(A[i],A[j],A[k])]
return len(ans) | HumanEval |
Write a Python function which follows this instruction: 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 bf(planet1, planet2):
planet_names = ("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune")
if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2:
return ()
planet1_index = planet_names.index(planet1)
planet2_index = planet_names.index(... | HumanEval |
Write a Python function which follows this instruction: Write a function that accepts a list of strings as a parameter, deletes the strings that have odd lengths from it, and returns the resulted list with a sorted order, The list is always a list of strings and never an array of numbers, and it may contain duplicates.... |
def sorted_list_sum(lst):
lst.sort()
new_lst = []
for i in lst:
if len(i)%2 == 0:
new_lst.append(i)
return sorted(new_lst, key=len) | HumanEval |
Write a Python function which follows this instruction: A simple program which should return the value of x if n is a prime number and should return the value of y otherwise. |
def x_or_y(n, x, y):
if n == 1:
return y
for i in range(2, n):
if n % i == 0:
return y
break
else:
return x | HumanEval |
Write a Python function which follows this instruction: 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. If the input list is empty, return 0. |
def double_the_difference(lst):
return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)]) | HumanEval |
Write a Python function which follows this instruction: 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 correctly guessed the results ... |
def compare(game,guess):
return [abs(x-y) for x,y in zip(game,guess)] | HumanEval |
Write a Python function which follows this instruction: You will be given the name of a class (a string) and a list of extensions. The extensions are to be used to load additional classes to the class. The strength of the extension is as follows: Let CAP be the number of the uppercase letters in the extension's name, a... | def Strongest_Extension(class_name, extensions):
strong = extensions[0]
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()])
for s in extensions:
val = len([x for x in s if x.isalpha() and x.isupper()]) - len([x for ... | HumanEval |
Write a Python function which follows this instruction: 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 |
def cycpattern_check(a , b):
l = len(b)
pat = b + b
for i in range(len(a) - l + 1):
for j in range(l + 1):
if a[i:i+l] == pat[j:j+l]:
return True
return False | HumanEval |
Write a Python function which follows this instruction: Given an integer. return a tuple that has the number of even and odd digits respectively. |
def even_odd_count(num):
even_count = 0
odd_count = 0
for i in str(abs(num)):
if int(i)%2==0:
even_count +=1
else:
odd_count +=1
return (even_count, odd_count) | HumanEval |
Write a Python function which follows this instruction: Given a positive integer, obtain its roman numeral equivalent as a string, and return it in lowercase. Restrictions: 1 <= num <= 1000 |
def int_to_mini_roman(number):
num = [1, 4, 5, 9, 10, 40, 50, 90,
100, 400, 500, 900, 1000]
sym = ["I", "IV", "V", "IX", "X", "XL",
"L", "XC", "C", "CD", "D", "CM", "M"]
i = 12
res = ''
while number:
div = number // num[i]
number %= num[i]
whil... | HumanEval |
Write a Python function which follows this instruction: 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 degree. |
def right_angle_triangle(a, b, c):
return a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b | HumanEval |
Write a Python function which follows this instruction: Write a function that accepts a list of strings. The list contains different words. Return the word with maximum number of unique characters. If multiple strings have maximum number of unique characters, return the one which comes first in lexicographical order. |
def find_max(words):
return sorted(words, key = lambda x: (-len(set(x)), x))[0] | HumanEval |
Write a Python function which follows this instruction: 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, the number of carrots left after your... |
def eat(number, need, remaining):
if(need <= remaining):
return [ number + need , remaining-need ]
else:
return [ number + remaining , 0] | HumanEval |
Write a Python function which follows this instruction: Given two lists operator, and operand. The first list has basic algebra operations, and the second list is a list of integers. Use the two given lists to build the algebric expression and return the evaluation of this expression. The basic algebra operations: Ad... |
def do_algebra(operator, operand):
expression = str(operand[0])
for oprt, oprn in zip(operator, operand[1:]):
expression+= oprt + str(oprn)
return eval(expression) | HumanEval |
Write a Python function which follows this instruction: You are given a string s. if s[i] is a letter, reverse its case from lower to upper or vise versa, otherwise keep it as it is. If the string contains no letters, reverse the string. The function should return the resulted string. |
def solve(s):
flg = 0
idx = 0
new_str = list(s)
for i in s:
if i.isalpha():
new_str[idx] = i.swapcase()
flg = 1
idx += 1
s = ""
for i in new_str:
s += i
if flg == 0:
return s[len(s)::-1]
return s | HumanEval |
Write a Python function which follows this instruction: Given a string 'text', return its md5 hash equivalent string. If 'text' is an empty string, return None. |
def string_to_md5(text):
import hashlib
return hashlib.md5(text.encode('ascii')).hexdigest() if text else None | HumanEval |
Write a Python function which follows this instruction: Given two positive integers a and b, return the even digits between a and b, in ascending order. |
def generate_integers(a, b):
lower = max(2, min(a, b))
upper = min(8, max(a, b))
return [i for i in range(lower, upper+1) if i % 2 == 0] | HumanEval |
Write a Python function which follows this instruction: Write a function to find the shared elements from the given two lists. | def similar_elements(test_tup1, test_tup2):
res = tuple(set(test_tup1) & set(test_tup2))
return (res) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to identify non-prime numbers. | import math
def is_not_prime(n):
result = False
for i in range(2,int(math.sqrt(n)) + 1):
if n % i == 0:
result = True
return result | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find the n largest integers from a given list of numbers, returned in descending order. | import heapq as hq
def heap_queue_largest(nums,n):
largest_nums = hq.nlargest(n, nums)
return largest_nums | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check whether the two numbers differ at one bit position only or not. | def is_Power_Of_Two (x):
return x and (not(x & (x - 1)))
def differ_At_One_Bit_Pos(a,b):
return is_Power_Of_Two(a ^ b) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find all words which are at least 4 characters long in a string. | import re
def find_char_long(text):
return (re.findall(r"\b\w{4,}\b", text)) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find squares of individual elements in a list. | def square_nums(nums):
square_nums = list(map(lambda x: x ** 2, nums))
return square_nums | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to find the minimum number of rotations (greater than 0) required to get the same string. | def find_Rotations(str):
tmp = str + str
n = len(str)
for i in range(1,n + 1):
substring = tmp[i: i+n]
if (str == substring):
return i
return n | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to remove first and last occurrence of a given character from the string. | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to sort a given matrix in ascending order according to the sum of its rows. | def sort_matrix(M):
result = sorted(M, key=sum)
return result | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to find the volume of a triangular prism. | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise. | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return True
else:
return False | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function that returns the perimeter of a square given its side length as input. | def square_perimeter(a):
perimeter=4*a
return perimeter | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to remove characters from the first string which are present in the second string. | NO_OF_CHARS = 256
def str_to_list(string):
temp = []
for x in string:
temp.append(x)
return temp
def lst_to_string(List):
return ''.join(List)
def get_char_count_array(string):
count = [0] * NO_OF_CHARS
for i in string:
count[ord(i)] += 1
return count
def remove_dirty_chars(string, second_string):... | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find whether a given array of integers contains any duplicate element. | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to check if the given number is woodball or not. | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check if a given number is one less than twice its reverse. | def rev(num):
rev_num = 0
while (num > 0):
rev_num = (rev_num * 10 + num % 10)
num = num // 10
return rev_num
def check(n):
return (2 * rev(n) == n + 1) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to find the largest number that can be formed with the given list of digits. | def find_Max_Num(arr) :
n = len(arr)
arr.sort(reverse = True)
num = arr[0]
for i in range(1,n) :
num = num * 10 + arr[i]
return num | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check whether the given two integers have opposite sign or not. | def opposite_Signs(x,y):
return ((x ^ y) < 0); | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find the nth octagonal number. | def is_octagonal(n):
return 3 * n * n - 2 * n | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to count the number of substrings with the sum of digits equal to their length. | from collections import defaultdict
def count_Substrings(s):
n = len(s)
count,sum = 0,0
mp = defaultdict(lambda : 0)
mp[0] += 1
for i in range(n):
sum += ord(s[i]) - ord('0')
count += mp[sum - (i + 1)]
mp[sum - (i + 1)] += 1
return count | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to find smallest number in a list. | def smallest_num(xs):
return min(xs)
| mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find the maximum difference between available pairs in the given tuple list. | def max_difference(test_list):
temp = [abs(b - a) for a, b in test_list]
res = max(temp)
return (res) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to sort a list of tuples using the second value of each tuple. | def subject_marks(subjectmarks):
#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])
subjectmarks.sort(key = lambda x: x[1])
return subjectmarks | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to flatten a list and sum all of its elements. | def recursive_list_sum(data_list):
total = 0
for element in data_list:
if type(element) == type([]):
total = total + recursive_list_sum(element)
else:
total = total + element
return total | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to count the number of positive numbers in a list. | def pos_count(list):
pos_count= 0
for num in list:
if num >= 0:
pos_count += 1
return pos_count | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find the number of ways to partition a set of Bell numbers. | def bell_number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0] | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check whether the given array is monotonic or not. | def is_Monotonic(A):
return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or
all(A[i] >= A[i + 1] for i in range(len(A) - 1))) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to check whether a list contains the given sublist or not. | def is_sublist(l, s):
sub_set = False
if s == []:
sub_set = True
elif s == l:
sub_set = True
elif len(s) > len(l):
sub_set = False
else:
for i in range(len(l)):
if l[i] == s[0]:
n = 1
while (n < len(s)) and (l[i+n] == s[n]):
n += 1
if n == len(s):
sub_set = True
return sub_set | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find whether all the given tuples have equal length or not. | def find_equal_tuple(Input):
k = 0 if not Input else len(Input[0])
flag = 1
for tuple in Input:
if len(tuple) != k:
flag = 0
break
return flag
def get_equal(Input):
return find_equal_tuple(Input) == 1 | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to sort a list of elements. | def comb_sort(nums):
shrink_fact = 1.3
gaps = len(nums)
swapped = True
i = 0
while gaps > 1 or swapped:
gaps = int(float(gaps) / shrink_fact)
swapped = False
i = 0
while gaps + i < len(nums):
if nums[i] > nums[i+gaps]:
nums[i], nums[i+gaps]... | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check whether the given number can be represented as the difference of two squares or not. | def dif_Square(n):
if (n % 4 != 2):
return True
return False | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to check whether it follows the sequence given in the patterns array. | def is_samepatterns(colors, patterns):
if len(colors) != len(patterns):
return False
sdict = {}
pset = set()
sset = set()
for i in range(len(patterns)):
pset.add(patterns[i])
sset.add(colors[i])
if patterns[i] not in sdict.keys():
sdict[pattern... | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find tuples which have all elements divisible by k from the given list of tuples. | def find_tuples(test_list, K):
res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]
return res | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to find whether a number is divisible by 11. | def is_Diff(n):
return (n % 11 == 0) | mbpp_sanitized |
Write a Python function which follows this instruction: Write a python function to check whether the length of the word is odd or not. | def word_len(s):
s = s.split(' ')
for word in s:
if len(word)%2!=0:
return True
else:
return False | mbpp_sanitized |
Write a Python function which follows this instruction: Write a function to find the nth tetrahedral number. | def tetrahedral_number(n):
return (n * (n + 1) * (n + 2)) / 6 | mbpp_sanitized |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.