task_id
int64
601
974
source_split
stringclasses
1 value
text
stringlengths
38
249
test_setup_code
stringclasses
2 values
test_list
listlengths
3
3
challenge_test_list
listlengths
0
0
user_input
stringlengths
144
964
assistant_response
stringlengths
211
1.4k
messages
listlengths
2
2
901
train
Write a function to find the smallest multiple of the first n numbers.
[ "assert smallest_multiple(13)==360360", "assert smallest_multiple(2)==2", "assert smallest_multiple(1)==1" ]
[]
def smallest_multiple(n): ''' Write a function to find the smallest multiple of the first n numbers. >>> smallest_multiple(13) 360360 >>> smallest_multiple(2) 2 >>> smallest_multiple(1) 1 '''
```python def smallest_multiple(n): ''' Write a function to find the smallest multiple of the first n numbers. >>> smallest_multiple(13) 360360 >>> smallest_multiple(2) 2 >>> smallest_multiple(1) 1 ''' if (n<=2): return n i = n * 2 factors = [number for number in range...
[ { "role": "user", "content": "def smallest_multiple(n):\n\t''' Write a function to find the smallest multiple of the first n numbers.\n\t>>> smallest_multiple(13)\n\t360360\n\t>>> smallest_multiple(2)\n\t2\n\t>>> smallest_multiple(1)\n\t1\n\t'''" }, { "role": "assistant", "content": "```python\n...
902
train
Write a function to combine two dictionaries by adding values for common keys.
[ "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': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900}) ", "assert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,...
[]
from collections import Counter def add_dict(d1,d2): ''' Write a function to combine two dictionaries by adding values for common keys. >>> add_dict({'a': 100, 'b': 200, 'c': 300}, {'a': 300, 'b': 200, 'd': 400}) {'b': 400, 'd': 400, 'a': 400, 'c': 300} >>> add_dict({'a': 500, 'b': 700, 'c': 900}, {'a': 500, 'b': 6...
```python from collections import Counter def add_dict(d1,d2): ''' Write a function to combine two dictionaries by adding values for common keys. >>> add_dict({'a': 100, 'b': 200, 'c': 300}, {'a': 300, 'b': 200, 'd': 400}) {'b': 400, 'd': 400, 'a': 400, 'c': 300} >>> add_dict({'a': 500, 'b': 700, 'c': 900},...
[ { "role": "user", "content": "from collections import Counter\ndef add_dict(d1,d2):\n\t''' Write a function to combine two dictionaries by adding values for common keys.\n\t>>> add_dict({'a': 100, 'b': 200, 'c': 300}, {'a': 300, 'b': 200, 'd': 400})\n\t{'b': 400, 'd': 400, 'a': 400, 'c': 300}\n\t>>> add_dic...
903
train
Write a python function to count the total unset bits from 1 to n.
[ "assert count_Unset_Bits(2) == 1", "assert count_Unset_Bits(5) == 4", "assert count_Unset_Bits(14) == 17" ]
[]
def count_Unset_Bits(n) : ''' Write a python function to count the total unset bits from 1 to n. >>> count_Unset_Bits(2) 1 >>> count_Unset_Bits(5) 4 >>> count_Unset_Bits(14) 17 '''
```python def count_Unset_Bits(n) : ''' Write a python function to count the total unset bits from 1 to n. >>> count_Unset_Bits(2) 1 >>> count_Unset_Bits(5) 4 >>> count_Unset_Bits(14) 17 ''' cnt = 0; for i in range(1,n + 1) : temp = i; while (temp) : ...
[ { "role": "user", "content": "def count_Unset_Bits(n) : \n\t''' Write a python function to count the total unset bits from 1 to n.\n\t>>> count_Unset_Bits(2)\n\t1\n\t>>> count_Unset_Bits(5)\n\t4\n\t>>> count_Unset_Bits(14)\n\t17\n\t'''" }, { "role": "assistant", "content": "```python\ndef count...
904
train
Write a function to return true if the given number is even else return false.
[ "assert even_num(13.5)==False", "assert even_num(0)==True", "assert even_num(-9)==False" ]
[]
def even_num(x): ''' Write a function to return true if the given number is even else return false. >>> even_num(13.5) False >>> even_num(0) True >>> even_num(-9) False '''
```python def even_num(x): ''' Write a function to return true if the given number is even else return false. >>> even_num(13.5) False >>> even_num(0) True >>> even_num(-9) False ''' if x%2==0: return True else: return False ```
[ { "role": "user", "content": "def even_num(x):\n\t''' Write a function to return true if the given number is even else return false.\n\t>>> even_num(13.5)\n\tFalse\n\t>>> even_num(0)\n\tTrue\n\t>>> even_num(-9)\n\tFalse\n\t'''" }, { "role": "assistant", "content": "```python\ndef even_num(x):\n ...
905
train
Write a python function to find the sum of squares of binomial co-efficients.
[ "assert sum_of_square(4) == 70", "assert sum_of_square(5) == 252", "assert sum_of_square(2) == 6" ]
[]
def factorial(start,end): ''' Write a python function to find the sum of squares of binomial co-efficients. >>> sum_of_square(4) 70 >>> sum_of_square(5) 252 >>> sum_of_square(2) 6 '''
```python def factorial(start,end): ''' Write a python function to find the sum of squares of binomial co-efficients. >>> sum_of_square(4) 70 >>> sum_of_square(5) 252 >>> sum_of_square(2) 6 ''' res = 1 for i in range(start,end + 1): res *= i return res def s...
[ { "role": "user", "content": "def factorial(start,end): \n\t''' Write a python function to find the sum of squares of binomial co-efficients.\n\t>>> sum_of_square(4)\n\t70\n\t>>> sum_of_square(5)\n\t252\n\t>>> sum_of_square(2)\n\t6\n\t'''" }, { "role": "assistant", "content": "```python\ndef fac...
906
train
Write a function to extract year, month and date from a url by using regex.
[ "assert extract_date(\"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\") == [('2016', '09', '02')]", "assert extract_date(\"https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-...
[]
import re def extract_date(url): ''' Write a function to extract year, month and date from a url by using regex. >>> extract_date('https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/') [('2016', '09', '02')] >>> extract_dat...
```python import re def extract_date(url): ''' Write a function to extract year, month and date from a url by using regex. >>> extract_date('https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/') [('2016'...
[ { "role": "user", "content": "import re\ndef extract_date(url):\n\t''' Write a function to extract year, month and date from a url by using regex.\n\t>>> extract_date('https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-aut...
907
train
Write a function to print the first n lucky numbers.
[ "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]" ]
[]
def lucky_num(n): ''' Write a function to print the first n lucky numbers. >>> lucky_num(10) [1, 3, 7, 9, 13, 15, 21, 25, 31, 33] >>> lucky_num(5) [1, 3, 7, 9, 13] >>> lucky_num(8) [1, 3, 7, 9, 13, 15, 21, 25] '''
```python def lucky_num(n): ''' Write a function to print the first n lucky numbers. >>> lucky_num(10) [1, 3, 7, 9, 13, 15, 21, 25, 31, 33] >>> lucky_num(5) [1, 3, 7, 9, 13] >>> lucky_num(8) [1, 3, 7, 9, 13, 15, 21, 25] ''' List=range(-1,n*n+9,2) i=2 while List[i:]:List=sorted(set(List)-set(List[List[i]::Lis...
[ { "role": "user", "content": "def lucky_num(n):\n\t''' Write a function to print the first n lucky numbers.\n\t>>> lucky_num(10)\n\t[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]\n\t>>> lucky_num(5)\n\t[1, 3, 7, 9, 13]\n\t>>> lucky_num(8)\n\t[1, 3, 7, 9, 13, 15, 21, 25]\n\t'''" }, { "role": "assistant", "...
908
train
Write a function to find the fixed point in the given array.
[ "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, 17],5) == 0" ]
[]
def find_fixed_point(arr, n): ''' Write a function to find the fixed point in the given array. >>> find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100], 9) 3 >>> find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8], 8) -1 >>> find_fixed_point([0, 2, 5, 8, 17], 5) 0 '''
```python def find_fixed_point(arr, n): ''' Write a function to find the fixed point in the given array. >>> find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100], 9) 3 >>> find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8], 8) -1 >>> find_fixed_point([0, 2, 5, 8, 17], 5) 0 ''' for i in range(n): if arr[i] is i: ...
[ { "role": "user", "content": "def find_fixed_point(arr, n): \n\t''' Write a function to find the fixed point in the given array.\n\t>>> find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100], 9)\n\t3\n\t>>> find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8], 8)\n\t-1\n\t>>> find_fixed_point([0, 2, 5, 8, 17], 5)\n\t0\...
909
train
Write a function to find the previous palindrome of a specified number.
[ "assert previous_palindrome(99)==88", "assert previous_palindrome(1221)==1111", "assert previous_palindrome(120)==111" ]
[]
def previous_palindrome(num): ''' Write a function to find the previous palindrome of a specified number. >>> previous_palindrome(99) 88 >>> previous_palindrome(1221) 1111 >>> previous_palindrome(120) 111 '''
```python def previous_palindrome(num): ''' Write a function to find the previous palindrome of a specified number. >>> previous_palindrome(99) 88 >>> previous_palindrome(1221) 1111 >>> previous_palindrome(120) 111 ''' for x in range(num-1,0,-1): if str(x) == str(x)[::-1]: ...
[ { "role": "user", "content": "def previous_palindrome(num):\n\t''' Write a function to find the previous palindrome of a specified number.\n\t>>> previous_palindrome(99)\n\t88\n\t>>> previous_palindrome(1221)\n\t1111\n\t>>> previous_palindrome(120)\n\t111\n\t'''" }, { "role": "assistant", "conte...
910
train
Write a function to validate a gregorian date.
[ "assert check_date(11,11,2002)==True", "assert check_date(13,11,2002)==False", "assert check_date('11','11','2002')==True" ]
[]
import datetime def check_date(m, d, y): ''' Write a function to validate a gregorian date. >>> check_date(11, 11, 2002) True >>> check_date(13, 11, 2002) False >>> check_date('11', '11', '2002') True '''
```python import datetime def check_date(m, d, y): ''' Write a function to validate a gregorian date. >>> check_date(11, 11, 2002) True >>> check_date(13, 11, 2002) False >>> check_date('11', '11', '2002') True ''' try: m, d, y = map(int, (m, d, y)) datetime.date(y, m...
[ { "role": "user", "content": "import datetime\ndef check_date(m, d, y):\n\t''' Write a function to validate a gregorian date.\n\t>>> check_date(11, 11, 2002)\n\tTrue\n\t>>> check_date(13, 11, 2002)\n\tFalse\n\t>>> check_date('11', '11', '2002')\n\tTrue\n\t'''" }, { "role": "assistant", "content"...
911
train
Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.
[ "assert maximum_product( [12, 74, 9, 50, 61, 41])==225700", "assert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375", "assert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520" ]
[]
def maximum_product(nums): ''' Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm. >>> maximum_product([12, 74, 9, 50, 61, 41]) 225700 >>> maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58]) 414375 >>> maximum_product([18, 14, 10, 9, 8, 7, 9, 3, ...
```python def maximum_product(nums): ''' Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm. >>> maximum_product([12, 74, 9, 50, 61, 41]) 225700 >>> maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58]) 414375 >>> maximum_product(...
[ { "role": "user", "content": "def maximum_product(nums):\n\t''' Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.\n\t>>> maximum_product([12, 74, 9, 50, 61, 41])\n\t225700\n\t>>> maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])\n\t4143...
912
train
Write a function to find ln, m lobb number.
[ "assert int(lobb_num(5, 3)) == 35", "assert int(lobb_num(3, 2)) == 5", "assert int(lobb_num(4, 2)) == 20" ]
[]
def binomial_coeff(n, k): ''' Write a function to find ln, m lobb number. >>> int(lobb_num(5, 3)) 35 >>> int(lobb_num(3, 2)) 5 >>> int(lobb_num(4, 2)) 20 '''
```python def binomial_coeff(n, k): ''' Write a function to find ln, m lobb number. >>> int(lobb_num(5, 3)) 35 >>> int(lobb_num(3, 2)) 5 >>> int(lobb_num(4, 2)) 20 ''' C = [[0 for j in range(k + 1)] for i in range(n + 1)] for i in range(0, n + 1): for j in range(0, min(i, k) + 1): if (j == 0 or j...
[ { "role": "user", "content": "def binomial_coeff(n, k): \n\t''' Write a function to find ln, m lobb number.\n\t>>> int(lobb_num(5, 3))\n\t35\n\t>>> int(lobb_num(3, 2))\n\t5\n\t>>> int(lobb_num(4, 2))\n\t20\n\t'''" }, { "role": "assistant", "content": "```python\ndef binomial_coeff(n, k): \n\t'''...
913
train
Write a function to check for a number at the end of a string.
[ "assert end_num('abcdef')==False", "assert end_num('abcdef7')==True", "assert end_num('abc')==False" ]
[]
import re def end_num(string): ''' Write a function to check for a number at the end of a string. >>> end_num('abcdef') False >>> end_num('abcdef7') True >>> end_num('abc') False '''
```python import re def end_num(string): ''' Write a function to check for a number at the end of a string. >>> end_num('abcdef') False >>> end_num('abcdef7') True >>> end_num('abc') False ''' text = re.compile(r".*[0-9]$") if text.match(string): return True else: ...
[ { "role": "user", "content": "import re\ndef end_num(string):\n\t''' Write a function to check for a number at the end of a string.\n\t>>> end_num('abcdef')\n\tFalse\n\t>>> end_num('abcdef7')\n\tTrue\n\t>>> end_num('abc')\n\tFalse\n\t'''" }, { "role": "assistant", "content": "```python\nimport r...
914
train
Write a python function to check whether the given string is made up of two alternating characters or not.
[ "assert is_Two_Alter(\"abab\") == True", "assert is_Two_Alter(\"aaaa\") == False", "assert is_Two_Alter(\"xyz\") == False" ]
[]
def is_Two_Alter(s): ''' Write a python function to check whether the given string is made up of two alternating characters or not. >>> is_Two_Alter('abab') True >>> is_Two_Alter('aaaa') False >>> is_Two_Alter('xyz') False '''
```python def is_Two_Alter(s): ''' Write a python function to check whether the given string is made up of two alternating characters or not. >>> is_Two_Alter('abab') True >>> is_Two_Alter('aaaa') False >>> is_Two_Alter('xyz') False ''' for i in range (len( s) - 2) : if (s...
[ { "role": "user", "content": "def is_Two_Alter(s): \n\t''' Write a python function to check whether the given string is made up of two alternating characters or not.\n\t>>> is_Two_Alter('abab')\n\tTrue\n\t>>> is_Two_Alter('aaaa')\n\tFalse\n\t>>> is_Two_Alter('xyz')\n\tFalse\n\t'''" }, { "role": "as...
915
train
Write a function to rearrange positive and negative numbers in a given array using lambda function.
[ "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,12,-20])==[10, 12, 13, 14, 15, -20, -18]", "assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]" ]
[]
def rearrange_numbs(array_nums): ''' Write a function to rearrange positive and negative numbers in a given array using lambda function. >>> rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10]) [2, 5, 7, 8, 9, -10, -3, -1] >>> rearrange_numbs([10, 15, 14, 13, -18, 12, -20]) [10, 12, 13, 14, 15, -20, -18] >>> rearrange_n...
```python def rearrange_numbs(array_nums): ''' Write a function to rearrange positive and negative numbers in a given array using lambda function. >>> rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10]) [2, 5, 7, 8, 9, -10, -3, -1] >>> rearrange_numbs([10, 15, 14, 13, -18, 12, -20]) [10, 12, 13, 14, 15, -20, -18] ...
[ { "role": "user", "content": "def rearrange_numbs(array_nums):\n\t''' Write a function to rearrange positive and negative numbers in a given array using lambda function.\n\t>>> rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])\n\t[2, 5, 7, 8, 9, -10, -3, -1]\n\t>>> rearrange_numbs([10, 15, 14, 13, -18, 12, -20]...
916
train
Write a function to find if there is a triplet in the array whose sum is equal to a given value.
[ "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) == (12, 3, 9)", "assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)" ]
[]
def find_triplet_array(A, arr_size, sum): ''' Write a function to find if there is a triplet in the array whose sum is equal to a given value. >>> find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) (4, 10, 8) >>> find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) (12, 3, 9) >>> find_triplet_array([1, 2, 3, 4, 5], 5, 9)...
```python def find_triplet_array(A, arr_size, sum): ''' Write a function to find if there is a triplet in the array whose sum is equal to a given value. >>> find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) (4, 10, 8) >>> find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) (12, 3, 9) >>> find_triplet_array([1, 2, 3, 4,...
[ { "role": "user", "content": "def find_triplet_array(A, arr_size, sum): \n\t''' Write a function to find if there is a triplet in the array whose sum is equal to a given value.\n\t>>> find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22)\n\t(4, 10, 8)\n\t>>> find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24)\n\t(12, ...
917
train
Write a function to find the sequences of one upper case letter followed by lower case letters.
[ "assert text_uppercase_lowercase(\"AaBbGg\")==('Found a match!')", "assert text_uppercase_lowercase(\"aA\")==('Not matched!')", "assert text_uppercase_lowercase(\"PYTHON\")==('Not matched!')" ]
[]
import re def text_uppercase_lowercase(text): ''' Write a function to find the sequences of one upper case letter followed by lower case letters. >>> text_uppercase_lowercase('AaBbGg') 'Found a match!' >>> text_uppercase_lowercase('aA') 'Not matched!' >>> text_uppercase_lowercase('PYTHON') 'Not matched!' '''
```python import re def text_uppercase_lowercase(text): ''' Write a function to find the sequences of one upper case letter followed by lower case letters. >>> text_uppercase_lowercase('AaBbGg') 'Found a match!' >>> text_uppercase_lowercase('aA') 'Not matched!' >>> text_u...
[ { "role": "user", "content": "import re\ndef text_uppercase_lowercase(text):\n\t''' Write a function to find the sequences of one upper case letter followed by lower case letters.\n\t>>> text_uppercase_lowercase('AaBbGg')\n\t'Found a match!'\n\t>>> text_uppercase_lowercase('aA')\n\t'Not matched!'\n\t>>> tex...
918
train
Write a function to count coin change.
[ "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" ]
[]
def coin_change(S, m, n): ''' Write a function to count coin change. >>> coin_change([1, 2, 3], 3, 4) 4 >>> coin_change([4, 5, 6, 7, 8, 9], 6, 9) 2 >>> coin_change([4, 5, 6, 7, 8, 9], 6, 4) 1 '''
```python def coin_change(S, m, n): ''' Write a function to count coin change. >>> coin_change([1, 2, 3], 3, 4) 4 >>> coin_change([4, 5, 6, 7, 8, 9], 6, 9) 2 >>> coin_change([4, 5, 6, 7, 8, 9], 6, 4) 1 ''' table = [[0 for x in range(m)] for x in range(n+1)] for i in range(m): ...
[ { "role": "user", "content": "def coin_change(S, m, n): \n\t''' Write a function to count coin change.\n\t>>> coin_change([1, 2, 3], 3, 4)\n\t4\n\t>>> coin_change([4, 5, 6, 7, 8, 9], 6, 9)\n\t2\n\t>>> coin_change([4, 5, 6, 7, 8, 9], 6, 4)\n\t1\n\t'''" }, { "role": "assistant", "content": "```pyt...
919
train
Write a python function to multiply all items in the list.
[ "assert multiply_list([1,-2,3]) == -6", "assert multiply_list([1,2,3,4]) == 24", "assert multiply_list([3,1,2,3]) == 18" ]
[]
def multiply_list(items): ''' Write a python function to multiply all items in the list. >>> multiply_list([1, -2, 3]) -6 >>> multiply_list([1, 2, 3, 4]) 24 >>> multiply_list([3, 1, 2, 3]) 18 '''
```python def multiply_list(items): ''' Write a python function to multiply all items in the list. >>> multiply_list([1, -2, 3]) -6 >>> multiply_list([1, 2, 3, 4]) 24 >>> multiply_list([3, 1, 2, 3]) 18 ''' tot = 1 for x in items: tot *= x return tot ```
[ { "role": "user", "content": "def multiply_list(items):\n\t''' Write a python function to multiply all items in the list.\n\t>>> multiply_list([1, -2, 3])\n\t-6\n\t>>> multiply_list([1, 2, 3, 4])\n\t24\n\t>>> multiply_list([3, 1, 2, 3])\n\t18\n\t'''" }, { "role": "assistant", "content": "```pyth...
920
train
Write a function to remove all tuples with all none values in the given tuple list.
[ "assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'", "assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'", "assert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(...
[]
def remove_tuple(test_list): ''' Write a function to remove all tuples with all none values in the given tuple list. >>> remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None,)]) '[(None, 2), (3, 4), (12, 3)]' >>> remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None, 1)]) '[(3, 6), (17, 3), (No...
```python def remove_tuple(test_list): ''' Write a function to remove all tuples with all none values in the given tuple list. >>> remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None,)]) '[(None, 2), (3, 4), (12, 3)]' >>> remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None, 1)]) '[(3, 6...
[ { "role": "user", "content": "def remove_tuple(test_list):\n\t''' Write a function to remove all tuples with all none values in the given tuple list.\n\t>>> remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None,)])\n\t'[(None, 2), (3, 4), (12, 3)]'\n\t>>> remove_tuple([(None, None), (None, None), (3...
921
train
Write a function to perform chunking of tuples each of size n.
[ "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), (5, 6), (7, 8), (9,)]", "assert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16, 17), (19, 21, 22, 25)]" ]
[]
def chunk_tuples(test_tup, N): ''' Write a function to perform chunking of tuples each of size n. >>> chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) [(10, 4, 5), (6, 7, 6), (8, 3, 4)] >>> chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) [(1, 2), (3, 4), (5, 6), (7, 8), (9,)] >>> chunk_tuples((11, 14, 16, 17, 19, 21, 2...
```python def chunk_tuples(test_tup, N): ''' Write a function to perform chunking of tuples each of size n. >>> chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) [(10, 4, 5), (6, 7, 6), (8, 3, 4)] >>> chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) [(1, 2), (3, 4), (5, 6), (7, 8), (9,)] >>> chunk_tuples((11, 14, 1...
[ { "role": "user", "content": "def chunk_tuples(test_tup, N):\n\t''' Write a function to perform chunking of tuples each of size n.\n\t>>> chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3)\n\t[(10, 4, 5), (6, 7, 6), (8, 3, 4)]\n\t>>> chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2)\n\t[(1, 2), (3, 4), (5, 6), (7, 8)...
922
train
Write a function to find a pair with the highest product from a given array of integers.
[ "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, 5, 6, 8, 9])==(8,9)" ]
[]
def max_product(arr): ''' Write a function to find a pair with the highest product from a given array of integers. >>> max_product([1, 2, 3, 4, 7, 0, 8, 4]) (7, 8) >>> max_product([0, -1, -2, -4, 5, 0, -6]) (-4, -6) >>> max_product([1, 3, 5, 6, 8, 9]) (8, 9) '''
```python def max_product(arr): ''' Write a function to find a pair with the highest product from a given array of integers. >>> max_product([1, 2, 3, 4, 7, 0, 8, 4]) (7, 8) >>> max_product([0, -1, -2, -4, 5, 0, -6]) (-4, -6) >>> max_product([1, 3, 5, 6, 8, 9]) (8, 9) ''' arr_len = ...
[ { "role": "user", "content": "def max_product(arr): \n\t''' Write a function to find a pair with the highest product from a given array of integers.\n\t>>> max_product([1, 2, 3, 4, 7, 0, 8, 4])\n\t(7, 8)\n\t>>> max_product([0, -1, -2, -4, 5, 0, -6])\n\t(-4, -6)\n\t>>> max_product([1, 3, 5, 6, 8, 9])\n\t(8, ...
923
train
Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.
[ "assert super_seq(\"AGGTAB\", \"GXTXAYB\", 6, 7) == 9", "assert super_seq(\"feek\", \"eke\", 4, 3) == 5", "assert super_seq(\"PARRT\", \"RTA\", 5, 3) == 6" ]
[]
def super_seq(X, Y, m, n): ''' Write a function to find the length of the shortest string that has both str1 and str2 as subsequences. >>> super_seq('AGGTAB', 'GXTXAYB', 6, 7) 9 >>> super_seq('feek', 'eke', 4, 3) 5 >>> super_seq('PARRT', 'RTA', 5, 3) 6 '''
```python def super_seq(X, Y, m, n): ''' Write a function to find the length of the shortest string that has both str1 and str2 as subsequences. >>> super_seq('AGGTAB', 'GXTXAYB', 6, 7) 9 >>> super_seq('feek', 'eke', 4, 3) 5 >>> super_seq('PARRT', 'RTA', 5, 3) 6 ''' if (not m): return n if (not n): return...
[ { "role": "user", "content": "def super_seq(X, Y, m, n):\n\t''' Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.\n\t>>> super_seq('AGGTAB', 'GXTXAYB', 6, 7)\n\t9\n\t>>> super_seq('feek', 'eke', 4, 3)\n\t5\n\t>>> super_seq('PARRT', 'RTA', 5, 3)\n\t6\n\t'...
924
train
Write a function to find maximum of two numbers.
[ "assert max_of_two(10,20)==20", "assert max_of_two(19,15)==19", "assert max_of_two(-10,-20)==-10" ]
[]
def max_of_two( x, y ): ''' Write a function to find maximum of two numbers. >>> max_of_two(10, 20) 20 >>> max_of_two(19, 15) 19 >>> max_of_two(-10, -20) -10 '''
```python def max_of_two( x, y ): ''' Write a function to find maximum of two numbers. >>> max_of_two(10, 20) 20 >>> max_of_two(19, 15) 19 >>> max_of_two(-10, -20) -10 ''' if x > y: return x return y ```
[ { "role": "user", "content": "def max_of_two( x, y ):\n\t''' Write a function to find maximum of two numbers.\n\t>>> max_of_two(10, 20)\n\t20\n\t>>> max_of_two(19, 15)\n\t19\n\t>>> max_of_two(-10, -20)\n\t-10\n\t'''" }, { "role": "assistant", "content": "```python\ndef max_of_two( x, y ):\n '...
925
train
Write a python function to calculate the product of all the numbers of a given tuple.
[ "assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864", "assert mutiple_tuple((1,2,3)) == 6", "assert mutiple_tuple((-2,-4,-6)) == -48" ]
[]
def mutiple_tuple(nums): ''' Write a python function to calculate the product of all the numbers of a given tuple. >>> mutiple_tuple((4, 3, 2, 2, -1, 18)) -864 >>> mutiple_tuple((1, 2, 3)) 6 >>> mutiple_tuple((-2, -4, -6)) -48 '''
```python def mutiple_tuple(nums): ''' Write a python function to calculate the product of all the numbers of a given tuple. >>> mutiple_tuple((4, 3, 2, 2, -1, 18)) -864 >>> mutiple_tuple((1, 2, 3)) 6 >>> mutiple_tuple((-2, -4, -6)) -48 ''' temp = list(nums) product = 1 for ...
[ { "role": "user", "content": "def mutiple_tuple(nums):\n\t''' Write a python function to calculate the product of all the numbers of a given tuple.\n\t>>> mutiple_tuple((4, 3, 2, 2, -1, 18))\n\t-864\n\t>>> mutiple_tuple((1, 2, 3))\n\t6\n\t>>> mutiple_tuple((-2, -4, -6))\n\t-48\n\t'''" }, { "role": "...
926
train
Write a function to find n-th rencontres number.
[ "assert rencontres_number(7, 2) == 924", "assert rencontres_number(3, 0) == 2", "assert rencontres_number(3, 1) == 3" ]
[]
def binomial_coeffi(n, k): ''' Write a function to find n-th rencontres number. >>> rencontres_number(7, 2) 924 >>> rencontres_number(3, 0) 2 >>> rencontres_number(3, 1) 3 '''
```python def binomial_coeffi(n, k): ''' Write a function to find n-th rencontres number. >>> rencontres_number(7, 2) 924 >>> rencontres_number(3, 0) 2 >>> rencontres_number(3, 1) 3 ''' if (k == 0 or k == n): return 1 return (binomial_coeffi(n - 1, k - 1) + binomial_coeffi(n - 1, k)) def rencontres_nu...
[ { "role": "user", "content": "def binomial_coeffi(n, k): \n\t''' Write a function to find n-th rencontres number.\n\t>>> rencontres_number(7, 2)\n\t924\n\t>>> rencontres_number(3, 0)\n\t2\n\t>>> rencontres_number(3, 1)\n\t3\n\t'''" }, { "role": "assistant", "content": "```python\ndef binomial_co...
927
train
Write a function to calculate the height of the given binary tree.
root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root1 = Node(1); root1.left = Node(2); root1.right = Node(3); root1.left.left = Node(4); root1.right.left = Node(5); root1.right.right = Node(6); root1.right.right.right= Node(7); ro...
[ "assert (max_height(root)) == 3", "assert (max_height(root1)) == 5 ", "assert (max_height(root2)) == 4" ]
[]
root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root1 = Node(1); root1.left = Node(2); root1.right = Node(3); root1.left.left = Node(4); root1.right.left = Node(5); root1.right.right = Node(6); root1.right.right.right= Node(7); root1.right.ri...
```python class Node: ''' Write a function to calculate the height of the given binary tree. >>> max_height(root) 3 >>> max_height(root1) 5 >>> max_height(root2) 4 ''' def __init__(self, data): self.data = data self.left = None self.right = None def max_height(node): if node is None: return 0 ; ...
[ { "role": "user", "content": "root = Node(1) \nroot.left = Node(2) \nroot.right = Node(3) \nroot.left.left = Node(4) \nroot.left.right = Node(5) \nroot1 = Node(1); \nroot1.left = Node(2); \nroot1.right = Node(3); \nroot1.left.left = Node(4); \nroot1.right.left = Node(5); \nroot1.right.right = Node(6); ...
928
train
Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.
[ "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')=='06-06-2030'" ]
[]
import re def change_date_format(dt): ''' Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format. >>> change_date_format('2026-01-02') '02-01-2026' >>> change_date_format('2021-01-04') '04-01-2021' >>> change_date_format('2030-06-06') '06-06-2030' '''
```python import re def change_date_format(dt): ''' Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format. >>> change_date_format('2026-01-02') '02-01-2026' >>> change_date_format('2021-01-04') '04-01-2021' >>> change_date_format('2030-06-06') ...
[ { "role": "user", "content": "import re\ndef change_date_format(dt):\n\t''' Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.\n\t>>> change_date_format('2026-01-02')\n\t'02-01-2026'\n\t>>> change_date_format('2021-01-04')\n\t'04-01-2021'\n\t>>> change_date_format('2030-06-06')\n\...
929
train
Write a function to count repeated items of a tuple.
[ "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" ]
[]
def count_tuplex(tuplex,value): ''' Write a function to count repeated items of a tuple. >>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 4) 3 >>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 2) 2 >>> count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7), 7) 4 '''
```python def count_tuplex(tuplex,value): ''' Write a function to count repeated items of a tuple. >>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 4) 3 >>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 2) 2 >>> count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7), 7) 4 ''' count = tuplex.count(value) return count `...
[ { "role": "user", "content": "def count_tuplex(tuplex,value): \n\t''' Write a function to count repeated items of a tuple.\n\t>>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 4)\n\t3\n\t>>> count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7), 2)\n\t2\n\t>>> count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7), 7)\n\t4\n\t'''" }, ...
930
train
Write a function that matches a string that has an a followed by zero or more b's by using regex.
[ "assert text_match(\"msb\") == 'Not matched!'", "assert text_match(\"a0c\") == 'Found a match!'", "assert text_match(\"abbc\") == 'Found a match!'" ]
[]
import re def text_match(text): ''' Write a function that matches a string that has an a followed by zero or more b's by using regex. >>> text_match('msb') 'Not matched!' >>> text_match('a0c') 'Found a match!' >>> text_match('abbc') 'Found a match!' '''
```python import re def text_match(text): ''' Write a function that matches a string that has an a followed by zero or more b's by using regex. >>> text_match('msb') 'Not matched!' >>> text_match('a0c') 'Found a match!' >>> text_match('abbc') 'Found a match!' ...
[ { "role": "user", "content": "import re\ndef text_match(text):\n\t''' Write a function that matches a string that has an a followed by zero or more b's by using regex.\n\t>>> text_match('msb')\n\t'Not matched!'\n\t>>> text_match('a0c')\n\t'Found a match!'\n\t>>> text_match('abbc')\n\t'Found a match!'\n\t'''...
931
train
Write a function to calculate the sum of series 1³+2³+3³+….+n³.
[ "assert sum_series(7)==784", "assert sum_series(5)==225", "assert sum_series(15)==14400" ]
[]
import math def sum_series(number): ''' Write a function to calculate the sum of series 1³+2³+3³+….+n³. >>> sum_series(7) 784 >>> sum_series(5) 225 >>> sum_series(15) 14400 '''
```python import math def sum_series(number): ''' Write a function to calculate the sum of series 1³+2³+3³+….+n³. >>> sum_series(7) 784 >>> sum_series(5) 225 >>> sum_series(15) 14400 ''' total = 0 total = math.pow((number * (number + 1)) /2, 2) return total ```
[ { "role": "user", "content": "import math\ndef sum_series(number):\n\t''' Write a function to calculate the sum of series 1³+2³+3³+….+n³.\n\t>>> sum_series(7)\n\t784\n\t>>> sum_series(5)\n\t225\n\t>>> sum_series(15)\n\t14400\n\t'''" }, { "role": "assistant", "content": "```python\nimport math\nd...
932
train
Write a function to remove duplicate words from a given list of strings.
[ "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\"])==['Python', 'Exercises', 'Practice', 'Solution']", "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"Java\"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']...
[]
def remove_duplic_list(l): ''' Write a function to remove duplicate words from a given list of strings. >>> remove_duplic_list(['Python', 'Exercises', 'Practice', 'Solution', 'Exercises']) ['Python', 'Exercises', 'Practice', 'Solution'] >>> remove_duplic_list(['Python', 'Exercises', 'Practice', 'Solution', 'Exercis...
```python def remove_duplic_list(l): ''' Write a function to remove duplicate words from a given list of strings. >>> remove_duplic_list(['Python', 'Exercises', 'Practice', 'Solution', 'Exercises']) ['Python', 'Exercises', 'Practice', 'Solution'] >>> remove_duplic_list(['Python', 'Exercises', 'Practice'...
[ { "role": "user", "content": "def remove_duplic_list(l):\n\t''' Write a function to remove duplicate words from a given list of strings.\n\t>>> remove_duplic_list(['Python', 'Exercises', 'Practice', 'Solution', 'Exercises'])\n\t['Python', 'Exercises', 'Practice', 'Solution']\n\t>>> remove_duplic_list(['Pyth...
933
train
Write a function to convert camel case string to snake case string by using regex.
[ "assert camel_to_snake('GoogleAssistant') == 'google_assistant'", "assert camel_to_snake('ChromeCast') == 'chrome_cast'", "assert camel_to_snake('QuadCore') == 'quad_core'" ]
[]
import re def camel_to_snake(text): ''' Write a function to convert camel case string to snake case string by using regex. >>> camel_to_snake('GoogleAssistant') 'google_assistant' >>> camel_to_snake('ChromeCast') 'chrome_cast' >>> camel_to_snake('QuadCore') 'quad_core' '''
```python import re def camel_to_snake(text): ''' Write a function to convert camel case string to snake case string by using regex. >>> camel_to_snake('GoogleAssistant') 'google_assistant' >>> camel_to_snake('ChromeCast') 'chrome_cast' >>> camel_to_snake('QuadCore') 'quad_core' ''' str1 = re.sub('(.)...
[ { "role": "user", "content": "import re\ndef camel_to_snake(text):\n\t''' Write a function to convert camel case string to snake case string by using regex.\n\t>>> camel_to_snake('GoogleAssistant')\n\t'google_assistant'\n\t>>> camel_to_snake('ChromeCast')\n\t'chrome_cast'\n\t>>> camel_to_snake('QuadCore')\n...
934
train
Write a function to find the nth delannoy number.
[ "assert dealnnoy_num(3, 4) == 129", "assert dealnnoy_num(3, 3) == 63", "assert dealnnoy_num(4, 5) == 681" ]
[]
def dealnnoy_num(n, m): ''' Write a function to find the nth delannoy number. >>> dealnnoy_num(3, 4) 129 >>> dealnnoy_num(3, 3) 63 >>> dealnnoy_num(4, 5) 681 '''
```python def dealnnoy_num(n, m): ''' Write a function to find the nth delannoy number. >>> dealnnoy_num(3, 4) 129 >>> dealnnoy_num(3, 3) 63 >>> dealnnoy_num(4, 5) 681 ''' if (m == 0 or n == 0) : return 1 return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1) ```
[ { "role": "user", "content": "def dealnnoy_num(n, m): \n\t''' Write a function to find the nth delannoy number.\n\t>>> dealnnoy_num(3, 4)\n\t129\n\t>>> dealnnoy_num(3, 3)\n\t63\n\t>>> dealnnoy_num(4, 5)\n\t681\n\t'''" }, { "role": "assistant", "content": "```python\ndef dealnnoy_num(n, m): \n\t'...
935
train
Write a function to calculate the sum of series 1²+2²+3²+….+n².
[ "assert series_sum(6)==91", "assert series_sum(7)==140", "assert series_sum(12)==650" ]
[]
def series_sum(number): ''' Write a function to calculate the sum of series 1²+2²+3²+….+n². >>> series_sum(6) 91 >>> series_sum(7) 140 >>> series_sum(12) 650 '''
```python def series_sum(number): ''' Write a function to calculate the sum of series 1²+2²+3²+….+n². >>> series_sum(6) 91 >>> series_sum(7) 140 >>> series_sum(12) 650 ''' total = 0 total = (number * (number + 1) * (2 * number + 1)) / 6 return total ```
[ { "role": "user", "content": "def series_sum(number):\n\t''' Write a function to calculate the sum of series 1²+2²+3²+….+n².\n\t>>> series_sum(6)\n\t91\n\t>>> series_sum(7)\n\t140\n\t>>> series_sum(12)\n\t650\n\t'''" }, { "role": "assistant", "content": "```python\ndef series_sum(number):\n ''' ...
936
train
Write a function to re-arrange the given tuples based on the given ordered list.
[ "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), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]", "assert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)], [2, 5, 3, 6]) == [...
[]
def re_arrange_tuples(test_list, ord_list): ''' Write a function to re-arrange the given tuples based on the given ordered list. >>> re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) [(1, 9), (4, 3), (2, 10), (3, 2)] >>> re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) [(3, 11),...
```python def re_arrange_tuples(test_list, ord_list): ''' Write a function to re-arrange the given tuples based on the given ordered list. >>> re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) [(1, 9), (4, 3), (2, 10), (3, 2)] >>> re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, ...
[ { "role": "user", "content": "def re_arrange_tuples(test_list, ord_list):\n\t''' Write a function to re-arrange the given tuples based on the given ordered list.\n\t>>> re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3])\n\t[(1, 9), (4, 3), (2, 10), (3, 2)]\n\t>>> re_arrange_tuples([(5, 4), (...
937
train
Write a function to count the most common character in a given string.
[ "assert max_char(\"hello world\")==('l')", "assert max_char(\"hello \")==('l')", "assert max_char(\"python pr\")==('p')" ]
[]
from collections import Counter def max_char(str1): ''' Write a function to count the most common character in a given string. >>> max_char('hello world') 'l' >>> max_char('hello ') 'l' >>> max_char('python pr') 'p' '''
```python from collections import Counter def max_char(str1): ''' Write a function to count the most common character in a given string. >>> max_char('hello world') 'l' >>> max_char('hello ') 'l' >>> max_char('python pr') 'p' ''' temp = Counter(str1) max_char = max(temp, key = t...
[ { "role": "user", "content": "from collections import Counter\ndef max_char(str1):\n\t''' Write a function to count the most common character in a given string.\n\t>>> max_char('hello world')\n\t'l'\n\t>>> max_char('hello ')\n\t'l'\n\t>>> max_char('python pr')\n\t'p'\n\t'''" }, { "role": "assistant"...
938
train
Write a function to find three closest elements from three sorted arrays.
[ "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],3,5,5) == (24, 22, 23)", "assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)" ]
[]
import sys def find_closet(A, B, C, p, q, r): ''' Write a function to find three closest elements from three sorted arrays. >>> find_closet([1, 4, 10], [2, 15, 20], [10, 12], 3, 3, 2) (10, 15, 10) >>> find_closet([20, 24, 100], [2, 19, 22, 79, 800], [10, 12, 23, 24, 119], 3, 5, 5) (24, 22, 23) >>> find_closet([2...
```python import sys def find_closet(A, B, C, p, q, r): ''' Write a function to find three closest elements from three sorted arrays. >>> find_closet([1, 4, 10], [2, 15, 20], [10, 12], 3, 3, 2) (10, 15, 10) >>> find_closet([20, 24, 100], [2, 19, 22, 79, 800], [10, 12, 23, 24, 119], 3, 5, 5) (24, 22, 23) >>> find...
[ { "role": "user", "content": "import sys\ndef find_closet(A, B, C, p, q, r): \n\t''' Write a function to find three closest elements from three sorted arrays.\n\t>>> find_closet([1, 4, 10], [2, 15, 20], [10, 12], 3, 3, 2)\n\t(10, 15, 10)\n\t>>> find_closet([20, 24, 100], [2, 19, 22, 79, 800], [10, 12, 23, 2...
939
train
Write a function to sort a list of dictionaries using lambda function.
[ "assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}...
[]
def sorted_models(models): ''' Write a function to sort a list of dictionaries using lambda function. >>> sorted_models([{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]) [{'make': 'Nokia', 'model': 216, 'color': 'Bl...
```python def sorted_models(models): ''' Write a function to sort a list of dictionaries using lambda function. >>> sorted_models([{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]) [{'make': 'Nokia', 'model': 216, 'c...
[ { "role": "user", "content": "def sorted_models(models):\n\t''' Write a function to sort a list of dictionaries using lambda function.\n\t>>> sorted_models([{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}])\...
940
train
Write a function to sort the given array by using heap sort.
[ "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]) == [15, 21, 29, 65, 78]" ]
[]
def heap_sort(arr): ''' Write a function to sort the given array by using heap sort. >>> heap_sort([12, 2, 4, 5, 2, 3]) [2, 2, 3, 4, 5, 12] >>> heap_sort([32, 14, 5, 6, 7, 19]) [5, 6, 7, 14, 19, 32] >>> heap_sort([21, 15, 29, 78, 65]) [15, 21, 29, 65, 78] '''
```python def heap_sort(arr): ''' Write a function to sort the given array by using heap sort. >>> heap_sort([12, 2, 4, 5, 2, 3]) [2, 2, 3, 4, 5, 12] >>> heap_sort([32, 14, 5, 6, 7, 19]) [5, 6, 7, 14, 19, 32] >>> heap_sort([21, 15, 29, 78, 65]) [15, 21, 29, 65, 78] ''' heapify(arr) ...
[ { "role": "user", "content": "def heap_sort(arr):\n\t''' Write a function to sort the given array by using heap sort.\n\t>>> heap_sort([12, 2, 4, 5, 2, 3])\n\t[2, 2, 3, 4, 5, 12]\n\t>>> heap_sort([32, 14, 5, 6, 7, 19])\n\t[5, 6, 7, 14, 19, 32]\n\t>>> heap_sort([21, 15, 29, 78, 65])\n\t[15, 21, 29, 65, 78]\n...
941
train
Write a function to count the elements in a list until an element is a tuple.
[ "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" ]
[]
def count_elim(num): ''' Write a function to count the elements in a list until an element is a tuple. >>> count_elim([10, 20, 30, (10, 20), 40]) 3 >>> count_elim([10, (20, 30), (10, 20), 40]) 1 >>> count_elim([(10, (20, 30, (10, 20), 40))]) 0 '''
```python def count_elim(num): ''' Write a function to count the elements in a list until an element is a tuple. >>> count_elim([10, 20, 30, (10, 20), 40]) 3 >>> count_elim([10, (20, 30), (10, 20), 40]) 1 >>> count_elim([(10, (20, 30, (10, 20), 40))]) 0 ''' count_elim = 0 for n in num: if isinst...
[ { "role": "user", "content": "def count_elim(num):\n\t''' Write a function to count the elements in a list until an element is a tuple.\n\t>>> count_elim([10, 20, 30, (10, 20), 40])\n\t3\n\t>>> count_elim([10, (20, 30), (10, 20), 40])\n\t1\n\t>>> count_elim([(10, (20, 30, (10, 20), 40))])\n\t0\n\t'''" }, ...
942
train
Write a function to check if any list element is present in the given list.
[ "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, 2, 1, 4, 5), [9, 8, 7, 6]) == False" ]
[]
def check_element(test_tup, check_list): ''' Write a function to check if any list element is present in the given list. >>> check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) True >>> check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) True >>> check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) False '''
```python def check_element(test_tup, check_list): ''' Write a function to check if any list element is present in the given list. >>> check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) True >>> check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) True >>> check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) False ''' re...
[ { "role": "user", "content": "def check_element(test_tup, check_list):\n\t''' Write a function to check if any list element is present in the given list.\n\t>>> check_element((4, 5, 7, 9, 3), [6, 7, 10, 11])\n\tTrue\n\t>>> check_element((1, 2, 3, 4), [4, 6, 7, 8, 9])\n\tTrue\n\t>>> check_element((3, 2, 1, 4...
943
train
Write a function to combine two given sorted lists using heapq module.
[ "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, 11])==[1,2,3,5,5,6,7,8,9,11]", "assert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]" ]
[]
from heapq import merge def combine_lists(num1,num2): ''' Write a function to combine two given sorted lists using heapq module. >>> 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] >>> combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11]) [1, 2, 3, 5, 5, 6, 7, 8, 9, 11] >...
```python from heapq import merge def combine_lists(num1,num2): ''' Write a function to combine two given sorted lists using heapq module. >>> 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] >>> combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11]) [1, 2, 3, 5, 5, 6, ...
[ { "role": "user", "content": "from heapq import merge\ndef combine_lists(num1,num2):\n\t''' Write a function to combine two given sorted lists using heapq module.\n\t>>> combine_lists([1, 3, 5, 7, 9, 11], [0, 2, 4, 6, 8, 10])\n\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n\t>>> combine_lists([1, 3, 5, 6, 8, 9],...
944
train
Write a function to separate and print the numbers and their position of a given string.
[ "assert num_position(\"there are 70 flats in this apartment\")==10", "assert num_position(\"every adult have 32 teeth\")==17", "assert num_position(\"isha has 79 chocolates in her bag\")==9" ]
[]
import re def num_position(text): ''' Write a function to separate and print the numbers and their position of a given string. >>> num_position('there are 70 flats in this apartment') 10 >>> num_position('every adult have 32 teeth') 17 >>> num_position('isha has 79 chocolates in her bag') 9 '''
```python import re def num_position(text): ''' Write a function to separate and print the numbers and their position of a given string. >>> num_position('there are 70 flats in this apartment') 10 >>> num_position('every adult have 32 teeth') 17 >>> num_position('isha has 79 chocolates in her bag') 9 ''' for m...
[ { "role": "user", "content": "import re\ndef num_position(text):\n\t''' Write a function to separate and print the numbers and their position of a given string.\n\t>>> num_position('there are 70 flats in this apartment')\n\t10\n\t>>> num_position('every adult have 32 teeth')\n\t17\n\t>>> num_position('isha ...
945
train
Write a function to convert the given tuples into set.
[ "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'}" ]
[]
def tuple_to_set(t): ''' Write a function to convert the given tuples into set. >>> tuple_to_set(('x', 'y', 'z')) {'y', 'x', 'z'} >>> tuple_to_set(('a', 'b', 'c')) {'c', 'a', 'b'} >>> tuple_to_set(('z', 'd', 'e')) {'d', 'e', 'z'} '''
```python def tuple_to_set(t): ''' Write a function to convert the given tuples into set. >>> tuple_to_set(('x', 'y', 'z')) {'y', 'x', 'z'} >>> tuple_to_set(('a', 'b', 'c')) {'c', 'a', 'b'} >>> tuple_to_set(('z', 'd', 'e')) {'d', 'e', 'z'} ''' s = set(t) return (s) ```
[ { "role": "user", "content": "def tuple_to_set(t):\n\t''' Write a function to convert the given tuples into set.\n\t>>> tuple_to_set(('x', 'y', 'z'))\n\t{'y', 'x', 'z'}\n\t>>> tuple_to_set(('a', 'b', 'c'))\n\t{'c', 'a', 'b'}\n\t>>> tuple_to_set(('z', 'd', 'e'))\n\t{'d', 'e', 'z'}\n\t'''" }, { "role"...
946
train
Write a function to find the most common elements and their counts of a specified text.
[ "assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)] ", "assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]", "assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]" ]
[]
from collections import Counter def most_common_elem(s,a): ''' Write a function to find the most common elements and their counts of a specified text. >>> most_common_elem('lkseropewdssafsdfafkpwe', 3) [('s', 4), ('e', 3), ('f', 3)] >>> most_common_elem('lkseropewdssafsdfafkpwe', 2) [('s', 4), ('e', 3)] >>> most_...
```python from collections import Counter def most_common_elem(s,a): ''' Write a function to find the most common elements and their counts of a specified text. >>> most_common_elem('lkseropewdssafsdfafkpwe', 3) [('s', 4), ('e', 3), ('f', 3)] >>> most_common_elem('lkseropewdssafsdfafkpwe', 2) [('s', 4), ('e',...
[ { "role": "user", "content": "from collections import Counter\ndef most_common_elem(s,a):\n\t''' Write a function to find the most common elements and their counts of a specified text.\n\t>>> most_common_elem('lkseropewdssafsdfafkpwe', 3)\n\t[('s', 4), ('e', 3), ('f', 3)]\n\t>>> most_common_elem('lkseropewd...
947
train
Write a python function to find the length of the shortest word.
[ "assert len_log([\"win\",\"lose\",\"great\"]) == 3", "assert len_log([\"a\",\"ab\",\"abc\"]) == 1", "assert len_log([\"12\",\"12\",\"1234\"]) == 2" ]
[]
def len_log(list1): ''' Write a python function to find the length of the shortest word. >>> len_log(['win', 'lose', 'great']) 3 >>> len_log(['a', 'ab', 'abc']) 1 >>> len_log(['12', '12', '1234']) 2 '''
```python def len_log(list1): ''' Write a python function to find the length of the shortest word. >>> len_log(['win', 'lose', 'great']) 3 >>> len_log(['a', 'ab', 'abc']) 1 >>> len_log(['12', '12', '1234']) 2 ''' min=len(list1[0]) for i in list1: if len(i)<min: ...
[ { "role": "user", "content": "def len_log(list1):\n\t''' Write a python function to find the length of the shortest word.\n\t>>> len_log(['win', 'lose', 'great'])\n\t3\n\t>>> len_log(['a', 'ab', 'abc'])\n\t1\n\t>>> len_log(['12', '12', '1234'])\n\t2\n\t'''" }, { "role": "assistant", "content": "...
948
train
Write a function to get an item of a tuple.
[ "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\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),-3)==('r')" ]
[]
def get_item(tup1,index): ''' Write a function to get an item of a tuple. >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), 3) 'e' >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), -4) 'u' >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), -3) 'r' '''
```python def get_item(tup1,index): ''' Write a function to get an item of a tuple. >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), 3) 'e' >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), -4) 'u' >>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), -3) 'r' ''' it...
[ { "role": "user", "content": "def get_item(tup1,index):\n\t''' Write a function to get an item of a tuple.\n\t>>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), 3)\n\t'e'\n\t>>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u', 'r', 'c', 'e'), -4)\n\t'u'\n\t>>> get_item(('w', 3, 'r', 'e', 's', 'o', 'u'...
949
train
Write a function to sort the given tuple list basis the total digits in tuple.
[ "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([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234, 334)]'", "assert sort_list([(34, 4, 61, 723), (1, 2), (145,), (13...
[]
def count_digs(tup): ''' Write a function to sort the given tuple list basis the total digits in tuple. >>> sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)]) '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]' >>> sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)]) '[(1, 2), (3, 4, 8), (12343...
```python def count_digs(tup): ''' Write a function to sort the given tuple list basis the total digits in tuple. >>> sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)]) '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]' >>> sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)]) '[(1, 2), (3...
[ { "role": "user", "content": "def count_digs(tup):\n\t''' Write a function to sort the given tuple list basis the total digits in tuple.\n\t>>> sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)])\n\t'[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'\n\t>>> sort_list([(3, 4, 8), (1, 2), (1234335,...
950
train
Write a function to display sign of the chinese zodiac for given year.
[ "assert chinese_zodiac(1997)==('Ox')", "assert chinese_zodiac(1998)==('Tiger')", "assert chinese_zodiac(1994)==('Dog')" ]
[]
def chinese_zodiac(year): ''' Write a function to display sign of the chinese zodiac for given year. >>> chinese_zodiac(1997) 'Ox' >>> chinese_zodiac(1998) 'Tiger' >>> chinese_zodiac(1994) 'Dog' '''
```python def chinese_zodiac(year): ''' Write a function to display sign of the chinese zodiac for given year. >>> chinese_zodiac(1997) 'Ox' >>> chinese_zodiac(1998) 'Tiger' >>> chinese_zodiac(1994) 'Dog' ''' if (year - 2000) % 12 == 0: sign = 'Dragon' elif (year - 2000) % 12 == 1: sign = 'Snake' e...
[ { "role": "user", "content": "def chinese_zodiac(year):\n\t''' Write a function to display sign of the chinese zodiac for given year.\n\t>>> chinese_zodiac(1997)\n\t'Ox'\n\t>>> chinese_zodiac(1998)\n\t'Tiger'\n\t>>> chinese_zodiac(1994)\n\t'Dog'\n\t'''" }, { "role": "assistant", "content": "```p...
951
train
Write a function to find the maximum of similar indices in two lists of tuples.
[ "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), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]", "assert max_similar_indices([(4, 6), (8, 9), (7, 3)],[(7, 6), (10, 12), (10, 16)]) == ...
[]
def max_similar_indices(test_list1, test_list2): ''' Write a function to find the maximum of similar indices in two lists of tuples. >>> max_similar_indices([(2, 4), (6, 7), (5, 1)], [(5, 4), (8, 10), (8, 14)]) [(5, 4), (8, 10), (8, 14)] >>> max_similar_indices([(3, 5), (7, 8), (6, 2)], [(6, 5), (9, 11), (9, 15)]) ...
```python def max_similar_indices(test_list1, test_list2): ''' Write a function to find the maximum of similar indices in two lists of tuples. >>> max_similar_indices([(2, 4), (6, 7), (5, 1)], [(5, 4), (8, 10), (8, 14)]) [(5, 4), (8, 10), (8, 14)] >>> max_similar_indices([(3, 5), (7, 8), (6, 2)], [(6, 5), (9, 1...
[ { "role": "user", "content": "def max_similar_indices(test_list1, test_list2):\n\t''' Write a function to find the maximum of similar indices in two lists of tuples.\n\t>>> max_similar_indices([(2, 4), (6, 7), (5, 1)], [(5, 4), (8, 10), (8, 14)])\n\t[(5, 4), (8, 10), (8, 14)]\n\t>>> max_similar_indices([(3,...
952
train
Write a function to compute the value of ncr mod p.
[ "assert nCr_mod_p(10, 2, 13) == 6", "assert nCr_mod_p(11, 3, 14) == 11", "assert nCr_mod_p(18, 14, 19) == 1" ]
[]
def nCr_mod_p(n, r, p): ''' Write a function to compute the value of ncr mod p. >>> nCr_mod_p(10, 2, 13) 6 >>> nCr_mod_p(11, 3, 14) 11 >>> nCr_mod_p(18, 14, 19) 1 '''
```python def nCr_mod_p(n, r, p): ''' Write a function to compute the value of ncr mod p. >>> nCr_mod_p(10, 2, 13) 6 >>> nCr_mod_p(11, 3, 14) 11 >>> nCr_mod_p(18, 14, 19) 1 ''' if (r > n- r): r = n - r C = [0 for i in range(r + 1)] C[0] = 1 for i in range(1, n + 1): for j in range(min(i, r), 0, -1...
[ { "role": "user", "content": "def nCr_mod_p(n, r, p): \n\t''' Write a function to compute the value of ncr mod p.\n\t>>> nCr_mod_p(10, 2, 13)\n\t6\n\t>>> nCr_mod_p(11, 3, 14)\n\t11\n\t>>> nCr_mod_p(18, 14, 19)\n\t1\n\t'''" }, { "role": "assistant", "content": "```python\ndef nCr_mod_p(n, r, p): ...
953
train
Write a python function to find the minimun number of subsets with distinct elements.
[ "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" ]
[]
def subset(ar, n): ''' Write a python function to find the minimun number of subsets with distinct elements. >>> subset([1, 2, 3, 4], 4) 1 >>> subset([5, 6, 9, 3, 4, 3, 4], 7) 2 >>> subset([1, 2, 3], 3) 1 '''
```python def subset(ar, n): ''' Write a python function to find the minimun number of subsets with distinct elements. >>> subset([1, 2, 3, 4], 4) 1 >>> subset([5, 6, 9, 3, 4, 3, 4], 7) 2 >>> subset([1, 2, 3], 3) 1 ''' res = 0 ar.sort() for i in range(0, n) : count...
[ { "role": "user", "content": "def subset(ar, n): \n\t''' Write a python function to find the minimun number of subsets with distinct elements.\n\t>>> subset([1, 2, 3, 4], 4)\n\t1\n\t>>> subset([5, 6, 9, 3, 4, 3, 4], 7)\n\t2\n\t>>> subset([1, 2, 3], 3)\n\t1\n\t'''" }, { "role": "assistant", "cont...
954
train
Write a function that gives profit amount if the given amount has profit else return none.
[ "assert profit_amount(1500,1200)==300", "assert profit_amount(100,200)==None", "assert profit_amount(2000,5000)==None" ]
[]
def profit_amount(actual_cost,sale_amount): ''' Write a function that gives profit amount if the given amount has profit else return none. >>> profit_amount(1500, 1200) 300 >>> profit_amount(100, 200) None >>> profit_amount(2000, 5000) None '''
```python def profit_amount(actual_cost,sale_amount): ''' Write a function that gives profit amount if the given amount has profit else return none. >>> profit_amount(1500, 1200) 300 >>> profit_amount(100, 200) None >>> profit_amount(2000, 5000) None ''' if(actual_cost > sale_amount): amount = actual_cost...
[ { "role": "user", "content": "def profit_amount(actual_cost,sale_amount): \n\t''' Write a function that gives profit amount if the given amount has profit else return none.\n\t>>> profit_amount(1500, 1200)\n\t300\n\t>>> profit_amount(100, 200)\n\tNone\n\t>>> profit_amount(2000, 5000)\n\tNone\n\t'''" }, ...
955
train
Write a function to find out, if the given number is abundant.
[ "assert is_abundant(12)==True", "assert is_abundant(13)==False", "assert is_abundant(9)==False" ]
[]
def is_abundant(n): ''' Write a function to find out, if the given number is abundant. >>> is_abundant(12) True >>> is_abundant(13) False >>> is_abundant(9) False '''
```python def is_abundant(n): ''' Write a function to find out, if the given number is abundant. >>> is_abundant(12) True >>> is_abundant(13) False >>> is_abundant(9) False ''' fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0]) return fctrsum > n ```
[ { "role": "user", "content": "def is_abundant(n):\n\t''' Write a function to find out, if the given number is abundant.\n\t>>> is_abundant(12)\n\tTrue\n\t>>> is_abundant(13)\n\tFalse\n\t>>> is_abundant(9)\n\tFalse\n\t'''" }, { "role": "assistant", "content": "```python\ndef is_abundant(n):\n ...
956
train
Write a function to split the given string at uppercase letters by using regex.
[ "assert split_list(\"LearnToBuildAnythingWithGoogle\") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']", "assert split_list(\"ApmlifyingTheBlack+DeveloperCommunity\") == ['Apmlifying', 'The', 'Black+', 'Developer', 'Community']", "assert split_list(\"UpdateInTheGoEcoSystem\") == ['Update', 'In', 'The'...
[]
import re def split_list(text): ''' Write a function to split the given string at uppercase letters by using regex. >>> split_list('LearnToBuildAnythingWithGoogle') ['Learn', 'To', 'Build', 'Anything', 'With', 'Google'] >>> split_list('ApmlifyingTheBlack+DeveloperCommunity') ['Apmlifying', 'The', 'Black+', 'Develo...
```python import re def split_list(text): ''' Write a function to split the given string at uppercase letters by using regex. >>> split_list('LearnToBuildAnythingWithGoogle') ['Learn', 'To', 'Build', 'Anything', 'With', 'Google'] >>> split_list('ApmlifyingTheBlack+DeveloperCommunity') ['Apmlifying', 'The', 'B...
[ { "role": "user", "content": "import re\ndef split_list(text):\n\t''' Write a function to split the given string at uppercase letters by using regex.\n\t>>> split_list('LearnToBuildAnythingWithGoogle')\n\t['Learn', 'To', 'Build', 'Anything', 'With', 'Google']\n\t>>> split_list('ApmlifyingTheBlack+DeveloperC...
957
train
Write a python function to get the position of rightmost set bit.
[ "assert get_First_Set_Bit_Pos(12) == 3", "assert get_First_Set_Bit_Pos(18) == 2", "assert get_First_Set_Bit_Pos(16) == 5" ]
[]
import math def get_First_Set_Bit_Pos(n): ''' Write a python function to get the position of rightmost set bit. >>> get_First_Set_Bit_Pos(12) 3 >>> get_First_Set_Bit_Pos(18) 2 >>> get_First_Set_Bit_Pos(16) 5 '''
```python import math def get_First_Set_Bit_Pos(n): ''' Write a python function to get the position of rightmost set bit. >>> get_First_Set_Bit_Pos(12) 3 >>> get_First_Set_Bit_Pos(18) 2 >>> get_First_Set_Bit_Pos(16) 5 ''' return math.log2(n&-n)+1 ```
[ { "role": "user", "content": "import math\ndef get_First_Set_Bit_Pos(n):\n\t''' Write a python function to get the position of rightmost set bit.\n\t>>> get_First_Set_Bit_Pos(12)\n\t3\n\t>>> get_First_Set_Bit_Pos(18)\n\t2\n\t>>> get_First_Set_Bit_Pos(16)\n\t5\n\t'''" }, { "role": "assistant", "c...
958
train
Write a function to convert an integer into a roman numeral.
[ "assert int_to_roman(1)==(\"I\")", "assert int_to_roman(50)==(\"L\")", "assert int_to_roman(4)==(\"IV\")" ]
[]
def int_to_roman( num): ''' Write a function to convert an integer into a roman numeral. >>> int_to_roman(1) 'I' >>> int_to_roman(50) 'L' >>> int_to_roman(4) 'IV' '''
```python def int_to_roman( num): ''' Write a function to convert an integer into a roman numeral. >>> int_to_roman(1) 'I' >>> int_to_roman(50) 'L' >>> int_to_roman(4) 'IV' ''' val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1] syb =...
[ { "role": "user", "content": "def int_to_roman( num):\n\t''' Write a function to convert an integer into a roman numeral.\n\t>>> int_to_roman(1)\n\t'I'\n\t>>> int_to_roman(50)\n\t'L'\n\t>>> int_to_roman(4)\n\t'IV'\n\t'''" }, { "role": "assistant", "content": "```python\ndef int_to_roman( num):\n...
959
train
Write a python function to find the average of a list.
[ "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" ]
[]
def Average(lst): ''' Write a python function to find the average of a list. >>> Average([15, 9, 55, 41, 35, 20, 62, 49]) 35.75 >>> Average([4, 5, 1, 2, 9, 7, 10, 8]) 5.75 >>> Average([1, 2, 3]) 2 '''
```python def Average(lst): ''' Write a python function to find the average of a list. >>> Average([15, 9, 55, 41, 35, 20, 62, 49]) 35.75 >>> Average([4, 5, 1, 2, 9, 7, 10, 8]) 5.75 >>> Average([1, 2, 3]) 2 ''' return sum(lst) / len(lst) ```
[ { "role": "user", "content": "def Average(lst): \n\t''' Write a python function to find the average of a list.\n\t>>> Average([15, 9, 55, 41, 35, 20, 62, 49])\n\t35.75\n\t>>> Average([4, 5, 1, 2, 9, 7, 10, 8])\n\t5.75\n\t>>> Average([1, 2, 3])\n\t2\n\t'''" }, { "role": "assistant", "content": "`...
960
train
Write a function to solve tiling problem.
[ "assert get_noOfways(4)==3", "assert get_noOfways(3)==2", "assert get_noOfways(5)==5" ]
[]
def get_noOfways(n): ''' Write a function to solve tiling problem. >>> get_noOfways(4) 3 >>> get_noOfways(3) 2 >>> get_noOfways(5) 5 '''
```python def get_noOfways(n): ''' Write a function to solve tiling problem. >>> get_noOfways(4) 3 >>> get_noOfways(3) 2 >>> get_noOfways(5) 5 ''' if (n == 0): return 0; if (n == 1): return 1; return get_noOfways(n - 1) + get_noOfways(n - 2); ```
[ { "role": "user", "content": "def get_noOfways(n):\n\t''' Write a function to solve tiling problem.\n\t>>> get_noOfways(4)\n\t3\n\t>>> get_noOfways(3)\n\t2\n\t>>> get_noOfways(5)\n\t5\n\t'''" }, { "role": "assistant", "content": "```python\ndef get_noOfways(n):\n ''' Write a function to solve...
961
train
Write a function to convert a roman numeral to an integer.
[ "assert roman_to_int('MMMCMLXXXVI')==3986", "assert roman_to_int('MMMM')==4000", "assert roman_to_int('C')==100" ]
[]
def roman_to_int(s): ''' Write a function to convert a roman numeral to an integer. >>> roman_to_int('MMMCMLXXXVI') 3986 >>> roman_to_int('MMMM') 4000 >>> roman_to_int('C') 100 '''
```python def roman_to_int(s): ''' Write a function to convert a roman numeral to an integer. >>> roman_to_int('MMMCMLXXXVI') 3986 >>> roman_to_int('MMMM') 4000 >>> roman_to_int('C') 100 ''' rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D...
[ { "role": "user", "content": "def roman_to_int(s):\n\t''' Write a function to convert a roman numeral to an integer.\n\t>>> roman_to_int('MMMCMLXXXVI')\n\t3986\n\t>>> roman_to_int('MMMM')\n\t4000\n\t>>> roman_to_int('C')\n\t100\n\t'''" }, { "role": "assistant", "content": "```python\ndef roman_t...
962
train
Write a python function to find the sum of all even natural numbers within the range l and r.
[ "assert sum_Even(2,5) == 6", "assert sum_Even(3,8) == 18", "assert sum_Even(4,6) == 10" ]
[]
def sum_Natural(n): ''' Write a python function to find the sum of all even natural numbers within the range l and r. >>> sum_Even(2, 5) 6 >>> sum_Even(3, 8) 18 >>> sum_Even(4, 6) 10 '''
```python def sum_Natural(n): ''' Write a python function to find the sum of all even natural numbers within the range l and r. >>> sum_Even(2, 5) 6 >>> sum_Even(3, 8) 18 >>> sum_Even(4, 6) 10 ''' sum = (n * (n + 1)) return int(sum) def sum_Even(l,r): return (sum_Natural(...
[ { "role": "user", "content": "def sum_Natural(n): \n\t''' Write a python function to find the sum of all even natural numbers within the range l and r.\n\t>>> sum_Even(2, 5)\n\t6\n\t>>> sum_Even(3, 8)\n\t18\n\t>>> sum_Even(4, 6)\n\t10\n\t'''" }, { "role": "assistant", "content": "```python\ndef ...
963
train
Write a function to calculate the discriminant value.
[ "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)" ]
[]
def discriminant_value(x,y,z): ''' Write a function to calculate the discriminant value. >>> discriminant_value(4, 8, 2) ('Two solutions', 32) >>> discriminant_value(5, 7, 9) ('no real solution', -131) >>> discriminant_value(0, 0, 9) ('one solution', 0) '''
```python def discriminant_value(x,y,z): ''' Write a function to calculate the discriminant value. >>> discriminant_value(4, 8, 2) ('Two solutions', 32) >>> discriminant_value(5, 7, 9) ('no real solution', -131) >>> discriminant_value(0, 0, 9) ('one solution', 0) ''' discriminant = (...
[ { "role": "user", "content": "def discriminant_value(x,y,z):\n\t''' Write a function to calculate the discriminant value.\n\t>>> discriminant_value(4, 8, 2)\n\t('Two solutions', 32)\n\t>>> discriminant_value(5, 7, 9)\n\t('no real solution', -131)\n\t>>> discriminant_value(0, 0, 9)\n\t('one solution', 0)\n\t...
964
train
Write a python function to check whether the length of the word is even or not.
[ "assert word_len(\"program\") == False", "assert word_len(\"solution\") == True", "assert word_len(\"data\") == True" ]
[]
def word_len(s): ''' Write a python function to check whether the length of the word is even or not. >>> word_len('program') False >>> word_len('solution') True >>> word_len('data') True '''
```python def word_len(s): ''' Write a python function to check whether the length of the word is even or not. >>> word_len('program') False >>> word_len('solution') True >>> word_len('data') True ''' s = s.split(' ') for word in s: if len(word)%2==0: ...
[ { "role": "user", "content": "def word_len(s): \n\t''' Write a python function to check whether the length of the word is even or not.\n\t>>> word_len('program')\n\tFalse\n\t>>> word_len('solution')\n\tTrue\n\t>>> word_len('data')\n\tTrue\n\t'''" }, { "role": "assistant", "content": "```python\n...
965
train
Write a function to convert camel case string to snake case string.
[ "assert camel_to_snake('PythonProgram')==('python_program')", "assert camel_to_snake('pythonLanguage')==('python_language')", "assert camel_to_snake('ProgrammingLanguage')==('programming_language')" ]
[]
def camel_to_snake(text): ''' Write a function to convert camel case string to snake case string. >>> camel_to_snake('PythonProgram') 'python_program' >>> camel_to_snake('pythonLanguage') 'python_language' >>> camel_to_snake('ProgrammingLanguage') 'programming_language' '''
```python def camel_to_snake(text): ''' Write a function to convert camel case string to snake case string. >>> camel_to_snake('PythonProgram') 'python_program' >>> camel_to_snake('pythonLanguage') 'python_language' >>> camel_to_snake('ProgrammingLanguage') 'progr...
[ { "role": "user", "content": "def camel_to_snake(text):\n\t''' Write a function to convert camel case string to snake case string.\n\t>>> camel_to_snake('PythonProgram')\n\t'python_program'\n\t>>> camel_to_snake('pythonLanguage')\n\t'python_language'\n\t>>> camel_to_snake('ProgrammingLanguage')\n\t'programm...
966
train
Write a function to remove an empty tuple from a list of tuples.
[ "assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd'] ", "assert remove_empty([(), (), ('',), (\"python\"), (\"program\")])==[('',), (\"python\"), (\"program\")] ", "assert remove_empty([(), (), ('',), (\"java\")])==[('',),(\"java\") ] " ]
[]
def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')] ''' Write a function to remove an empty tuple from a list of tuples. >>> remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), 'd']) [('',), ('a', 'b'), ('a', 'b', 'c'), 'd'] >>> remove_empty([(), (), ('',), 'python', 'program'])...
```python def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')] ''' Write a function to remove an empty tuple from a list of tuples. >>> remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), 'd']) [('',), ('a', 'b'), ('a', 'b', 'c'), 'd'] >>> remove_empty([(), (), ('',), 'py...
[ { "role": "user", "content": "def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]\n\t''' Write a function to remove an empty tuple from a list of tuples.\n\t>>> remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), 'd'])\n\t[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']\n\t>>> ...
967
train
Write a python function to accept the strings which contains all vowels.
[ "assert check(\"SEEquoiaL\") == 'accepted'", "assert check('program') == \"not accepted\"", "assert check('fine') == \"not accepted\"" ]
[]
def check(string): ''' Write a python function to accept the strings which contains all vowels. >>> check('SEEquoiaL') 'accepted' >>> check('program') 'not accepted' >>> check('fine') 'not accepted' '''
```python def check(string): ''' Write a python function to accept the strings which contains all vowels. >>> check('SEEquoiaL') 'accepted' >>> check('program') 'not accepted' >>> check('fine') 'not accepted' ''' if len(set(string).intersection("AEIOUaeiou"))>=5: return ('accepted') else: ...
[ { "role": "user", "content": "def check(string): \n\t''' Write a python function to accept the strings which contains all vowels.\n\t>>> check('SEEquoiaL')\n\t'accepted'\n\t>>> check('program')\n\t'not accepted'\n\t>>> check('fine')\n\t'not accepted'\n\t'''" }, { "role": "assistant", "content": ...
968
train
Write a python function to find maximum possible value for the given periodic function.
[ "assert floor_Max(11,10,9) == 9", "assert floor_Max(5,7,4) == 2", "assert floor_Max(2,2,1) == 1" ]
[]
def floor_Max(A,B,N): ''' Write a python function to find maximum possible value for the given periodic function. >>> floor_Max(11, 10, 9) 9 >>> floor_Max(5, 7, 4) 2 >>> floor_Max(2, 2, 1) 1 '''
```python def floor_Max(A,B,N): ''' Write a python function to find maximum possible value for the given periodic function. >>> floor_Max(11, 10, 9) 9 >>> floor_Max(5, 7, 4) 2 >>> floor_Max(2, 2, 1) 1 ''' x = min(B - 1,N) return (A*x) // B ```
[ { "role": "user", "content": "def floor_Max(A,B,N):\n\t''' Write a python function to find maximum possible value for the given periodic function.\n\t>>> floor_Max(11, 10, 9)\n\t9\n\t>>> floor_Max(5, 7, 4)\n\t2\n\t>>> floor_Max(2, 2, 1)\n\t1\n\t'''" }, { "role": "assistant", "content": "```pytho...
969
train
Write a function to join the tuples if they have similar initial elements.
[ "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, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]", "assert join_tuples([(7, 8), (7, 9), (8, 10), (8, 12), (9, 15)] ) == [(7, 8, 9), (8, 10, 12), (9, 15)]" ]
[]
def join_tuples(test_list): ''' Write a function to join the tuples if they have similar initial elements. >>> join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)]) [(5, 6, 7), (6, 8, 10), (7, 13)] >>> join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)]) [(6, 7, 8), (7, 9, 11), (8, 14)] >>> join_tuples([(7, ...
```python def join_tuples(test_list): ''' Write a function to join the tuples if they have similar initial elements. >>> join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)]) [(5, 6, 7), (6, 8, 10), (7, 13)] >>> join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)]) [(6, 7, 8), (7, 9, 11), (8, 14)] >>> j...
[ { "role": "user", "content": "def join_tuples(test_list):\n\t''' Write a function to join the tuples if they have similar initial elements.\n\t>>> join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)])\n\t[(5, 6, 7), (6, 8, 10), (7, 13)]\n\t>>> join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)])\n\t[(6...
970
train
Write a function to find minimum of two numbers.
[ "assert min_of_two(10,20)==10", "assert min_of_two(19,15)==15", "assert min_of_two(-10,-20)==-20" ]
[]
def min_of_two( x, y ): ''' Write a function to find minimum of two numbers. >>> min_of_two(10, 20) 10 >>> min_of_two(19, 15) 15 >>> min_of_two(-10, -20) -20 '''
```python def min_of_two( x, y ): ''' Write a function to find minimum of two numbers. >>> min_of_two(10, 20) 10 >>> min_of_two(19, 15) 15 >>> min_of_two(-10, -20) -20 ''' if x < y: return x return y ```
[ { "role": "user", "content": "def min_of_two( x, y ):\n\t''' Write a function to find minimum of two numbers.\n\t>>> min_of_two(10, 20)\n\t10\n\t>>> min_of_two(19, 15)\n\t15\n\t>>> min_of_two(-10, -20)\n\t-20\n\t'''" }, { "role": "assistant", "content": "```python\ndef min_of_two( x, y ):\n '...
971
train
Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.
[ "assert maximum_segments(7, 5, 2, 5) == 2", "assert maximum_segments(17, 2, 1, 3) == 17", "assert maximum_segments(18, 16, 3, 6) == 6" ]
[]
def maximum_segments(n, a, b, c) : ''' Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n. >>> maximum_segments(7, 5, 2, 5) 2 >>> maximum_segments(17, 2, 1, 3) 17 >>> maximum_segments(18, 16, 3, 6) 6 '''
```python def maximum_segments(n, a, b, c) : ''' Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n. >>> maximum_segments(7, 5, 2, 5) 2 >>> maximum_segments(17, 2, 1, 3) 17 >>> maximum_segments(18, 16, 3, 6) 6 ''' dp = [-1] * (n + 10) dp[0] = 0 for i in ...
[ { "role": "user", "content": "def maximum_segments(n, a, b, c) : \n\t''' Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.\n\t>>> maximum_segments(7, 5, 2, 5)\n\t2\n\t>>> maximum_segments(17, 2, 1, 3)\n\t17\n\t>>> maximum_segments(18, 16, 3, 6)\n\t6\n\t...
972
train
Write a function to concatenate the given two tuples to a nested tuple.
[ "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, 8)) == (4, 5, 6, 8)" ]
[]
def concatenate_nested(test_tup1, test_tup2): ''' Write a function to concatenate the given two tuples to a nested tuple. >>> concatenate_nested((3, 4), (5, 6)) (3, 4, 5, 6) >>> concatenate_nested((1, 2), (3, 4)) (1, 2, 3, 4) >>> concatenate_nested((4, 5), (6, 8)) (4, 5, 6, 8) '''
```python def concatenate_nested(test_tup1, test_tup2): ''' Write a function to concatenate the given two tuples to a nested tuple. >>> concatenate_nested((3, 4), (5, 6)) (3, 4, 5, 6) >>> concatenate_nested((1, 2), (3, 4)) (1, 2, 3, 4) >>> concatenate_nested((4, 5), (6, 8)) (4, 5, 6, 8) ''' res = test...
[ { "role": "user", "content": "def concatenate_nested(test_tup1, test_tup2):\n\t''' Write a function to concatenate the given two tuples to a nested tuple.\n\t>>> concatenate_nested((3, 4), (5, 6))\n\t(3, 4, 5, 6)\n\t>>> concatenate_nested((1, 2), (3, 4))\n\t(1, 2, 3, 4)\n\t>>> concatenate_nested((4, 5), (6,...
973
train
Write a python function to left rotate the string.
[ "assert left_rotate(\"python\",2) == \"thonpy\" ", "assert left_rotate(\"bigdata\",3 ) == \"databig\" ", "assert left_rotate(\"hadoop\",1 ) == \"adooph\" " ]
[]
def left_rotate(s,d): ''' Write a python function to left rotate the string. >>> left_rotate('python', 2) 'thonpy' >>> left_rotate('bigdata', 3) 'databig' >>> left_rotate('hadoop', 1) 'adooph' '''
```python def left_rotate(s,d): ''' Write a python function to left rotate the string. >>> left_rotate('python', 2) 'thonpy' >>> left_rotate('bigdata', 3) 'databig' >>> left_rotate('hadoop', 1) 'adooph' ''' tmp = s[d : ] + s[0 : d] return tmp ```
[ { "role": "user", "content": "def left_rotate(s,d):\n\t''' Write a python function to left rotate the string.\n\t>>> left_rotate('python', 2)\n\t'thonpy'\n\t>>> left_rotate('bigdata', 3)\n\t'databig'\n\t>>> left_rotate('hadoop', 1)\n\t'adooph'\n\t'''" }, { "role": "assistant", "content": "```pyt...
974
train
Write a function to find the minimum total path sum in the given triangle.
[ "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 ], [5, 2, 7 ]]) == 9" ]
[]
def min_sum_path(A): ''' Write a function to find the minimum total path sum in the given triangle. >>> min_sum_path([[2], [3, 9], [1, 6, 7]]) 6 >>> min_sum_path([[2], [3, 7], [8, 5, 6]]) 10 >>> min_sum_path([[3], [6, 4], [5, 2, 7]]) 9 '''
```python def min_sum_path(A): ''' Write a function to find the minimum total path sum in the given triangle. >>> min_sum_path([[2], [3, 9], [1, 6, 7]]) 6 >>> min_sum_path([[2], [3, 7], [8, 5, 6]]) 10 >>> min_sum_path([[3], [6, 4], [5, 2, 7]]) 9 ''' memo = [None] * len(A) n = len(A) - 1 for i in range(len(...
[ { "role": "user", "content": "def min_sum_path(A): \n\t''' Write a function to find the minimum total path sum in the given triangle.\n\t>>> min_sum_path([[2], [3, 9], [1, 6, 7]])\n\t6\n\t>>> min_sum_path([[2], [3, 7], [8, 5, 6]])\n\t10\n\t>>> min_sum_path([[3], [6, 4], [5, 2, 7]])\n\t9\n\t'''" }, { ...