text stringlengths 297 1.47k |
|---|
You are an expert Python programmer, and here is your task: Write a function to find the smallest multiple of the first n numbers. Your code should pass these tests:
assert smallest_multiple(13)==360360
assert smallest_multiple(2)==2
assert smallest_multiple(1)==1
[BEGIN]
def smallest_multiple(n):
if (n<=2):
... |
You are an expert Python programmer, and here is your task: Write a function to combine two dictionaries by adding values for common keys. Your code should pass these tests:
assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300})
assert add_dict({'a': 5... |
You are an expert Python programmer, and here is your task: Write a python function to count the total unset bits from 1 to n. Your code should pass these tests:
assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17
[BEGIN]
def count_Unset_Bits(n) :
cnt = 0;
fo... |
You are an expert Python programmer, and here is your task: Write a function to return true if the given number is even else return false. Your code should pass these tests:
assert even_num(13.5)==False
assert even_num(0)==True
assert even_num(-9)==False
[BEGIN]
def even_num(x):
if x%2==0:
return True
else... |
You are an expert Python programmer, and here is your task: Write a python function to find the sum of squares of binomial co-efficients. Your code should pass these tests:
assert sum_of_square(4) == 70
assert sum_of_square(5) == 252
assert sum_of_square(2) == 6
[BEGIN]
def factorial(start,end):
res = 1
fo... |
You are an expert Python programmer, and here is your task: Write a function to extract year, month and date from a url by using regex. Your code should pass these tests:
assert extract_date("https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-nor... |
You are an expert Python programmer, and here is your task: Write a function to print the first n lucky numbers. Your code should pass these tests:
assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]
assert lucky_num(5)==[1, 3, 7, 9, 13]
assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]
[BEGIN]
def lucky_num(n... |
You are an expert Python programmer, and here is your task: Write a function to find the fixed point in the given array. Your code should pass these tests:
assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3
assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1
assert find_fixed_point([0, 2, 5, 8,... |
You are an expert Python programmer, and here is your task: Write a function to find the previous palindrome of a specified number. Your code should pass these tests:
assert previous_palindrome(99)==88
assert previous_palindrome(1221)==1111
assert previous_palindrome(120)==111
[BEGIN]
def previous_palindrome(num):
... |
You are an expert Python programmer, and here is your task: Write a function to validate a gregorian date. Your code should pass these tests:
assert check_date(11,11,2002)==True
assert check_date(13,11,2002)==False
assert check_date('11','11','2002')==True
[BEGIN]
import datetime
def check_date(m, d, y):
try:
... |
You are an expert Python programmer, and here is your task: Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm. Your code should pass these tests:
assert maximum_product( [12, 74, 9, 50, 61, 41])==225700
assert maximum_product([25, 35, 22, 85, 14, 65, 7... |
You are an expert Python programmer, and here is your task: Write a function to find ln, m lobb number. Your code should pass these tests:
assert int(lobb_num(5, 3)) == 35
assert int(lobb_num(3, 2)) == 5
assert int(lobb_num(4, 2)) == 20
[BEGIN]
def binomial_coeff(n, k):
C = [[0 for j in range(k + 1)]
for i in ... |
You are an expert Python programmer, and here is your task: Write a function to check for a number at the end of a string. Your code should pass these tests:
assert end_num('abcdef')==False
assert end_num('abcdef7')==True
assert end_num('abc')==False
[BEGIN]
import re
def end_num(string):
text = re.compile(r".*[... |
You are an expert Python programmer, and here is your task: Write a python function to check whether the given string is made up of two alternating characters or not. Your code should pass these tests:
assert is_Two_Alter("abab") == True
assert is_Two_Alter("aaaa") == False
assert is_Two_Alter("xyz") == False
[BEGIN]
... |
You are an expert Python programmer, and here is your task: Write a function to rearrange positive and negative numbers in a given array using lambda function. Your code should pass these tests:
assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]
assert rearrange_numbs([10,15,14,13,-18,1... |
You are an expert Python programmer, and here is your task: Write a function to find if there is a triplet in the array whose sum is equal to a given value. Your code should pass these tests:
assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)
assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (... |
You are an expert Python programmer, and here is your task: Write a function to find the sequences of one upper case letter followed by lower case letters. Your code should pass these tests:
assert text_uppercase_lowercase("AaBbGg")==('Found a match!')
assert text_uppercase_lowercase("aA")==('Not matched!')
assert tex... |
You are an expert Python programmer, and here is your task: Write a function to count coin change. Your code should pass these tests:
assert coin_change([1, 2, 3],3,4)==4
assert coin_change([4,5,6,7,8,9],6,9)==2
assert coin_change([4,5,6,7,8,9],6,4)==1
[BEGIN]
def coin_change(S, m, n):
table = [[0 for x in range... |
You are an expert Python programmer, and here is your task: Write a python function to multiply all items in the list. Your code should pass these tests:
assert multiply_list([1,-2,3]) == -6
assert multiply_list([1,2,3,4]) == 24
assert multiply_list([3,1,2,3]) == 18
[BEGIN]
def multiply_list(items):
tot = 1
... |
You are an expert Python programmer, and here is your task: Write a function to remove all tuples with all none values in the given tuple list. Your code should pass these tests:
assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'
assert remove_tuple([(None, Non... |
You are an expert Python programmer, and here is your task: Write a function to perform chunking of tuples each of size n. Your code should pass these tests:
assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]
assert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4)... |
You are an expert Python programmer, and here is your task: Write a function to find a pair with the highest product from a given array of integers. Your code should pass these tests:
assert max_product([1, 2, 3, 4, 7, 0, 8, 4])==(7, 8)
assert max_product([0, -1, -2, -4, 5, 0, -6])==(-4, -6)
assert max_product([1, 3, ... |
You are an expert Python programmer, and here is your task: Write a function to find the length of the shortest string that has both str1 and str2 as subsequences. Your code should pass these tests:
assert super_seq("AGGTAB", "GXTXAYB", 6, 7) == 9
assert super_seq("feek", "eke", 4, 3) == 5
assert super_seq("PARRT", "R... |
You are an expert Python programmer, and here is your task: Write a function to find maximum of two numbers. Your code should pass these tests:
assert max_of_two(10,20)==20
assert max_of_two(19,15)==19
assert max_of_two(-10,-20)==-10
[BEGIN]
def max_of_two( x, y ):
if x > y:
return x
return y
[DONE] |
You are an expert Python programmer, and here is your task: Write a python function to calculate the product of all the numbers of a given tuple. Your code should pass these tests:
assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864
assert mutiple_tuple((1,2,3)) == 6
assert mutiple_tuple((-2,-4,-6)) == -48
[BEGIN]
def ... |
You are an expert Python programmer, and here is your task: Write a function to find n-th rencontres number. Your code should pass these tests:
assert rencontres_number(7, 2) == 924
assert rencontres_number(3, 0) == 2
assert rencontres_number(3, 1) == 3
[BEGIN]
def binomial_coeffi(n, k):
if (k == 0 or k == n):
... |
You are an expert Python programmer, and here is your task: Write a function to calculate the height of the given binary tree. Your code should pass these tests:
assert (max_height(root)) == 3
assert (max_height(root1)) == 5
assert (max_height(root2)) == 4
[BEGIN]
class Node:
def __init__(self, data):
self.dat... |
You are an expert Python programmer, and here is your task: Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format. Your code should pass these tests:
assert change_date_format('2026-01-02')=='02-01-2026'
assert change_date_format('2021-01-04')=='04-01-2021'
assert change_date_format('2030-06-06'... |
You are an expert Python programmer, and here is your task: Write a function to count repeated items of a tuple. Your code should pass these tests:
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2
assert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4
[BEGIN]
d... |
You are an expert Python programmer, and here is your task: Write a function that matches a string that has an a followed by zero or more b's by using regex. Your code should pass these tests:
assert text_match("msb") == 'Not matched!'
assert text_match("a0c") == 'Found a match!'
assert text_match("abbc") == 'Found a ... |
You are an expert Python programmer, and here is your task: Write a function to calculate the sum of series 1³+2³+3³+….+n³. Your code should pass these tests:
assert sum_series(7)==784
assert sum_series(5)==225
assert sum_series(15)==14400
[BEGIN]
import math
def sum_series(number):
total = 0
total = math.pow((n... |
You are an expert Python programmer, and here is your task: Write a function to remove duplicate words from a given list of strings. Your code should pass these tests:
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises"])==['Python', 'Exercises', 'Practice', 'Solution']
assert remove_... |
You are an expert Python programmer, and here is your task: Write a function to convert camel case string to snake case string by using regex. Your code should pass these tests:
assert camel_to_snake('GoogleAssistant') == 'google_assistant'
assert camel_to_snake('ChromeCast') == 'chrome_cast'
assert camel_to_snake('Qu... |
You are an expert Python programmer, and here is your task: Write a function to find the nth delannoy number. Your code should pass these tests:
assert dealnnoy_num(3, 4) == 129
assert dealnnoy_num(3, 3) == 63
assert dealnnoy_num(4, 5) == 681
[BEGIN]
def dealnnoy_num(n, m):
if (m == 0 or n == 0) :
return 1
re... |
You are an expert Python programmer, and here is your task: Write a function to calculate the sum of series 1²+2²+3²+….+n². Your code should pass these tests:
assert series_sum(6)==91
assert series_sum(7)==140
assert series_sum(12)==650
[BEGIN]
def series_sum(number):
total = 0
total = (number * (number + 1) * (2 ... |
You are an expert Python programmer, and here is your task: Write a function to re-arrange the given tuples based on the given ordered list. Your code should pass these tests:
assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]
assert re_arrange_tuples([(5, 4... |
You are an expert Python programmer, and here is your task: Write a function to count the most common character in a given string. Your code should pass these tests:
assert max_char("hello world")==('l')
assert max_char("hello ")==('l')
assert max_char("python pr")==('p')
[BEGIN]
from collections import Counter
def ... |
You are an expert Python programmer, and here is your task: Write a function to find three closest elements from three sorted arrays. Your code should pass these tests:
assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)
assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],... |
You are an expert Python programmer, and here is your task: Write a function to sort a list of dictionaries using lambda function. Your code should pass these tests:
assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color... |
You are an expert Python programmer, and here is your task: Write a function to sort the given array by using heap sort. Your code should pass these tests:
assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]
assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]
assert heap_sort([21, 15, 29, 78, 65]... |
You are an expert Python programmer, and here is your task: Write a function to count the elements in a list until an element is a tuple. Your code should pass these tests:
assert count_elim([10,20,30,(10,20),40])==3
assert count_elim([10,(20,30),(10,20),40])==1
assert count_elim([(10,(20,30,(10,20),40))])==0
[BEGIN]
... |
You are an expert Python programmer, and here is your task: Write a function to check if any list element is present in the given list. Your code should pass these tests:
assert check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) == True
assert check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) == True
assert check_element((3,... |
You are an expert Python programmer, and here is your task: Write a function to combine two given sorted lists using heapq module. Your code should pass these tests:
assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
assert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, ... |
You are an expert Python programmer, and here is your task: Write a function to separate and print the numbers and their position of a given string. Your code should pass these tests:
assert num_position("there are 70 flats in this apartment")==10
assert num_position("every adult have 32 teeth")==17
assert num_positio... |
You are an expert Python programmer, and here is your task: Write a function to convert the given tuples into set. Your code should pass these tests:
assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}
assert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}
assert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'... |
You are an expert Python programmer, and here is your task: Write a function to find the most common elements and their counts of a specified text. Your code should pass these tests:
assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',... |
You are an expert Python programmer, and here is your task: Write a python function to find the length of the shortest word. Your code should pass these tests:
assert len_log(["win","lose","great"]) == 3
assert len_log(["a","ab","abc"]) == 1
assert len_log(["12","12","1234"]) == 2
[BEGIN]
def len_log(list1):
min=... |
You are an expert Python programmer, and here is your task: Write a function to get an item of a tuple. Your code should pass these tests:
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),3)==('e')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-4)==('u')
assert get_item(("w", 3, "r",... |
You are an expert Python programmer, and here is your task: Write a function to sort the given tuple list basis the total digits in tuple. Your code should pass these tests:
assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'
assert sort_list([(... |
You are an expert Python programmer, and here is your task: Write a function to display sign of the chinese zodiac for given year. Your code should pass these tests:
assert chinese_zodiac(1997)==('Ox')
assert chinese_zodiac(1998)==('Tiger')
assert chinese_zodiac(1994)==('Dog')
[BEGIN]
def chinese_zodiac(year):
if (y... |
You are an expert Python programmer, and here is your task: Write a function to find the maximum of similar indices in two lists of tuples. Your code should pass these tests:
assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]
assert max_similar_indices([(3, 5)... |
You are an expert Python programmer, and here is your task: Write a function to compute the value of ncr mod p. Your code should pass these tests:
assert nCr_mod_p(10, 2, 13) == 6
assert nCr_mod_p(11, 3, 14) == 11
assert nCr_mod_p(18, 14, 19) == 1
[BEGIN]
def nCr_mod_p(n, r, p):
if (r > n- r):
r = n - r
C = ... |
You are an expert Python programmer, and here is your task: Write a python function to find the minimun number of subsets with distinct elements. Your code should pass these tests:
assert subset([1, 2, 3, 4],4) == 1
assert subset([5, 6, 9, 3, 4, 3, 4],7) == 2
assert subset([1, 2, 3 ],3) == 1
[BEGIN]
def subset(ar, n):... |
You are an expert Python programmer, and here is your task: Write a function that gives profit amount if the given amount has profit else return none. Your code should pass these tests:
assert profit_amount(1500,1200)==300
assert profit_amount(100,200)==None
assert profit_amount(2000,5000)==None
[BEGIN]
def profit_amo... |
You are an expert Python programmer, and here is your task: Write a function to find out, if the given number is abundant. Your code should pass these tests:
assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False
[BEGIN]
def is_abundant(n):
fctrsum = sum([fctr for fctr in range(1,... |
You are an expert Python programmer, and here is your task: Write a function to split the given string at uppercase letters by using regex. Your code should pass these tests:
assert split_list("LearnToBuildAnythingWithGoogle") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']
assert split_list("ApmlifyingTheBl... |
You are an expert Python programmer, and here is your task: Write a python function to get the position of rightmost set bit. Your code should pass these tests:
assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5
[BEGIN]
import math
def get_First_Set_Bit_P... |
You are an expert Python programmer, and here is your task: Write a function to convert an integer into a roman numeral. Your code should pass these tests:
assert int_to_roman(1)==("I")
assert int_to_roman(50)==("L")
assert int_to_roman(4)==("IV")
[BEGIN]
def int_to_roman( num):
val = [1000, 900, 500, 400,100... |
You are an expert Python programmer, and here is your task: Write a python function to find the average of a list. Your code should pass these tests:
assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75
assert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75
assert Average([1,2,3]) == 2
[BEGIN]
def Average(lst):
r... |
You are an expert Python programmer, and here is your task: Write a function to solve tiling problem. Your code should pass these tests:
assert get_noOfways(4)==3
assert get_noOfways(3)==2
assert get_noOfways(5)==5
[BEGIN]
def get_noOfways(n):
if (n == 0):
return 0;
if (n == 1):
return 1;
... |
You are an expert Python programmer, and here is your task: Write a function to convert a roman numeral to an integer. Your code should pass these tests:
assert roman_to_int('MMMCMLXXXVI')==3986
assert roman_to_int('MMMM')==4000
assert roman_to_int('C')==100
[BEGIN]
def roman_to_int(s):
rom_val = {'I': 1, 'V'... |
You are an expert Python programmer, and here is your task: Write a python function to find the sum of all even natural numbers within the range l and r. Your code should pass these tests:
assert sum_Even(2,5) == 6
assert sum_Even(3,8) == 18
assert sum_Even(4,6) == 10
[BEGIN]
def sum_Natural(n):
sum = (n * (n + ... |
You are an expert Python programmer, and here is your task: Write a function to calculate the discriminant value. Your code should pass these tests:
assert discriminant_value(4,8,2)==("Two solutions",32)
assert discriminant_value(5,7,9)==("no real solution",-131)
assert discriminant_value(0,0,9)==("one solution",0)
[B... |
You are an expert Python programmer, and here is your task: Write a python function to check whether the length of the word is even or not. Your code should pass these tests:
assert word_len("program") == False
assert word_len("solution") == True
assert word_len("data") == True
[BEGIN]
def word_len(s):
s = s.spl... |
You are an expert Python programmer, and here is your task: Write a function to convert camel case string to snake case string. Your code should pass these tests:
assert camel_to_snake('PythonProgram')==('python_program')
assert camel_to_snake('pythonLanguage')==('python_language')
assert camel_to_snake('ProgrammingLa... |
You are an expert Python programmer, and here is your task: Write a function to remove an empty tuple from a list of tuples. Your code should pass these tests:
assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
assert remove_empty([(), (), ('',), ("pyt... |
You are an expert Python programmer, and here is your task: Write a python function to accept the strings which contains all vowels. Your code should pass these tests:
assert check("SEEquoiaL") == 'accepted'
assert check('program') == "not accepted"
assert check('fine') == "not accepted"
[BEGIN]
def check(string):
... |
You are an expert Python programmer, and here is your task: Write a python function to find maximum possible value for the given periodic function. Your code should pass these tests:
assert floor_Max(11,10,9) == 9
assert floor_Max(5,7,4) == 2
assert floor_Max(2,2,1) == 1
[BEGIN]
def floor_Max(A,B,N):
x = min(B - ... |
You are an expert Python programmer, and here is your task: Write a function to join the tuples if they have similar initial elements. Your code should pass these tests:
assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]
assert join_tuples([(6, 7), (6, 8), (7, 9), (7, 1... |
You are an expert Python programmer, and here is your task: Write a function to find minimum of two numbers. Your code should pass these tests:
assert min_of_two(10,20)==10
assert min_of_two(19,15)==15
assert min_of_two(-10,-20)==-20
[BEGIN]
def min_of_two( x, y ):
if x < y:
return x
return y
[DONE] |
You are an expert Python programmer, and here is your task: Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n. Your code should pass these tests:
assert maximum_segments(7, 5, 2, 5) == 2
assert maximum_segments(17, 2, 1, 3) == 17
assert maximum_segments(18, 16, 3, ... |
You are an expert Python programmer, and here is your task: Write a function to concatenate the given two tuples to a nested tuple. Your code should pass these tests:
assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)
assert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)
assert concatenate_nested((4, 5), (6... |
You are an expert Python programmer, and here is your task: Write a python function to left rotate the string. Your code should pass these tests:
assert left_rotate("python",2) == "thonpy"
assert left_rotate("bigdata",3 ) == "databig"
assert left_rotate("hadoop",1 ) == "adooph"
[BEGIN]
def left_rotate(s,d):
... |
You are an expert Python programmer, and here is your task: Write a function to find the minimum total path sum in the given triangle. Your code should pass these tests:
assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6
assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10
assert min_sum_path([[ 3 ], [6, 4 ], ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.