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 |
|---|---|---|---|---|---|---|---|---|
801 | train | Write a python function to count the number of equal numbers from three given integers. | [
"assert test_three_equal(1,1,1) == 3",
"assert test_three_equal(-1,-2,-3) == 0",
"assert test_three_equal(1,2,2) == 2"
] | [] | def test_three_equal(x,y,z):
''' Write a python function to count the number of equal numbers from three given integers.
>>> test_three_equal(1, 1, 1)
3
>>> test_three_equal(-1, -2, -3)
0
>>> test_three_equal(1, 2, 2)
2
''' | ```python
def test_three_equal(x,y,z):
''' Write a python function to count the number of equal numbers from three given integers.
>>> test_three_equal(1, 1, 1)
3
>>> test_three_equal(-1, -2, -3)
0
>>> test_three_equal(1, 2, 2)
2
'''
result= set([x,y,z])
if len(result)==3:
return 0
else:
r... | [
{
"role": "user",
"content": "def test_three_equal(x,y,z):\n\t''' Write a python function to count the number of equal numbers from three given integers.\n\t>>> test_three_equal(1, 1, 1)\n\t3\n\t>>> test_three_equal(-1, -2, -3)\n\t0\n\t>>> test_three_equal(1, 2, 2)\n\t2\n\t'''"
},
{
"role": "assista... | |
802 | train | Write a python function to count the number of rotations required to generate a sorted array. | [
"assert count_Rotation([3,2,1],3) == 1",
"assert count_Rotation([4,5,1,2,3],5) == 2",
"assert count_Rotation([7,8,9,1,2,3],6) == 3"
] | [] | def count_Rotation(arr,n):
''' Write a python function to count the number of rotations required to generate a sorted array.
>>> count_Rotation([3, 2, 1], 3)
1
>>> count_Rotation([4, 5, 1, 2, 3], 5)
2
>>> count_Rotation([7, 8, 9, 1, 2, 3], 6)
3
''' | ```python
def count_Rotation(arr,n):
''' Write a python function to count the number of rotations required to generate a sorted array.
>>> count_Rotation([3, 2, 1], 3)
1
>>> count_Rotation([4, 5, 1, 2, 3], 5)
2
>>> count_Rotation([7, 8, 9, 1, 2, 3], 6)
3
'''
for i in range (1,n): ... | [
{
"role": "user",
"content": "def count_Rotation(arr,n): \n\t''' Write a python function to count the number of rotations required to generate a sorted array.\n\t>>> count_Rotation([3, 2, 1], 3)\n\t1\n\t>>> count_Rotation([4, 5, 1, 2, 3], 5)\n\t2\n\t>>> count_Rotation([7, 8, 9, 1, 2, 3], 6)\n\t3\n\t'''"
... | |
803 | train | Write a python function to check whether the given number is a perfect square or not. | [
"assert is_Perfect_Square(10) == False",
"assert is_Perfect_Square(36) == True",
"assert is_Perfect_Square(14) == False"
] | [] | def is_Perfect_Square(n) :
''' Write a python function to check whether the given number is a perfect square or not.
>>> is_Perfect_Square(10)
False
>>> is_Perfect_Square(36)
True
>>> is_Perfect_Square(14)
False
''' | ```python
def is_Perfect_Square(n) :
''' Write a python function to check whether the given number is a perfect square or not.
>>> is_Perfect_Square(10)
False
>>> is_Perfect_Square(36)
True
>>> is_Perfect_Square(14)
False
'''
i = 1
while (i * i<= n):
if ((n % i == 0) and ... | [
{
"role": "user",
"content": "def is_Perfect_Square(n) :\n\t''' Write a python function to check whether the given number is a perfect square or not.\n\t>>> is_Perfect_Square(10)\n\tFalse\n\t>>> is_Perfect_Square(36)\n\tTrue\n\t>>> is_Perfect_Square(14)\n\tFalse\n\t'''"
},
{
"role": "assistant",
... | |
804 | train | Write a python function to check whether the product of numbers is even or not. | [
"assert is_Product_Even([1,2,3],3) == True",
"assert is_Product_Even([1,2,1,4],4) == True",
"assert is_Product_Even([1,1],2) == False"
] | [] | def is_Product_Even(arr,n):
''' Write a python function to check whether the product of numbers is even or not.
>>> is_Product_Even([1, 2, 3], 3)
True
>>> is_Product_Even([1, 2, 1, 4], 4)
True
>>> is_Product_Even([1, 1], 2)
False
''' | ```python
def is_Product_Even(arr,n):
''' Write a python function to check whether the product of numbers is even or not.
>>> is_Product_Even([1, 2, 3], 3)
True
>>> is_Product_Even([1, 2, 1, 4], 4)
True
>>> is_Product_Even([1, 1], 2)
False
'''
for i in range(0,n):
if ((arr[... | [
{
"role": "user",
"content": "def is_Product_Even(arr,n): \n\t''' Write a python function to check whether the product of numbers is even or not.\n\t>>> is_Product_Even([1, 2, 3], 3)\n\tTrue\n\t>>> is_Product_Even([1, 2, 1, 4], 4)\n\tTrue\n\t>>> is_Product_Even([1, 1], 2)\n\tFalse\n\t'''"
},
{
"role... | |
805 | train | Write a function to find the list in a list of lists whose sum of elements is the highest. | [
"assert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12] ",
"assert max_sum_list([[3,2,1], [6,5,4], [12,11,10]])==[12,11,10] ",
"assert max_sum_list([[2,3,1]])==[2,3,1] "
] | [] | def max_sum_list(lists):
''' Write a function to find the list in a list of lists whose sum of elements is the highest.
>>> max_sum_list([[1, 2, 3], [4, 5, 6], [10, 11, 12], [7, 8, 9]])
[10, 11, 12]
>>> max_sum_list([[3, 2, 1], [6, 5, 4], [12, 11, 10]])
[12, 11, 10]
>>> max_sum_list([[2, 3, 1]])
[2, 3, 1]
''' | ```python
def max_sum_list(lists):
''' Write a function to find the list in a list of lists whose sum of elements is the highest.
>>> max_sum_list([[1, 2, 3], [4, 5, 6], [10, 11, 12], [7, 8, 9]])
[10, 11, 12]
>>> max_sum_list([[3, 2, 1], [6, 5, 4], [12, 11, 10]])
[12, 11, 10]
>>> max_sum_list([[2, 3, 1]])
[2, 3,... | [
{
"role": "user",
"content": "def max_sum_list(lists):\n\t''' Write a function to find the list in a list of lists whose sum of elements is the highest.\n\t>>> max_sum_list([[1, 2, 3], [4, 5, 6], [10, 11, 12], [7, 8, 9]])\n\t[10, 11, 12]\n\t>>> max_sum_list([[3, 2, 1], [6, 5, 4], [12, 11, 10]])\n\t[12, 11, ... | |
806 | train | Write a function to find maximum run of uppercase characters in the given string. | [
"assert max_run_uppercase('GeMKSForGERksISBESt') == 5",
"assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6",
"assert max_run_uppercase('GooGLEFluTTER') == 4"
] | [] | def max_run_uppercase(test_str):
''' Write a function to find maximum run of uppercase characters in the given string.
>>> max_run_uppercase('GeMKSForGERksISBESt')
5
>>> max_run_uppercase('PrECIOusMOVemENTSYT')
6
>>> max_run_uppercase('GooGLEFluTTER')
4
''' | ```python
def max_run_uppercase(test_str):
''' Write a function to find maximum run of uppercase characters in the given string.
>>> max_run_uppercase('GeMKSForGERksISBESt')
5
>>> max_run_uppercase('PrECIOusMOVemENTSYT')
6
>>> max_run_uppercase('GooGLEFluTTER')
4
'''
cnt = 0
res = 0
for idx in ran... | [
{
"role": "user",
"content": "def max_run_uppercase(test_str):\n\t''' Write a function to find maximum run of uppercase characters in the given string.\n\t>>> max_run_uppercase('GeMKSForGERksISBESt')\n\t5\n\t>>> max_run_uppercase('PrECIOusMOVemENTSYT')\n\t6\n\t>>> max_run_uppercase('GooGLEFluTTER')\n\t4\n\t... | |
807 | train | Write a python function to find the first odd number in a given list of numbers. | [
"assert first_odd([1,3,5]) == 1",
"assert first_odd([2,4,1,3]) == 1",
"assert first_odd ([8,9,1]) == 9"
] | [] | def first_odd(nums):
''' Write a python function to find the first odd number in a given list of numbers.
>>> first_odd([1, 3, 5])
1
>>> first_odd([2, 4, 1, 3])
1
>>> first_odd([8, 9, 1])
9
''' | ```python
def first_odd(nums):
''' Write a python function to find the first odd number in a given list of numbers.
>>> first_odd([1, 3, 5])
1
>>> first_odd([2, 4, 1, 3])
1
>>> first_odd([8, 9, 1])
9
'''
first_odd = next((el for el in nums if el%2!=0),-1)
return first_odd
``` | [
{
"role": "user",
"content": "def first_odd(nums):\n\t''' Write a python function to find the first odd number in a given list of numbers.\n\t>>> first_odd([1, 3, 5])\n\t1\n\t>>> first_odd([2, 4, 1, 3])\n\t1\n\t>>> first_odd([8, 9, 1])\n\t9\n\t'''"
},
{
"role": "assistant",
"content": "```python... | |
808 | train | Write a function to check if the given tuples contain the k or not. | [
"assert check_K((10, 4, 5, 6, 8), 6) == True",
"assert check_K((1, 2, 3, 4, 5, 6), 7) == False",
"assert check_K((7, 8, 9, 44, 11, 12), 11) == True"
] | [] | def check_K(test_tup, K):
''' Write a function to check if the given tuples contain the k or not.
>>> check_K((10, 4, 5, 6, 8), 6)
True
>>> check_K((1, 2, 3, 4, 5, 6), 7)
False
>>> check_K((7, 8, 9, 44, 11, 12), 11)
True
''' | ```python
def check_K(test_tup, K):
''' Write a function to check if the given tuples contain the k or not.
>>> check_K((10, 4, 5, 6, 8), 6)
True
>>> check_K((1, 2, 3, 4, 5, 6), 7)
False
>>> check_K((7, 8, 9, 44, 11, 12), 11)
True
'''
res = False
for ele in test_tup:
if ele == K:
res = Tru... | [
{
"role": "user",
"content": "def check_K(test_tup, K):\n\t''' Write a function to check if the given tuples contain the k or not.\n\t>>> check_K((10, 4, 5, 6, 8), 6)\n\tTrue\n\t>>> check_K((1, 2, 3, 4, 5, 6), 7)\n\tFalse\n\t>>> check_K((7, 8, 9, 44, 11, 12), 11)\n\tTrue\n\t'''"
},
{
"role": "assist... | |
809 | train | Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple. | [
"assert check_smaller((1, 2, 3), (2, 3, 4)) == False",
"assert check_smaller((4, 5, 6), (3, 4, 5)) == True",
"assert check_smaller((11, 12, 13), (10, 11, 12)) == True"
] | [] | def check_smaller(test_tup1, test_tup2):
''' Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
>>> check_smaller((1, 2, 3), (2, 3, 4))
False
>>> check_smaller((4, 5, 6), (3, 4, 5))
True
>>> check_smaller((11, 12, 13), (10, 11, 12))
True
''' | ```python
def check_smaller(test_tup1, test_tup2):
''' Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
>>> check_smaller((1, 2, 3), (2, 3, 4))
False
>>> check_smaller((4, 5, 6), (3, 4, 5))
True
>>> check_smaller((11, 12, 13), (10, 11, 12))
... | [
{
"role": "user",
"content": "def check_smaller(test_tup1, test_tup2):\n\t''' Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.\n\t>>> check_smaller((1, 2, 3), (2, 3, 4))\n\tFalse\n\t>>> check_smaller((4, 5, 6), (3, 4, 5))\n\tTrue\n\t>>> check_... | |
810 | train | Write a function to iterate over elements repeating each as many times as its count. | [
"assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q'] ",
"assert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's'] ",
"assert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r',... | [] | from collections import Counter
def count_variable(a,b,c,d):
''' Write a function to iterate over elements repeating each as many times as its count.
>>> count_variable(4, 2, 0, -2)
['p', 'p', 'p', 'p', 'q', 'q']
>>> count_variable(0, 1, 2, 3)
['q', 'r', 'r', 's', 's', 's']
>>> count_variable(11, 15, 12, 23)
['p... | ```python
from collections import Counter
def count_variable(a,b,c,d):
''' Write a function to iterate over elements repeating each as many times as its count.
>>> count_variable(4, 2, 0, -2)
['p', 'p', 'p', 'p', 'q', 'q']
>>> count_variable(0, 1, 2, 3)
['q', 'r', 'r', 's', 's', 's']
>>> count_variable(11, ... | [
{
"role": "user",
"content": "from collections import Counter\ndef count_variable(a,b,c,d):\n\t''' Write a function to iterate over elements repeating each as many times as its count.\n\t>>> count_variable(4, 2, 0, -2)\n\t['p', 'p', 'p', 'p', 'q', 'q']\n\t>>> count_variable(0, 1, 2, 3)\n\t['q', 'r', 'r', 's... | |
811 | train | Write a function to check if two lists of tuples are identical or not. | [
"assert check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True",
"assert check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False",
"assert check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True"
] | [] | def check_identical(test_list1, test_list2):
''' Write a function to check if two lists of tuples are identical or not.
>>> check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)])
True
>>> check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)])
False
>>> check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)])
Tr... | ```python
def check_identical(test_list1, test_list2):
''' Write a function to check if two lists of tuples are identical or not.
>>> check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)])
True
>>> check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)])
False
>>> check_identical([(2, 14), (12, 25)], [(2, 14)... | [
{
"role": "user",
"content": "def check_identical(test_list1, test_list2):\n\t''' Write a function to check if two lists of tuples are identical or not.\n\t>>> check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)])\n\tTrue\n\t>>> check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)])\n\tFalse\n\t>>> check_i... | |
812 | train | Write a function to abbreviate 'road' as 'rd.' in a given string. | [
"assert road_rd(\"ravipadu Road\")==('ravipadu Rd.')",
"assert road_rd(\"palnadu Road\")==('palnadu Rd.')",
"assert road_rd(\"eshwar enclave Road\")==('eshwar enclave Rd.')"
] | [] | import re
def road_rd(street):
''' Write a function to abbreviate 'road' as 'rd.' in a given string.
>>> road_rd('ravipadu Road')
'ravipadu Rd.'
>>> road_rd('palnadu Road')
'palnadu Rd.'
>>> road_rd('eshwar enclave Road')
'eshwar enclave Rd.'
''' | ```python
import re
def road_rd(street):
''' Write a function to abbreviate 'road' as 'rd.' in a given string.
>>> road_rd('ravipadu Road')
'ravipadu Rd.'
>>> road_rd('palnadu Road')
'palnadu Rd.'
>>> road_rd('eshwar enclave Road')
'eshwar enclave Rd.'
'''
return (re.sub('Road$', 'Rd.', street))
``` | [
{
"role": "user",
"content": "import re\ndef road_rd(street):\n\t''' Write a function to abbreviate 'road' as 'rd.' in a given string.\n\t>>> road_rd('ravipadu Road')\n\t'ravipadu Rd.'\n\t>>> road_rd('palnadu Road')\n\t'palnadu Rd.'\n\t>>> road_rd('eshwar enclave Road')\n\t'eshwar enclave Rd.'\n\t'''"
},
... | |
813 | train | Write a function to find length of the string. | [
"assert string_length('python')==6",
"assert string_length('program')==7",
"assert string_length('language')==8"
] | [] | def string_length(str1):
''' Write a function to find length of the string.
>>> string_length('python')
6
>>> string_length('program')
7
>>> string_length('language')
8
''' | ```python
def string_length(str1):
''' Write a function to find length of the string.
>>> string_length('python')
6
>>> string_length('program')
7
>>> string_length('language')
8
'''
count = 0
for char in str1:
count += 1
return count
``` | [
{
"role": "user",
"content": "def string_length(str1):\n\t''' Write a function to find length of the string.\n\t>>> string_length('python')\n\t6\n\t>>> string_length('program')\n\t7\n\t>>> string_length('language')\n\t8\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef string_length(s... | |
814 | train | Write a function to find the area of a rombus. | [
"assert rombus_area(10,20)==100",
"assert rombus_area(10,5)==25",
"assert rombus_area(4,2)==4"
] | [] | def rombus_area(p,q):
''' Write a function to find the area of a rombus.
>>> rombus_area(10, 20)
100
>>> rombus_area(10, 5)
25
>>> rombus_area(4, 2)
4
''' | ```python
def rombus_area(p,q):
''' Write a function to find the area of a rombus.
>>> rombus_area(10, 20)
100
>>> rombus_area(10, 5)
25
>>> rombus_area(4, 2)
4
'''
area=(p*q)/2
return area
``` | [
{
"role": "user",
"content": "def rombus_area(p,q):\n\t''' Write a function to find the area of a rombus.\n\t>>> rombus_area(10, 20)\n\t100\n\t>>> rombus_area(10, 5)\n\t25\n\t>>> rombus_area(4, 2)\n\t4\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef rombus_area(p,q):\n ''' Write a ... | |
815 | train | Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2. | [
"assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]",
"assert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]",
"assert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]"
] | [] | def sort_by_dnf(arr, n):
''' Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.
>>> sort_by_dnf([1, 2, 0, 1, 0, 1, 2, 1, 1], 9)
[0, 0, 1, 1, 1, 1, 1, 2, 2]
>>> sort_by_dnf([1, 0, 0, 1, 2, 1, 2, 2, 1, 0], 10)
[0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
>>... | ```python
def sort_by_dnf(arr, n):
''' Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.
>>> sort_by_dnf([1, 2, 0, 1, 0, 1, 2, 1, 1], 9)
[0, 0, 1, 1, 1, 1, 1, 2, 2]
>>> sort_by_dnf([1, 0, 0, 1, 2, 1, 2, 2, 1, 0], 10)
[0, 0, 0, 1, 1, 1, ... | [
{
"role": "user",
"content": "def sort_by_dnf(arr, n):\n\t''' Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.\n\t>>> sort_by_dnf([1, 2, 0, 1, 0, 1, 2, 1, 1], 9)\n\t[0, 0, 1, 1, 1, 1, 1, 2, 2]\n\t>>> sort_by_dnf([1, 0, 0, 1, 2, 1, 2,... | |
816 | train | Write a function to clear the values of the given tuples. | [
"assert clear_tuple((1, 5, 3, 6, 8)) == ()",
"assert clear_tuple((2, 1, 4 ,5 ,6)) == ()",
"assert clear_tuple((3, 2, 5, 6, 8)) == ()"
] | [] | def clear_tuple(test_tup):
''' Write a function to clear the values of the given tuples.
>>> clear_tuple((1, 5, 3, 6, 8))
()
>>> clear_tuple((2, 1, 4, 5, 6))
()
>>> clear_tuple((3, 2, 5, 6, 8))
()
''' | ```python
def clear_tuple(test_tup):
''' Write a function to clear the values of the given tuples.
>>> clear_tuple((1, 5, 3, 6, 8))
()
>>> clear_tuple((2, 1, 4, 5, 6))
()
>>> clear_tuple((3, 2, 5, 6, 8))
()
'''
temp = list(test_tup)
temp.clear()
test_tup = tuple(temp)
return (test_tup)
``` | [
{
"role": "user",
"content": "def clear_tuple(test_tup):\n\t''' Write a function to clear the values of the given tuples.\n\t>>> clear_tuple((1, 5, 3, 6, 8))\n\t()\n\t>>> clear_tuple((2, 1, 4, 5, 6))\n\t()\n\t>>> clear_tuple((3, 2, 5, 6, 8))\n\t()\n\t'''"
},
{
"role": "assistant",
"content": "``... | |
817 | train | Write a function to find numbers divisible by m or n from a list of numbers using lambda function. | [
"assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],19,13)==[19, 65, 57, 39, 152, 190]",
"assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[2, 5, 8, 10]",
"assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10, 15, 20]"
] | [] | def div_of_nums(nums,m,n):
''' Write a function to find numbers divisible by m or n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 19, 13)
[19, 65, 57, 39, 152, 190]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[2, 5, 8, 10]
>>> div_of_nums([10, 15, 14... | ```python
def div_of_nums(nums,m,n):
''' Write a function to find numbers divisible by m or n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 19, 13)
[19, 65, 57, 39, 152, 190]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[2, 5, 8, 10]
>>> div_of_nums([... | [
{
"role": "user",
"content": "def div_of_nums(nums,m,n):\n\t''' Write a function to find numbers divisible by m or n from a list of numbers using lambda function.\n\t>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 19, 13)\n\t[19, 65, 57, 39, 152, 190]\n\t>>> div_of_nums([1, 2, 3, 5, 7, 8, 10],... | |
818 | train | Write a python function to count lower case letters in a given string. | [
"assert lower_ctr('abc') == 3",
"assert lower_ctr('string') == 6",
"assert lower_ctr('Python') == 5"
] | [] | def lower_ctr(str):
''' Write a python function to count lower case letters in a given string.
>>> lower_ctr('abc')
3
>>> lower_ctr('string')
6
>>> lower_ctr('Python')
5
''' | ```python
def lower_ctr(str):
''' Write a python function to count lower case letters in a given string.
>>> lower_ctr('abc')
3
>>> lower_ctr('string')
6
>>> lower_ctr('Python')
5
'''
lower_ctr= 0
for i in range(len(str)):
if str[i] >= 'a' and str[i]... | [
{
"role": "user",
"content": "def lower_ctr(str):\n\t''' Write a python function to count lower case letters in a given string.\n\t>>> lower_ctr('abc')\n\t3\n\t>>> lower_ctr('string')\n\t6\n\t>>> lower_ctr('Python')\n\t5\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef lower_ctr(str)... | |
819 | train | Write a function to count the frequency of consecutive duplicate elements in a given list of numbers. | [
"assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4])",
"assert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])",
"assert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])"
] | [] | def count_duplic(lists):
''' Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.
>>> count_duplic([1, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5])
([1, 2, 4, 5], [1, 3, 3, 4])
>>> count_duplic([2, 2, 3, 1, 2, 6, 7, 9])
([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])
>>> count_du... | ```python
def count_duplic(lists):
''' Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.
>>> count_duplic([1, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5])
([1, 2, 4, 5], [1, 3, 3, 4])
>>> count_duplic([2, 2, 3, 1, 2, 6, 7, 9])
([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1... | [
{
"role": "user",
"content": "def count_duplic(lists):\n\t''' Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.\n\t>>> count_duplic([1, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5])\n\t([1, 2, 4, 5], [1, 3, 3, 4])\n\t>>> count_duplic([2, 2, 3, 1, 2, 6, 7, 9])\n\t([2, 3, ... | |
820 | train | Write a function to check whether the given month number contains 28 days or not. | [
"assert check_monthnum_number(2)==True",
"assert check_monthnum_number(1)==False",
"assert check_monthnum_number(3)==False"
] | [] | def check_monthnum_number(monthnum1):
''' Write a function to check whether the given month number contains 28 days or not.
>>> check_monthnum_number(2)
True
>>> check_monthnum_number(1)
False
>>> check_monthnum_number(3)
False
''' | ```python
def check_monthnum_number(monthnum1):
''' Write a function to check whether the given month number contains 28 days or not.
>>> check_monthnum_number(2)
True
>>> check_monthnum_number(1)
False
>>> check_monthnum_number(3)
False
'''
if monthnum1 == 2:
return True
else:
return False
... | [
{
"role": "user",
"content": "def check_monthnum_number(monthnum1):\n\t''' Write a function to check whether the given month number contains 28 days or not.\n\t>>> check_monthnum_number(2)\n\tTrue\n\t>>> check_monthnum_number(1)\n\tFalse\n\t>>> check_monthnum_number(3)\n\tFalse\n\t'''"
},
{
"role": ... | |
821 | train | Write a function to merge two dictionaries into a single expression. | [
"assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}",
"assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{ \"O\": \"Orange\", \"W\": \"White\", \... | [] | import collections as ct
def merge_dictionaries(dict1,dict2):
''' Write a function to merge two dictionaries into a single expression.
>>> merge_dictionaries({'R': 'Red', 'B': 'Black', 'P': 'Pink'}, {'G': 'Green', 'W': 'White'})
{'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
>>> merge_dictionar... | ```python
import collections as ct
def merge_dictionaries(dict1,dict2):
''' Write a function to merge two dictionaries into a single expression.
>>> merge_dictionaries({'R': 'Red', 'B': 'Black', 'P': 'Pink'}, {'G': 'Green', 'W': 'White'})
{'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
... | [
{
"role": "user",
"content": "import collections as ct\ndef merge_dictionaries(dict1,dict2):\n\t''' Write a function to merge two dictionaries into a single expression.\n\t>>> merge_dictionaries({'R': 'Red', 'B': 'Black', 'P': 'Pink'}, {'G': 'Green', 'W': 'White'})\n\t{'B': 'Black', 'R': 'Red', 'P': 'Pink',... | |
822 | train | Write a function to return true if the password is valid. | [
"assert pass_validity(\"password\")==False",
"assert pass_validity(\"Password@10\")==True",
"assert pass_validity(\"password@10\")==False"
] | [] | import re
def pass_validity(p):
''' Write a function to return true if the password is valid.
>>> pass_validity('password')
False
>>> pass_validity('Password@10')
True
>>> pass_validity('password@10')
False
''' | ```python
import re
def pass_validity(p):
''' Write a function to return true if the password is valid.
>>> pass_validity('password')
False
>>> pass_validity('Password@10')
True
>>> pass_validity('password@10')
False
'''
x = True
while x:
if (len(p)<6 or len(p)>12):
break
elif not re.search(... | [
{
"role": "user",
"content": "import re\ndef pass_validity(p):\n\t''' Write a function to return true if the password is valid.\n\t>>> pass_validity('password')\n\tFalse\n\t>>> pass_validity('Password@10')\n\tTrue\n\t>>> pass_validity('password@10')\n\tFalse\n\t'''"
},
{
"role": "assistant",
"co... | |
823 | train | Write a function to check if the given string starts with a substring using regex. | [
"assert check_substring(\"dreams for dreams makes life fun\", \"makes\") == 'string doesnt start with the given substring'",
"assert check_substring(\"Hi there how are you Hi alex\", \"Hi\") == 'string starts with the given substring'",
"assert check_substring(\"Its been a long day\", \"been\") == 'string doesn... | [] | import re
def check_substring(string, sample) :
''' Write a function to check if the given string starts with a substring using regex.
>>> check_substring('dreams for dreams makes life fun', 'makes')
'string doesnt start with the given substring'
>>> check_substring('Hi there how are you Hi alex', 'Hi')
'string s... | ```python
import re
def check_substring(string, sample) :
''' Write a function to check if the given string starts with a substring using regex.
>>> check_substring('dreams for dreams makes life fun', 'makes')
'string doesnt start with the given substring'
>>> check_substring('Hi there how are you Hi alex', 'H... | [
{
"role": "user",
"content": "import re\ndef check_substring(string, sample) : \n\t''' Write a function to check if the given string starts with a substring using regex.\n\t>>> check_substring('dreams for dreams makes life fun', 'makes')\n\t'string doesnt start with the given substring'\n\t>>> check_substri... | |
824 | train | Write a python function to remove even numbers from a given list. | [
"assert remove_even([1,3,5,2]) == [1,3,5]",
"assert remove_even([5,6,7]) == [5,7]",
"assert remove_even([1,2,3,4]) == [1,3]"
] | [] | def remove_even(l):
''' Write a python function to remove even numbers from a given list.
>>> remove_even([1, 3, 5, 2])
[1, 3, 5]
>>> remove_even([5, 6, 7])
[5, 7]
>>> remove_even([1, 2, 3, 4])
[1, 3]
''' | ```python
def remove_even(l):
''' Write a python function to remove even numbers from a given list.
>>> remove_even([1, 3, 5, 2])
[1, 3, 5]
>>> remove_even([5, 6, 7])
[5, 7]
>>> remove_even([1, 2, 3, 4])
[1, 3]
'''
for i in l:
if i % 2 == 0:
l.remove(i)
return... | [
{
"role": "user",
"content": "def remove_even(l):\n\t''' Write a python function to remove even numbers from a given list.\n\t>>> remove_even([1, 3, 5, 2])\n\t[1, 3, 5]\n\t>>> remove_even([5, 6, 7])\n\t[5, 7]\n\t>>> remove_even([1, 2, 3, 4])\n\t[1, 3]\n\t'''"
},
{
"role": "assistant",
"content":... | |
825 | train | Write a python function to access multiple elements of specified index from a given list. | [
"assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]",
"assert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3]",
"assert access_elements([1,0,2,3],[0,1]) == [1,0]"
] | [] | def access_elements(nums, list_index):
''' Write a python function to access multiple elements of specified index from a given list.
>>> access_elements([2, 3, 8, 4, 7, 9], [0, 3, 5])
[2, 4, 9]
>>> access_elements([1, 2, 3, 4, 5], [1, 2])
[2, 3]
>>> access_elements([1, 0, 2, 3], [0, 1])
[1, 0]
''' | ```python
def access_elements(nums, list_index):
''' Write a python function to access multiple elements of specified index from a given list.
>>> access_elements([2, 3, 8, 4, 7, 9], [0, 3, 5])
[2, 4, 9]
>>> access_elements([1, 2, 3, 4, 5], [1, 2])
[2, 3]
>>> access_elements([1, 0, 2, 3], [0, 1]... | [
{
"role": "user",
"content": "def access_elements(nums, list_index):\n\t''' Write a python function to access multiple elements of specified index from a given list.\n\t>>> access_elements([2, 3, 8, 4, 7, 9], [0, 3, 5])\n\t[2, 4, 9]\n\t>>> access_elements([1, 2, 3, 4, 5], [1, 2])\n\t[2, 3]\n\t>>> access_ele... | |
826 | train | Write a python function to find the type of triangle from the given sides. | [
"assert check_Type_Of_Triangle(1,2,3) == \"Obtuse-angled Triangle\"",
"assert check_Type_Of_Triangle(2,2,2) == \"Acute-angled Triangle\"",
"assert check_Type_Of_Triangle(1,0,1) == \"Right-angled Triangle\""
] | [] | def check_Type_Of_Triangle(a,b,c):
''' Write a python function to find the type of triangle from the given sides.
>>> check_Type_Of_Triangle(1, 2, 3)
'Obtuse-angled Triangle'
>>> check_Type_Of_Triangle(2, 2, 2)
'Acute-angled Triangle'
>>> check_Type_Of_Triangle(1, 0, 1)
'Right-angled Triangle'
''' | ```python
def check_Type_Of_Triangle(a,b,c):
''' Write a python function to find the type of triangle from the given sides.
>>> check_Type_Of_Triangle(1, 2, 3)
'Obtuse-angled Triangle'
>>> check_Type_Of_Triangle(2, 2, 2)
'Acute-angled Triangle'
>>> check_Type_Of_Triangle(1, 0, 1)
'Right-ang... | [
{
"role": "user",
"content": "def check_Type_Of_Triangle(a,b,c): \n\t''' Write a python function to find the type of triangle from the given sides.\n\t>>> check_Type_Of_Triangle(1, 2, 3)\n\t'Obtuse-angled Triangle'\n\t>>> check_Type_Of_Triangle(2, 2, 2)\n\t'Acute-angled Triangle'\n\t>>> check_Type_Of_Triang... | |
827 | train | Write a function to sum a specific column of a list in a given list of lists. | [
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12",
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15",
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9"
] | [] | def sum_column(list1, C):
''' Write a function to sum a specific column of a list in a given list of lists.
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 0)
12
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 1)
15
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 3)
9
''' | ```python
def sum_column(list1, C):
''' Write a function to sum a specific column of a list in a given list of lists.
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 0)
12
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 1)
15
>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, ... | [
{
"role": "user",
"content": "def sum_column(list1, C):\n\t''' Write a function to sum a specific column of a list in a given list of lists.\n\t>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 0)\n\t12\n\t>>> sum_column([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]], 1)\n\t15\n\t>>> sum_column([[1, 2,... | |
828 | train | Write a function to count alphabets,digits and special charactes in a given string. | [
"assert count_alpha_dig_spl(\"abc!@#123\")==(3,3,3)",
"assert count_alpha_dig_spl(\"dgsuy@#$%&1255\")==(5,4,5)",
"assert count_alpha_dig_spl(\"fjdsif627348#%$^&\")==(6,6,5)"
] | [] | def count_alpha_dig_spl(string):
''' Write a function to count alphabets,digits and special charactes in a given string.
>>> count_alpha_dig_spl('abc!@#123')
(3, 3, 3)
>>> count_alpha_dig_spl('dgsuy@#$%&1255')
(5, 4, 5)
>>> count_alpha_dig_spl('fjdsif627348#%$^&')
(6, 6, 5)
''' | ```python
def count_alpha_dig_spl(string):
''' Write a function to count alphabets,digits and special charactes in a given string.
>>> count_alpha_dig_spl('abc!@#123')
(3, 3, 3)
>>> count_alpha_dig_spl('dgsuy@#$%&1255')
(5, 4, 5)
>>> count_alpha_dig_spl('fjdsif627348#%$^&')
(6, 6, 5)
'''
alphabets=dig... | [
{
"role": "user",
"content": "def count_alpha_dig_spl(string):\n\t''' Write a function to count alphabets,digits and special charactes in a given string.\n\t>>> count_alpha_dig_spl('abc!@#123')\n\t(3, 3, 3)\n\t>>> count_alpha_dig_spl('dgsuy@#$%&1255')\n\t(5, 4, 5)\n\t>>> count_alpha_dig_spl('fjdsif627348#%$... | |
829 | train | Write a function to find out the second most repeated (or frequent) string in the given sequence. | [
"assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'",
"assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'",
"assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'"
] | [] | from collections import Counter
def second_frequent(input):
''' Write a function to find out the second most repeated (or frequent) string in the given sequence.
>>> second_frequent(['aaa', 'bbb', 'ccc', 'bbb', 'aaa', 'aaa'])
'bbb'
>>> second_frequent(['abc', 'bcd', 'abc', 'bcd', 'bcd', 'bcd'])
'abc'
>>> second_... | ```python
from collections import Counter
def second_frequent(input):
''' Write a function to find out the second most repeated (or frequent) string in the given sequence.
>>> second_frequent(['aaa', 'bbb', 'ccc', 'bbb', 'aaa', 'aaa'])
'bbb'
>>> second_frequent(['abc', 'bcd', 'abc', 'bcd', 'bcd', 'bcd'])
'abc'
>... | [
{
"role": "user",
"content": "from collections import Counter\ndef second_frequent(input): \n\t''' Write a function to find out the second most repeated (or frequent) string in the given sequence.\n\t>>> second_frequent(['aaa', 'bbb', 'ccc', 'bbb', 'aaa', 'aaa'])\n\t'bbb'\n\t>>> second_frequent(['abc', 'bcd... | |
830 | train | Write a function to round up a number to specific digits. | [
"assert round_up(123.01247,0)==124",
"assert round_up(123.01247,1)==123.1",
"assert round_up(123.01247,2)==123.02"
] | [] | import math
def round_up(a, digits):
''' Write a function to round up a number to specific digits.
>>> round_up(123.01247, 0)
124
>>> round_up(123.01247, 1)
123.1
>>> round_up(123.01247, 2)
123.02
''' | ```python
import math
def round_up(a, digits):
''' Write a function to round up a number to specific digits.
>>> round_up(123.01247, 0)
124
>>> round_up(123.01247, 1)
123.1
>>> round_up(123.01247, 2)
123.02
'''
n = 10**-digits
return round(math.ceil(a / n) * n, digits)
``` | [
{
"role": "user",
"content": "import math\ndef round_up(a, digits):\n\t''' Write a function to round up a number to specific digits.\n\t>>> round_up(123.01247, 0)\n\t124\n\t>>> round_up(123.01247, 1)\n\t123.1\n\t>>> round_up(123.01247, 2)\n\t123.02\n\t'''"
},
{
"role": "assistant",
"content": "`... | |
831 | train | Write a python function to count equal element pairs from the given array. | [
"assert count_Pairs([1,1,1,1],4) == 6",
"assert count_Pairs([1,5,1],3) == 1",
"assert count_Pairs([3,2,1,7,8,9],6) == 0"
] | [] | def count_Pairs(arr,n):
''' Write a python function to count equal element pairs from the given array.
>>> count_Pairs([1, 1, 1, 1], 4)
6
>>> count_Pairs([1, 5, 1], 3)
1
>>> count_Pairs([3, 2, 1, 7, 8, 9], 6)
0
''' | ```python
def count_Pairs(arr,n):
''' Write a python function to count equal element pairs from the given array.
>>> count_Pairs([1, 1, 1, 1], 4)
6
>>> count_Pairs([1, 5, 1], 3)
1
>>> count_Pairs([3, 2, 1, 7, 8, 9], 6)
0
'''
cnt = 0;
for i in range(n):
for j in range(i... | [
{
"role": "user",
"content": "def count_Pairs(arr,n): \n\t''' Write a python function to count equal element pairs from the given array.\n\t>>> count_Pairs([1, 1, 1, 1], 4)\n\t6\n\t>>> count_Pairs([1, 5, 1], 3)\n\t1\n\t>>> count_Pairs([3, 2, 1, 7, 8, 9], 6)\n\t0\n\t'''"
},
{
"role": "assistant",
... | |
832 | train | Write a function to extract the maximum numeric value from a string by using regex. | [
"assert extract_max('100klh564abc365bg') == 564",
"assert extract_max('hello300how546mer231') == 546",
"assert extract_max('its233beenalong343journey234') == 343"
] | [] | import re
def extract_max(input):
''' Write a function to extract the maximum numeric value from a string by using regex.
>>> extract_max('100klh564abc365bg')
564
>>> extract_max('hello300how546mer231')
546
>>> extract_max('its233beenalong343journey234')
343
''' | ```python
import re
def extract_max(input):
''' Write a function to extract the maximum numeric value from a string by using regex.
>>> extract_max('100klh564abc365bg')
564
>>> extract_max('hello300how546mer231')
546
>>> extract_max('its233beenalong343journey234')
343
'''
numbers = re.findall('\\d+',input)
... | [
{
"role": "user",
"content": "import re\ndef extract_max(input): \n\t''' Write a function to extract the maximum numeric value from a string by using regex.\n\t>>> extract_max('100klh564abc365bg')\n\t564\n\t>>> extract_max('hello300how546mer231')\n\t546\n\t>>> extract_max('its233beenalong343journey234')\n\t... | |
833 | train | Write a function to get dictionary keys as a list. | [
"assert get_key({1:'python',2:'java'})==[1,2]",
"assert get_key({10:'red',20:'blue',30:'black'})==[10,20,30]",
"assert get_key({27:'language',39:'java',44:'little'})==[27,39,44]"
] | [] | def get_key(dict):
''' Write a function to get dictionary keys as a list.
>>> get_key({1: 'python', 2: 'java'})
[1, 2]
>>> get_key({10: 'red', 20: 'blue', 30: 'black'})
[10, 20, 30]
>>> get_key({27: 'language', 39: 'java', 44: 'little'})
[27, 39, 44]
''' | ```python
def get_key(dict):
''' Write a function to get dictionary keys as a list.
>>> get_key({1: 'python', 2: 'java'})
[1, 2]
>>> get_key({10: 'red', 20: 'blue', 30: 'black'})
[10, 20, 30]
>>> get_key({27: 'language', 39: 'java', 44: 'little'})
[27, 39, 44]
'''
list = []
for... | [
{
"role": "user",
"content": "def get_key(dict): \n\t''' Write a function to get dictionary keys as a list.\n\t>>> get_key({1: 'python', 2: 'java'})\n\t[1, 2]\n\t>>> get_key({10: 'red', 20: 'blue', 30: 'black'})\n\t[10, 20, 30]\n\t>>> get_key({27: 'language', 39: 'java', 44: 'little'})\n\t[27, 39, 44]\n\t''... | |
834 | train | Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order. | [
"assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]] ",
"assert generate_matrix(2)==[[1,2],[4,3]]",
"assert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19... | [] | def generate_matrix(n):
''' Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.
>>> generate_matrix(3)
[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
>>> generate_matrix(2)
[[1, 2], [4, 3]]
>>> generate_matrix(7)
[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, ... | ```python
def generate_matrix(n):
''' Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.
>>> generate_matrix(3)
[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
>>> generate_matrix(2)
[[1, 2], [4, 3]]
>>> generate_matr... | [
{
"role": "user",
"content": "def generate_matrix(n):\n\t''' Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.\n\t>>> generate_matrix(3)\n\t[[1, 2, 3], [8, 9, 4], [7, 6, 5]]\n\t>>> generate_matrix(2)\n\t[[1, 2], [4, 3]]\n\t>>> generate_ma... | |
835 | train | Write a python function to find the slope of a line. | [
"assert slope(4,2,2,5) == -1.5",
"assert slope(2,4,4,6) == 1",
"assert slope(1,2,4,2) == 0"
] | [] | def slope(x1,y1,x2,y2):
''' Write a python function to find the slope of a line.
>>> slope(4, 2, 2, 5)
-1.5
>>> slope(2, 4, 4, 6)
1
>>> slope(1, 2, 4, 2)
0
''' | ```python
def slope(x1,y1,x2,y2):
''' Write a python function to find the slope of a line.
>>> slope(4, 2, 2, 5)
-1.5
>>> slope(2, 4, 4, 6)
1
>>> slope(1, 2, 4, 2)
0
'''
return (float)(y2-y1)/(x2-x1)
``` | [
{
"role": "user",
"content": "def slope(x1,y1,x2,y2): \n\t''' Write a python function to find the slope of a line.\n\t>>> slope(4, 2, 2, 5)\n\t-1.5\n\t>>> slope(2, 4, 4, 6)\n\t1\n\t>>> slope(1, 2, 4, 2)\n\t0\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef slope(x1,y1,x2,y2): \n '... | |
836 | train | Write a function to find length of the subarray having maximum sum. | [
"assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5",
"assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2",
"assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3"
] | [] | from sys import maxsize
def max_sub_array_sum(a,size):
''' Write a function to find length of the subarray having maximum sum.
>>> max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8)
5
>>> max_sub_array_sum([1, -2, 1, 1, -2, 1], 6)
2
>>> max_sub_array_sum([-1, -2, 3, 4, 5], 5)
3
''' | ```python
from sys import maxsize
def max_sub_array_sum(a,size):
''' Write a function to find length of the subarray having maximum sum.
>>> max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8)
5
>>> max_sub_array_sum([1, -2, 1, 1, -2, 1], 6)
2
>>> max_sub_array_sum([-1, -2, 3, 4, 5], 5)
3
'''
max_so_far = -ma... | [
{
"role": "user",
"content": "from sys import maxsize\ndef max_sub_array_sum(a,size): \n\t''' Write a function to find length of the subarray having maximum sum.\n\t>>> max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8)\n\t5\n\t>>> max_sub_array_sum([1, -2, 1, 1, -2, 1], 6)\n\t2\n\t>>> max_sub_array_sum([-... | |
837 | train | Write a python function to find the cube sum of first n odd natural numbers. | [
"assert cube_Sum(2) == 28",
"assert cube_Sum(3) == 153",
"assert cube_Sum(4) == 496"
] | [] | def cube_Sum(n):
''' Write a python function to find the cube sum of first n odd natural numbers.
>>> cube_Sum(2)
28
>>> cube_Sum(3)
153
>>> cube_Sum(4)
496
''' | ```python
def cube_Sum(n):
''' Write a python function to find the cube sum of first n odd natural numbers.
>>> cube_Sum(2)
28
>>> cube_Sum(3)
153
>>> cube_Sum(4)
496
'''
sum = 0
for i in range(0,n) :
sum += (2*i+1)*(2*i+1)*(2*i+1)
return sum
``` | [
{
"role": "user",
"content": "def cube_Sum(n): \n\t''' Write a python function to find the cube sum of first n odd natural numbers.\n\t>>> cube_Sum(2)\n\t28\n\t>>> cube_Sum(3)\n\t153\n\t>>> cube_Sum(4)\n\t496\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef cube_Sum(n): \n ''' Wri... | |
838 | train | Write a python function to find minimum number swaps required to make two binary strings equal. | [
"assert min_Swaps(\"0011\",\"1111\") == 1",
"assert min_Swaps(\"00011\",\"01001\") == 2",
"assert min_Swaps(\"111\",\"111\") == 0"
] | [] | def min_Swaps(s1,s2) :
''' Write a python function to find minimum number swaps required to make two binary strings equal.
>>> min_Swaps('0011', '1111')
1
>>> min_Swaps('00011', '01001')
2
>>> min_Swaps('111', '111')
0
''' | ```python
def min_Swaps(s1,s2) :
''' Write a python function to find minimum number swaps required to make two binary strings equal.
>>> min_Swaps('0011', '1111')
1
>>> min_Swaps('00011', '01001')
2
>>> min_Swaps('111', '111')
0
'''
c0 = 0; c1 = 0;
for i in range(len(s1)) : ... | [
{
"role": "user",
"content": "def min_Swaps(s1,s2) : \n\t''' Write a python function to find minimum number swaps required to make two binary strings equal.\n\t>>> min_Swaps('0011', '1111')\n\t1\n\t>>> min_Swaps('00011', '01001')\n\t2\n\t>>> min_Swaps('111', '111')\n\t0\n\t'''"
},
{
"role": "assist... | |
839 | train | Write a function to sort the tuples alphabetically by the first item of each tuple. | [
"assert sort_tuple([(\"Amana\", 28), (\"Zenat\", 30), (\"Abhishek\", 29),(\"Nikhil\", 21), (\"B\", \"C\")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]",
"assert sort_tuple([(\"aaaa\", 28), (\"aa\", 30), (\"bab\", 29), (\"bb\", 21), (\"csa\", \"C\")]) == [('aa', 30), ('aaaa', 2... | [] | def sort_tuple(tup):
''' Write a function to sort the tuples alphabetically by the first item of each tuple.
>>> sort_tuple([('Amana', 28), ('Zenat', 30), ('Abhishek', 29), ('Nikhil', 21), ('B', 'C')])
[('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]
>>> sort_tuple([('aaaa', 28), ('aa',... | ```python
def sort_tuple(tup):
''' Write a function to sort the tuples alphabetically by the first item of each tuple.
>>> sort_tuple([('Amana', 28), ('Zenat', 30), ('Abhishek', 29), ('Nikhil', 21), ('B', 'C')])
[('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]
>>> sort_tuple([('aaaa', 2... | [
{
"role": "user",
"content": "def sort_tuple(tup): \n\t''' Write a function to sort the tuples alphabetically by the first item of each tuple.\n\t>>> sort_tuple([('Amana', 28), ('Zenat', 30), ('Abhishek', 29), ('Nikhil', 21), ('B', 'C')])\n\t[('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Ze... | |
840 | train | Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not. | [
"assert Check_Solution(2,0,-1) == \"Yes\"",
"assert Check_Solution(1,-5,6) == \"No\"",
"assert Check_Solution(2,0,2) == \"Yes\""
] | [] | def Check_Solution(a,b,c):
''' Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.
>>> Check_Solution(2, 0, -1)
'Yes'
>>> Check_Solution(1, -5, 6)
'No'
>>> Check_Solution(2, 0, 2)
'Yes'
''' | ```python
def Check_Solution(a,b,c):
''' Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.
>>> Check_Solution(2, 0, -1)
'Yes'
>>> Check_Solution(1, -5, 6)
'No'
>>> Check_Solution(2, 0, 2)
'Yes'
'''
if b == ... | [
{
"role": "user",
"content": "def Check_Solution(a,b,c): \n\t''' Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.\n\t>>> Check_Solution(2, 0, -1)\n\t'Yes'\n\t>>> Check_Solution(1, -5, 6)\n\t'No'\n\t>>> Check_Solution(2, 0, 2)\n\t'... | |
841 | train | Write a function to count the number of inversions in the given array. | [
"assert get_inv_count([1, 20, 6, 4, 5], 5) == 5",
"assert get_inv_count([8, 4, 2, 1], 4) == 6",
"assert get_inv_count([3, 1, 2], 3) == 2"
] | [] | def get_inv_count(arr, n):
''' Write a function to count the number of inversions in the given array.
>>> get_inv_count([1, 20, 6, 4, 5], 5)
5
>>> get_inv_count([8, 4, 2, 1], 4)
6
>>> get_inv_count([3, 1, 2], 3)
2
''' | ```python
def get_inv_count(arr, n):
''' Write a function to count the number of inversions in the given array.
>>> get_inv_count([1, 20, 6, 4, 5], 5)
5
>>> get_inv_count([8, 4, 2, 1], 4)
6
>>> get_inv_count([3, 1, 2], 3)
2
'''
inv_count = 0
for i in range(n):
for j in range(i + 1, n):
if (arr[i] > ar... | [
{
"role": "user",
"content": "def get_inv_count(arr, n): \n\t''' Write a function to count the number of inversions in the given array.\n\t>>> get_inv_count([1, 20, 6, 4, 5], 5)\n\t5\n\t>>> get_inv_count([8, 4, 2, 1], 4)\n\t6\n\t>>> get_inv_count([3, 1, 2], 3)\n\t2\n\t'''"
},
{
"role": "assistant",
... | |
842 | train | Write a function to find the number which occurs for odd number of times in the given array. | [
"assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5",
"assert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3",
"assert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5"
] | [] | def get_odd_occurence(arr, arr_size):
''' Write a function to find the number which occurs for odd number of times in the given array.
>>> get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13)
5
>>> get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7)
3
>>> get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7)
5
''' | ```python
def get_odd_occurence(arr, arr_size):
''' Write a function to find the number which occurs for odd number of times in the given array.
>>> get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13)
5
>>> get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7)
3
>>> get_odd_occurence([5, 7, 2, 7, 5, 2, 5],... | [
{
"role": "user",
"content": "def get_odd_occurence(arr, arr_size):\n\t''' Write a function to find the number which occurs for odd number of times in the given array.\n\t>>> get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13)\n\t5\n\t>>> get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7)\n\t3\n\t>>> ge... | |
843 | train | Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm. | [
"assert nth_super_ugly_number(12,[2,7,13,19])==32",
"assert nth_super_ugly_number(10,[2,7,13,19])==26",
"assert nth_super_ugly_number(100,[2,7,13,19])==5408"
] | [] | import heapq
def nth_super_ugly_number(n, primes):
''' Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
>>> nth_super_ugly_number(12, [2, 7, 13, 19])
32
>>> nth_super_ugly_number(10, [2, 7, 13, 19])
26
>>> nth_super_ugly_number(100, [2, 7, 13, 19])
... | ```python
import heapq
def nth_super_ugly_number(n, primes):
''' Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
>>> nth_super_ugly_number(12, [2, 7, 13, 19])
32
>>> nth_super_ugly_number(10, [2, 7, 13, 19])
26
>>> nth_super_ugly_n... | [
{
"role": "user",
"content": "import heapq\ndef nth_super_ugly_number(n, primes):\n\t''' Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.\n\t>>> nth_super_ugly_number(12, [2, 7, 13, 19])\n\t32\n\t>>> nth_super_ugly_number(10, [2, 7, 13, 19])\n\... | |
844 | train | Write a python function to find the kth element in an array containing odd elements first and then even elements. | [
"assert get_Number(8,5) == 2",
"assert get_Number(7,2) == 3",
"assert get_Number(5,2) == 3"
] | [] | def get_Number(n, k):
''' Write a python function to find the kth element in an array containing odd elements first and then even elements.
>>> get_Number(8, 5)
2
>>> get_Number(7, 2)
3
>>> get_Number(5, 2)
3
''' | ```python
def get_Number(n, k):
''' Write a python function to find the kth element in an array containing odd elements first and then even elements.
>>> get_Number(8, 5)
2
>>> get_Number(7, 2)
3
>>> get_Number(5, 2)
3
'''
arr = [0] * n;
i = 0;
odd = 1;
while (odd <= ... | [
{
"role": "user",
"content": "def get_Number(n, k): \n\t''' Write a python function to find the kth element in an array containing odd elements first and then even elements.\n\t>>> get_Number(8, 5)\n\t2\n\t>>> get_Number(7, 2)\n\t3\n\t>>> get_Number(5, 2)\n\t3\n\t'''"
},
{
"role": "assistant",
"... | |
845 | train | Write a python function to count the number of digits in factorial of a given number. | [
"assert find_Digits(7) == 4",
"assert find_Digits(5) == 3",
"assert find_Digits(4) == 2"
] | [] | import math
def find_Digits(n):
''' Write a python function to count the number of digits in factorial of a given number.
>>> find_Digits(7)
4
>>> find_Digits(5)
3
>>> find_Digits(4)
2
''' | ```python
import math
def find_Digits(n):
''' Write a python function to count the number of digits in factorial of a given number.
>>> find_Digits(7)
4
>>> find_Digits(5)
3
>>> find_Digits(4)
2
'''
if (n < 0):
return 0;
if (n <= 1):
return 1;
x = ((n * ma... | [
{
"role": "user",
"content": "import math\ndef find_Digits(n): \n\t''' Write a python function to count the number of digits in factorial of a given number.\n\t>>> find_Digits(7)\n\t4\n\t>>> find_Digits(5)\n\t3\n\t>>> find_Digits(4)\n\t2\n\t'''"
},
{
"role": "assistant",
"content": "```python\ni... | |
846 | train | Write a function to find the minimum number of platforms required for a railway/bus station. | [
"assert find_platform([900, 940, 950, 1100, 1500, 1800],[910, 1200, 1120, 1130, 1900, 2000],6)==3",
"assert find_platform([100,200,300,400],[700,800,900,1000],4)==4",
"assert find_platform([5,6,7,8],[4,3,2,1],4)==1"
] | [] | def find_platform(arr, dep, n):
''' Write a function to find the minimum number of platforms required for a railway/bus station.
>>> find_platform([900, 940, 950, 1100, 1500, 1800], [910, 1200, 1120, 1130, 1900, 2000], 6)
3
>>> find_platform([100, 200, 300, 400], [700, 800, 900, 1000], 4)
4
>>> find_platform([5,... | ```python
def find_platform(arr, dep, n):
''' Write a function to find the minimum number of platforms required for a railway/bus station.
>>> find_platform([900, 940, 950, 1100, 1500, 1800], [910, 1200, 1120, 1130, 1900, 2000], 6)
3
>>> find_platform([100, 200, 300, 400], [700, 800, 900, 1000], 4)
... | [
{
"role": "user",
"content": "def find_platform(arr, dep, n): \n\t''' Write a function to find the minimum number of platforms required for a railway/bus station.\n\t>>> find_platform([900, 940, 950, 1100, 1500, 1800], [910, 1200, 1120, 1130, 1900, 2000], 6)\n\t3\n\t>>> find_platform([100, 200, 300, 400], [... | |
847 | train | Write a python function to copy a list from a singleton tuple. | [
"assert lcopy([1, 2, 3]) == [1, 2, 3]",
"assert lcopy([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18]",
"assert lcopy([4, 5, 6]) == [4, 5, 6]\n"
] | [] | def lcopy(xs):
''' Write a python function to copy a list from a singleton tuple.
>>> lcopy([1, 2, 3])
[1, 2, 3]
>>> lcopy([4, 8, 2, 10, 15, 18])
[4, 8, 2, 10, 15, 18]
>>> lcopy([4, 5, 6])
[4, 5, 6]
''' | ```python
def lcopy(xs):
''' Write a python function to copy a list from a singleton tuple.
>>> lcopy([1, 2, 3])
[1, 2, 3]
>>> lcopy([4, 8, 2, 10, 15, 18])
[4, 8, 2, 10, 15, 18]
>>> lcopy([4, 5, 6])
[4, 5, 6]
'''
return xs[:]
``` | [
{
"role": "user",
"content": "def lcopy(xs):\n\t''' Write a python function to copy a list from a singleton tuple.\n\t>>> lcopy([1, 2, 3])\n\t[1, 2, 3]\n\t>>> lcopy([4, 8, 2, 10, 15, 18])\n\t[4, 8, 2, 10, 15, 18]\n\t>>> lcopy([4, 5, 6])\n\t[4, 5, 6]\n\t'''"
},
{
"role": "assistant",
"content": "... | |
848 | train | Write a function to find the area of a trapezium. | [
"assert area_trapezium(6,9,4)==30",
"assert area_trapezium(10,20,30)==450",
"assert area_trapezium(15,25,35)==700"
] | [] | def area_trapezium(base1,base2,height):
''' Write a function to find the area of a trapezium.
>>> area_trapezium(6, 9, 4)
30
>>> area_trapezium(10, 20, 30)
450
>>> area_trapezium(15, 25, 35)
700
''' | ```python
def area_trapezium(base1,base2,height):
''' Write a function to find the area of a trapezium.
>>> area_trapezium(6, 9, 4)
30
>>> area_trapezium(10, 20, 30)
450
>>> area_trapezium(15, 25, 35)
700
'''
area = 0.5 * (base1 + base2) * height
return area
``` | [
{
"role": "user",
"content": "def area_trapezium(base1,base2,height):\n\t''' Write a function to find the area of a trapezium.\n\t>>> area_trapezium(6, 9, 4)\n\t30\n\t>>> area_trapezium(10, 20, 30)\n\t450\n\t>>> area_trapezium(15, 25, 35)\n\t700\n\t'''"
},
{
"role": "assistant",
"content": "```p... | |
849 | train | Write a python function to find sum of all prime divisors of a given number. | [
"assert Sum(60) == 10",
"assert Sum(39) == 16",
"assert Sum(40) == 7"
] | [] | def Sum(N):
''' Write a python function to find sum of all prime divisors of a given number.
>>> Sum(60)
10
>>> Sum(39)
16
>>> Sum(40)
7
''' | ```python
def Sum(N):
''' Write a python function to find sum of all prime divisors of a given number.
>>> Sum(60)
10
>>> Sum(39)
16
>>> Sum(40)
7
'''
SumOfPrimeDivisors = [0]*(N + 1)
for i in range(2,N + 1) :
if (SumOfPrimeDivisors[i] == 0) :
for j in r... | [
{
"role": "user",
"content": "def Sum(N): \n\t''' Write a python function to find sum of all prime divisors of a given number.\n\t>>> Sum(60)\n\t10\n\t>>> Sum(39)\n\t16\n\t>>> Sum(40)\n\t7\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef Sum(N): \n ''' Write a python function to f... | |
850 | train | Write a function to check if a triangle of positive area is possible with the given angles. | [
"assert is_triangleexists(50,60,70)==True",
"assert is_triangleexists(90,45,45)==True",
"assert is_triangleexists(150,30,70)==False"
] | [] | def is_triangleexists(a,b,c):
''' Write a function to check if a triangle of positive area is possible with the given angles.
>>> is_triangleexists(50, 60, 70)
True
>>> is_triangleexists(90, 45, 45)
True
>>> is_triangleexists(150, 30, 70)
False
''' | ```python
def is_triangleexists(a,b,c):
''' Write a function to check if a triangle of positive area is possible with the given angles.
>>> is_triangleexists(50, 60, 70)
True
>>> is_triangleexists(90, 45, 45)
True
>>> is_triangleexists(150, 30, 70)
False
'''
if(a != 0 and b != 0 and... | [
{
"role": "user",
"content": "def is_triangleexists(a,b,c): \n\t''' Write a function to check if a triangle of positive area is possible with the given angles.\n\t>>> is_triangleexists(50, 60, 70)\n\tTrue\n\t>>> is_triangleexists(90, 45, 45)\n\tTrue\n\t>>> is_triangleexists(150, 30, 70)\n\tFalse\n\t'''"
}... | |
851 | train | Write a python function to find sum of inverse of divisors. | [
"assert Sum_of_Inverse_Divisors(6,12) == 2",
"assert Sum_of_Inverse_Divisors(9,13) == 1.44",
"assert Sum_of_Inverse_Divisors(1,4) == 4"
] | [] | def Sum_of_Inverse_Divisors(N,Sum):
''' Write a python function to find sum of inverse of divisors.
>>> Sum_of_Inverse_Divisors(6, 12)
2
>>> Sum_of_Inverse_Divisors(9, 13)
1.44
>>> Sum_of_Inverse_Divisors(1, 4)
4
''' | ```python
def Sum_of_Inverse_Divisors(N,Sum):
''' Write a python function to find sum of inverse of divisors.
>>> Sum_of_Inverse_Divisors(6, 12)
2
>>> Sum_of_Inverse_Divisors(9, 13)
1.44
>>> Sum_of_Inverse_Divisors(1, 4)
4
'''
ans = float(Sum)*1.0 /float(N);
return round(ans,2... | [
{
"role": "user",
"content": "def Sum_of_Inverse_Divisors(N,Sum): \n\t''' Write a python function to find sum of inverse of divisors.\n\t>>> Sum_of_Inverse_Divisors(6, 12)\n\t2\n\t>>> Sum_of_Inverse_Divisors(9, 13)\n\t1.44\n\t>>> Sum_of_Inverse_Divisors(1, 4)\n\t4\n\t'''"
},
{
"role": "assistant",
... | |
852 | train | Write a python function to remove negative numbers from a list. | [
"assert remove_negs([1,-2,3,-4]) == [1,3]",
"assert remove_negs([1,2,3,-4]) == [1,2,3]",
"assert remove_negs([4,5,-6,7,-8]) == [4,5,7]"
] | [] | def remove_negs(num_list):
''' Write a python function to remove negative numbers from a list.
>>> remove_negs([1, -2, 3, -4])
[1, 3]
>>> remove_negs([1, 2, 3, -4])
[1, 2, 3]
>>> remove_negs([4, 5, -6, 7, -8])
[4, 5, 7]
''' | ```python
def remove_negs(num_list):
''' Write a python function to remove negative numbers from a list.
>>> remove_negs([1, -2, 3, -4])
[1, 3]
>>> remove_negs([1, 2, 3, -4])
[1, 2, 3]
>>> remove_negs([4, 5, -6, 7, -8])
[4, 5, 7]
'''
for item in num_list:
if item < 0:
... | [
{
"role": "user",
"content": "def remove_negs(num_list): \n\t''' Write a python function to remove negative numbers from a list.\n\t>>> remove_negs([1, -2, 3, -4])\n\t[1, 3]\n\t>>> remove_negs([1, 2, 3, -4])\n\t[1, 2, 3]\n\t>>> remove_negs([4, 5, -6, 7, -8])\n\t[4, 5, 7]\n\t'''"
},
{
"role": "assist... | |
853 | train | Write a python function to find sum of odd factors of a number. | [
"assert sum_of_odd_Factors(30) == 24",
"assert sum_of_odd_Factors(18) == 13",
"assert sum_of_odd_Factors(2) == 1"
] | [] | import math
def sum_of_odd_Factors(n):
''' Write a python function to find sum of odd factors of a number.
>>> sum_of_odd_Factors(30)
24
>>> sum_of_odd_Factors(18)
13
>>> sum_of_odd_Factors(2)
1
''' | ```python
import math
def sum_of_odd_Factors(n):
''' Write a python function to find sum of odd factors of a number.
>>> sum_of_odd_Factors(30)
24
>>> sum_of_odd_Factors(18)
13
>>> sum_of_odd_Factors(2)
1
'''
res = 1
while n % 2 == 0:
n = n // 2
for i in range(3,in... | [
{
"role": "user",
"content": "import math\ndef sum_of_odd_Factors(n): \n\t''' Write a python function to find sum of odd factors of a number.\n\t>>> sum_of_odd_Factors(30)\n\t24\n\t>>> sum_of_odd_Factors(18)\n\t13\n\t>>> sum_of_odd_Factors(2)\n\t1\n\t'''"
},
{
"role": "assistant",
"content": "``... | |
854 | train | Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm. | [
"assert raw_heap([25, 44, 68, 21, 39, 23, 89])==[21, 25, 23, 44, 39, 68, 89]",
"assert raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])== [14, 25, 22, 25, 35, 65, 75, 85, 58]",
"assert raw_heap([4, 5, 6, 2])==[2, 4, 6, 5]"
] | [] | import heapq as hq
def raw_heap(rawheap):
''' Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.
>>> raw_heap([25, 44, 68, 21, 39, 23, 89])
[21, 25, 23, 44, 39, 68, 89]
>>> raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])
[14, 25, 22, 25, 35, 65, 75, 85, 58]
>>> r... | ```python
import heapq as hq
def raw_heap(rawheap):
''' Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.
>>> raw_heap([25, 44, 68, 21, 39, 23, 89])
[21, 25, 23, 44, 39, 68, 89]
>>> raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])
[14, 25, 22, 25, 35, 65, 75,... | [
{
"role": "user",
"content": "import heapq as hq\ndef raw_heap(rawheap):\n\t''' Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.\n\t>>> raw_heap([25, 44, 68, 21, 39, 23, 89])\n\t[21, 25, 23, 44, 39, 68, 89]\n\t>>> raw_heap([25, 35, 22, 85, 14, 65, 75, 25... | |
855 | train | Write a python function to check for even parity of a given number. | [
"assert check_Even_Parity(10) == True",
"assert check_Even_Parity(11) == False",
"assert check_Even_Parity(18) == True"
] | [] | def check_Even_Parity(x):
''' Write a python function to check for even parity of a given number.
>>> check_Even_Parity(10)
True
>>> check_Even_Parity(11)
False
>>> check_Even_Parity(18)
True
''' | ```python
def check_Even_Parity(x):
''' Write a python function to check for even parity of a given number.
>>> check_Even_Parity(10)
True
>>> check_Even_Parity(11)
False
>>> check_Even_Parity(18)
True
'''
parity = 0
while (x != 0):
x = x & (x - 1)
parity += 1
... | [
{
"role": "user",
"content": "def check_Even_Parity(x): \n\t''' Write a python function to check for even parity of a given number.\n\t>>> check_Even_Parity(10)\n\tTrue\n\t>>> check_Even_Parity(11)\n\tFalse\n\t>>> check_Even_Parity(18)\n\tTrue\n\t'''"
},
{
"role": "assistant",
"content": "```pyt... | |
856 | train | Write a python function to find minimum adjacent swaps required to sort binary array. | [
"assert find_Min_Swaps([1,0,1,0],4) == 3",
"assert find_Min_Swaps([0,1,0],3) == 1",
"assert find_Min_Swaps([0,0,1,1,0],5) == 2"
] | [] | def find_Min_Swaps(arr,n) :
''' Write a python function to find minimum adjacent swaps required to sort binary array.
>>> find_Min_Swaps([1, 0, 1, 0], 4)
3
>>> find_Min_Swaps([0, 1, 0], 3)
1
>>> find_Min_Swaps([0, 0, 1, 1, 0], 5)
2
''' | ```python
def find_Min_Swaps(arr,n) :
''' Write a python function to find minimum adjacent swaps required to sort binary array.
>>> find_Min_Swaps([1, 0, 1, 0], 4)
3
>>> find_Min_Swaps([0, 1, 0], 3)
1
>>> find_Min_Swaps([0, 0, 1, 1, 0], 5)
2
'''
noOfZeroes = [0] * n
count = 0
... | [
{
"role": "user",
"content": "def find_Min_Swaps(arr,n) : \n\t''' Write a python function to find minimum adjacent swaps required to sort binary array.\n\t>>> find_Min_Swaps([1, 0, 1, 0], 4)\n\t3\n\t>>> find_Min_Swaps([0, 1, 0], 3)\n\t1\n\t>>> find_Min_Swaps([0, 0, 1, 1, 0], 5)\n\t2\n\t'''"
},
{
"ro... | |
857 | train | Write a function to list out the list of given strings individually using map function. | [
"assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]",
"assert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]",
"assert listify_list([' red ', 'green',' black', 'blue ',' o... | [] | def listify_list(list1):
''' Write a function to list out the list of given strings individually using map function.
>>> listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])
[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
>>> listify_list(['pyth... | ```python
def listify_list(list1):
''' Write a function to list out the list of given strings individually using map function.
>>> listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])
[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
>>> listi... | [
{
"role": "user",
"content": "def listify_list(list1):\n\t''' Write a function to list out the list of given strings individually using map function.\n\t>>> listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])\n\t[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e']... | |
858 | train | Write a function to count number of lists in a given list of lists and square the count. | [
"assert count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==25",
"assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]] )==16",
"assert count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])==9"
] | [] | def count_list(input_list):
''' Write a function to count number of lists in a given list of lists and square the count.
>>> count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])
25
>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])
16
>>> count_list([[2, 4], [[6, 8], [4, 5, 8]], [10, 12, 14]])
9
''' | ```python
def count_list(input_list):
''' Write a function to count number of lists in a given list of lists and square the count.
>>> count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])
25
>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])
16
>>> count_list([[2, 4], [[6, 8], [4, 5, 8... | [
{
"role": "user",
"content": "def count_list(input_list): \n\t''' Write a function to count number of lists in a given list of lists and square the count.\n\t>>> count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])\n\t25\n\t>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])\n\t16\n\t>>> count_list(... | |
859 | train | Write a function to generate all sublists of a given list. | [
"assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]",
"assert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z'... | [] | from itertools import combinations
def sub_lists(my_list):
''' Write a function to generate all sublists of a given list.
>>> sub_lists([10, 20, 30, 40])
[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]
... | ```python
from itertools import combinations
def sub_lists(my_list):
''' Write a function to generate all sublists of a given list.
>>> sub_lists([10, 20, 30, 40])
[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20,... | [
{
"role": "user",
"content": "from itertools import combinations\ndef sub_lists(my_list):\n\t''' Write a function to generate all sublists of a given list.\n\t>>> sub_lists([10, 20, 30, 40])\n\t[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40... | |
860 | train | Write a function to check whether the given string is ending with only alphanumeric characters or not using regex. | [
"assert check_alphanumeric(\"dawood@\") == 'Discard'",
"assert check_alphanumeric(\"skdmsam326\") == 'Accept'",
"assert check_alphanumeric(\"cooltricks@\") == 'Discard'"
] | [] | import re
regex = '[a-zA-z0-9]$'
def check_alphanumeric(string):
''' Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.
>>> check_alphanumeric('dawood@')
'Discard'
>>> check_alphanumeric('skdmsam326')
'Accept'
>>> check_alphanumeric('cooltricks@')
... | ```python
import re
regex = '[a-zA-z0-9]$'
def check_alphanumeric(string):
''' Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.
>>> check_alphanumeric('dawood@')
'Discard'
>>> check_alphanumeric('skdmsam326')
'Accept'
>>> check_alphanumeric('cool... | [
{
"role": "user",
"content": "import re \nregex = '[a-zA-z0-9]$'\ndef check_alphanumeric(string): \n\t''' Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.\n\t>>> check_alphanumeric('dawood@')\n\t'Discard'\n\t>>> check_alphanumeric('skdmsam326... | |
861 | train | Write a function to find all anagrams of a string in a given list of strings using lambda function. | [
"assert anagram_lambda([\"bcda\", \"abce\", \"cbda\", \"cbea\", \"adcb\"],\"abcd\")==['bcda', 'cbda', 'adcb']",
"assert anagram_lambda([\"recitals\",\" python\"], \"articles\" )==[\"recitals\"]",
"assert anagram_lambda([\" keep\",\" abcdef\",\" xyz\"],\" peek\")==[\" keep\"]"
] | [] | from collections import Counter
def anagram_lambda(texts,str):
''' Write a function to find all anagrams of a string in a given list of strings using lambda function.
>>> anagram_lambda(['bcda', 'abce', 'cbda', 'cbea', 'adcb'], 'abcd')
['bcda', 'cbda', 'adcb']
>>> anagram_lambda(['recitals', ' python'], 'articles')... | ```python
from collections import Counter
def anagram_lambda(texts,str):
''' Write a function to find all anagrams of a string in a given list of strings using lambda function.
>>> anagram_lambda(['bcda', 'abce', 'cbda', 'cbea', 'adcb'], 'abcd')
['bcda', 'cbda', 'adcb']
>>> anagram_lambda(['recitals', ' python'... | [
{
"role": "user",
"content": "from collections import Counter\ndef anagram_lambda(texts,str):\n\t''' Write a function to find all anagrams of a string in a given list of strings using lambda function.\n\t>>> anagram_lambda(['bcda', 'abce', 'cbda', 'cbea', 'adcb'], 'abcd')\n\t['bcda', 'cbda', 'adcb']\n\t>>> ... | |
862 | train | Write a function to find the occurrences of n most common words in a given text. | [
"assert n_common_words(\"python is a programming language\",1)==[('python', 1)]",
"assert n_common_words(\"python is a programming language\",1)==[('python', 1)]",
"assert n_common_words(\"python is a programming language\",5)==[('python', 1),('is', 1), ('a', 1), ('programming', 1), ('language', 1)]"
] | [] | from collections import Counter
import re
def n_common_words(text,n):
''' Write a function to find the occurrences of n most common words in a given text.
>>> n_common_words('python is a programming language', 1)
[('python', 1)]
>>> n_common_words('python is a programming language', 1)
[('python', 1)]
>>> n_commo... | ```python
from collections import Counter
import re
def n_common_words(text,n):
''' Write a function to find the occurrences of n most common words in a given text.
>>> n_common_words('python is a programming language', 1)
[('python', 1)]
>>> n_common_words('python is a programming language', 1)
[('python', 1... | [
{
"role": "user",
"content": "from collections import Counter\nimport re\ndef n_common_words(text,n):\n\t''' Write a function to find the occurrences of n most common words in a given text.\n\t>>> n_common_words('python is a programming language', 1)\n\t[('python', 1)]\n\t>>> n_common_words('python is a pro... | |
863 | train | Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers. | [
"assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3",
"assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4",
"assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5"
] | [] | def find_longest_conseq_subseq(arr, n):
''' Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
>>> find_longest_conseq_subseq([1, 2, 2, 3], 4)
3
>>> find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7)
4
>>> find_longest_conseq_subse... | ```python
def find_longest_conseq_subseq(arr, n):
''' Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
>>> find_longest_conseq_subseq([1, 2, 2, 3], 4)
3
>>> find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7)
4
>>> find_longest_co... | [
{
"role": "user",
"content": "def find_longest_conseq_subseq(arr, n): \n\t''' Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.\n\t>>> find_longest_conseq_subseq([1, 2, 2, 3], 4)\n\t3\n\t>>> find_longest_conseq_subseq([1, 9, 3, 1... | |
864 | train | Write a function to find palindromes in a given list of strings using lambda function. | [
"assert palindrome_lambda([\"php\", \"res\", \"Python\", \"abcd\", \"Java\", \"aaa\"])==['php', 'aaa']",
"assert palindrome_lambda([\"abcd\", \"Python\", \"abba\", \"aba\"])==['abba', 'aba']",
"assert palindrome_lambda([\"abcd\", \"abbccbba\", \"abba\", \"aba\"])==['abbccbba', 'abba', 'aba']"
] | [] | def palindrome_lambda(texts):
''' Write a function to find palindromes in a given list of strings using lambda function.
>>> palindrome_lambda(['php', 'res', 'Python', 'abcd', 'Java', 'aaa'])
['php', 'aaa']
>>> palindrome_lambda(['abcd', 'Python', 'abba', 'aba'])
['abba', 'aba']
>>> palindrome_lambda(['abcd', 'ab... | ```python
def palindrome_lambda(texts):
''' Write a function to find palindromes in a given list of strings using lambda function.
>>> palindrome_lambda(['php', 'res', 'Python', 'abcd', 'Java', 'aaa'])
['php', 'aaa']
>>> palindrome_lambda(['abcd', 'Python', 'abba', 'aba'])
['abba', 'aba']
>>> palindrome_lam... | [
{
"role": "user",
"content": "def palindrome_lambda(texts):\n\t''' Write a function to find palindromes in a given list of strings using lambda function.\n\t>>> palindrome_lambda(['php', 'res', 'Python', 'abcd', 'Java', 'aaa'])\n\t['php', 'aaa']\n\t>>> palindrome_lambda(['abcd', 'Python', 'abba', 'aba'])\n\... | |
865 | train | Write a function to print n-times a list using map function. | [
"assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21]",
"assert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28]",
"assert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70]"
] | [] | def ntimes_list(nums,n):
''' Write a function to print n-times a list using map function.
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 3)
[3, 6, 9, 12, 15, 18, 21]
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 4)
[4, 8, 12, 16, 20, 24, 28]
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 10)
[10, 20, 30, 40, 50, 60, 70]
''' | ```python
def ntimes_list(nums,n):
''' Write a function to print n-times a list using map function.
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 3)
[3, 6, 9, 12, 15, 18, 21]
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 4)
[4, 8, 12, 16, 20, 24, 28]
>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 10)
[10, 20, 30,... | [
{
"role": "user",
"content": "def ntimes_list(nums,n):\n\t''' Write a function to print n-times a list using map function.\n\t>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 3)\n\t[3, 6, 9, 12, 15, 18, 21]\n\t>>> ntimes_list([1, 2, 3, 4, 5, 6, 7], 4)\n\t[4, 8, 12, 16, 20, 24, 28]\n\t>>> ntimes_list([1, 2, 3, 4, 5, 6... | |
866 | train | Write a function to check whether the given month name contains 31 days or not. | [
"assert check_monthnumb(\"February\")==False",
"assert check_monthnumb(\"January\")==True",
"assert check_monthnumb(\"March\")==True"
] | [] | def check_monthnumb(monthname2):
''' Write a function to check whether the given month name contains 31 days or not.
>>> check_monthnumb('February')
False
>>> check_monthnumb('January')
True
>>> check_monthnumb('March')
True
''' | ```python
def check_monthnumb(monthname2):
''' Write a function to check whether the given month name contains 31 days or not.
>>> check_monthnumb('February')
False
>>> check_monthnumb('January')
True
>>> check_monthnumb('March')
True
'''
if(monthname2=="January" or monthname2=="March"or monthname2=="... | [
{
"role": "user",
"content": "def check_monthnumb(monthname2):\n\t''' Write a function to check whether the given month name contains 31 days or not.\n\t>>> check_monthnumb('February')\n\tFalse\n\t>>> check_monthnumb('January')\n\tTrue\n\t>>> check_monthnumb('March')\n\tTrue\n\t'''"
},
{
"role": "as... | |
867 | train | Write a python function to add a minimum number such that the sum of array becomes even. | [
"assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1",
"assert min_Num([1,2,3,4,5,6,7,8],8) == 2",
"assert min_Num([1,2,3],3) == 2"
] | [] | def min_Num(arr,n):
''' Write a python function to add a minimum number such that the sum of array becomes even.
>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8, 9], 9)
1
>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8], 8)
2
>>> min_Num([1, 2, 3], 3)
2
''' | ```python
def min_Num(arr,n):
''' Write a python function to add a minimum number such that the sum of array becomes even.
>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8, 9], 9)
1
>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8], 8)
2
>>> min_Num([1, 2, 3], 3)
2
'''
odd = 0
for i in range(n):
... | [
{
"role": "user",
"content": "def min_Num(arr,n): \n\t''' Write a python function to add a minimum number such that the sum of array becomes even.\n\t>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8, 9], 9)\n\t1\n\t>>> min_Num([1, 2, 3, 4, 5, 6, 7, 8], 8)\n\t2\n\t>>> min_Num([1, 2, 3], 3)\n\t2\n\t'''"
},
{
"rol... | |
868 | train | Write a python function to find the length of the last word in a given string. | [
"assert length_Of_Last_Word(\"python language\") == 8",
"assert length_Of_Last_Word(\"PHP\") == 3",
"assert length_Of_Last_Word(\"\") == 0"
] | [] | def length_Of_Last_Word(a):
''' Write a python function to find the length of the last word in a given string.
>>> length_Of_Last_Word('python language')
8
>>> length_Of_Last_Word('PHP')
3
>>> length_Of_Last_Word('')
0
''' | ```python
def length_Of_Last_Word(a):
''' Write a python function to find the length of the last word in a given string.
>>> length_Of_Last_Word('python language')
8
>>> length_Of_Last_Word('PHP')
3
>>> length_Of_Last_Word('')
0
'''
l = 0
x = a.strip()
for i in range(len(x)... | [
{
"role": "user",
"content": "def length_Of_Last_Word(a): \n\t''' Write a python function to find the length of the last word in a given string.\n\t>>> length_Of_Last_Word('python language')\n\t8\n\t>>> length_Of_Last_Word('PHP')\n\t3\n\t>>> length_Of_Last_Word('')\n\t0\n\t'''"
},
{
"role": "assista... | |
869 | train | Write a function to remove sublists from a given list of lists, which are outside a given range. | [
"assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]]",
"assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[2], [1, 2, 3]]",
"assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], ... | [] | def remove_list_range(list1, leftrange, rigthrange):
''' Write a function to remove sublists from a given list of lists, which are outside a given range.
>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 13, 17)
[[13, 14, 15, 17]]
>>> remove_list_range([[2], [0], [1, 2, 3],... | ```python
def remove_list_range(list1, leftrange, rigthrange):
''' Write a function to remove sublists from a given list of lists, which are outside a given range.
>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 13, 17)
[[13, 14, 15, 17]]
>>> remove_list_range([[2... | [
{
"role": "user",
"content": "def remove_list_range(list1, leftrange, rigthrange):\n\t''' Write a function to remove sublists from a given list of lists, which are outside a given range.\n\t>>> remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]], 13, 17)\n\t[[13, 14, 15, 1... | |
870 | train | Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function. | [
"assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48",
"assert sum_positivenum([10,15,-14,13,-18,12,-20])==50",
"assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522"
] | [] | def sum_positivenum(nums):
''' Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.
>>> sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])
48
>>> sum_positivenum([10, 15, -14, 13, -18, 12, -20])
50
>>> sum_positivenum([19, -65, 57, 39, 152, -639, 121, 4... | ```python
def sum_positivenum(nums):
''' Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.
>>> sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])
48
>>> sum_positivenum([10, 15, -14, 13, -18, 12, -20])
50
>>> sum_positivenum([19, -65, 57, 39, 1... | [
{
"role": "user",
"content": "def sum_positivenum(nums):\n\t''' Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.\n\t>>> sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])\n\t48\n\t>>> sum_positivenum([10, 15, -14, 13, -18, 12, -20])\n\t50\n\t>... | |
871 | train | Write a python function to check whether the given strings are rotations of each other or not. | [
"assert are_Rotations(\"abc\",\"cba\") == False",
"assert are_Rotations(\"abcd\",\"cdba\") == False",
"assert are_Rotations(\"abacd\",\"cdaba\") == True"
] | [] | def are_Rotations(string1,string2):
''' Write a python function to check whether the given strings are rotations of each other or not.
>>> are_Rotations('abc', 'cba')
False
>>> are_Rotations('abcd', 'cdba')
False
>>> are_Rotations('abacd', 'cdaba')
True
''' | ```python
def are_Rotations(string1,string2):
''' Write a python function to check whether the given strings are rotations of each other or not.
>>> are_Rotations('abc', 'cba')
False
>>> are_Rotations('abcd', 'cdba')
False
>>> are_Rotations('abacd', 'cdaba')
True
'''
size1 = len(str... | [
{
"role": "user",
"content": "def are_Rotations(string1,string2): \n\t''' Write a python function to check whether the given strings are rotations of each other or not.\n\t>>> are_Rotations('abc', 'cba')\n\tFalse\n\t>>> are_Rotations('abcd', 'cdba')\n\tFalse\n\t>>> are_Rotations('abacd', 'cdaba')\n\tTrue\n\... | |
872 | train | Write a function to check if a nested list is a subset of another nested list. | [
"assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True",
"assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True",
"assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False"
] | [] | def check_subset(list1,list2):
''' Write a function to check if a nested list is a subset of another nested list.
>>> check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]], [[1, 3], [13, 15, 17]])
True
>>> check_subset([[1, 2], [2, 3], [3, 4], [5, 6]], [[3, 4], [5, 6]])
True
>>> check_subset([[[1, 2], [2, 3]], [[... | ```python
def check_subset(list1,list2):
''' Write a function to check if a nested list is a subset of another nested list.
>>> check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]], [[1, 3], [13, 15, 17]])
True
>>> check_subset([[1, 2], [2, 3], [3, 4], [5, 6]], [[3, 4], [5, 6]])
True
>>> check_... | [
{
"role": "user",
"content": "def check_subset(list1,list2): \n\t''' Write a function to check if a nested list is a subset of another nested list.\n\t>>> check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]], [[1, 3], [13, 15, 17]])\n\tTrue\n\t>>> check_subset([[1, 2], [2, 3], [3, 4], [5, 6]], [[3, 4], [5, ... | |
873 | train | Write a function to solve the fibonacci sequence using recursion. | [
"assert fibonacci(7) == 13",
"assert fibonacci(8) == 21",
"assert fibonacci(9) == 34"
] | [] | def fibonacci(n):
''' Write a function to solve the fibonacci sequence using recursion.
>>> fibonacci(7)
13
>>> fibonacci(8)
21
>>> fibonacci(9)
34
''' | ```python
def fibonacci(n):
''' Write a function to solve the fibonacci sequence using recursion.
>>> fibonacci(7)
13
>>> fibonacci(8)
21
>>> fibonacci(9)
34
'''
if n == 1 or n == 2:
return 1
else:
return (fibonacci(n - 1) + (fibonacci(n - 2)))
``` | [
{
"role": "user",
"content": "def fibonacci(n):\n\t''' Write a function to solve the fibonacci sequence using recursion.\n\t>>> fibonacci(7)\n\t13\n\t>>> fibonacci(8)\n\t21\n\t>>> fibonacci(9)\n\t34\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef fibonacci(n):\n ''' Write a functio... | |
874 | train | Write a python function to check if the string is a concatenation of another string. | [
"assert check_Concat(\"abcabcabc\",\"abc\") == True",
"assert check_Concat(\"abcab\",\"abc\") == False",
"assert check_Concat(\"aba\",\"ab\") == False"
] | [] | def check_Concat(str1,str2):
''' Write a python function to check if the string is a concatenation of another string.
>>> check_Concat('abcabcabc', 'abc')
True
>>> check_Concat('abcab', 'abc')
False
>>> check_Concat('aba', 'ab')
False
''' | ```python
def check_Concat(str1,str2):
''' Write a python function to check if the string is a concatenation of another string.
>>> check_Concat('abcabcabc', 'abc')
True
>>> check_Concat('abcab', 'abc')
False
>>> check_Concat('aba', 'ab')
False
'''
N = len(str1)
M = len(str2)
... | [
{
"role": "user",
"content": "def check_Concat(str1,str2):\n\t''' Write a python function to check if the string is a concatenation of another string.\n\t>>> check_Concat('abcabcabc', 'abc')\n\tTrue\n\t>>> check_Concat('abcab', 'abc')\n\tFalse\n\t>>> check_Concat('aba', 'ab')\n\tFalse\n\t'''"
},
{
"... | |
875 | train | Write a function to find the minimum difference in the tuple pairs of given tuples. | [
"assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1",
"assert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2",
"assert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6"
] | [] | def min_difference(test_list):
''' Write a function to find the minimum difference in the tuple pairs of given tuples.
>>> min_difference([(3, 5), (1, 7), (10, 3), (1, 2)])
1
>>> min_difference([(4, 6), (12, 8), (11, 4), (2, 13)])
2
>>> min_difference([(5, 17), (3, 9), (12, 5), (3, 24)])
6
''' | ```python
def min_difference(test_list):
''' Write a function to find the minimum difference in the tuple pairs of given tuples.
>>> min_difference([(3, 5), (1, 7), (10, 3), (1, 2)])
1
>>> min_difference([(4, 6), (12, 8), (11, 4), (2, 13)])
2
>>> min_difference([(5, 17), (3, 9), (12, 5), (3, 24)])
6
'''... | [
{
"role": "user",
"content": "def min_difference(test_list):\n\t''' Write a function to find the minimum difference in the tuple pairs of given tuples.\n\t>>> min_difference([(3, 5), (1, 7), (10, 3), (1, 2)])\n\t1\n\t>>> min_difference([(4, 6), (12, 8), (11, 4), (2, 13)])\n\t2\n\t>>> min_difference([(5, 17)... | |
876 | train | Write a python function to find lcm of two positive integers. | [
"assert lcm(4,6) == 12",
"assert lcm(15,17) == 255",
"assert lcm(2,6) == 6"
] | [] | def lcm(x, y):
''' Write a python function to find lcm of two positive integers.
>>> lcm(4, 6)
12
>>> lcm(15, 17)
255
>>> lcm(2, 6)
6
''' | ```python
def lcm(x, y):
''' Write a python function to find lcm of two positive integers.
>>> lcm(4, 6)
12
>>> lcm(15, 17)
255
>>> lcm(2, 6)
6
'''
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
... | [
{
"role": "user",
"content": "def lcm(x, y):\n\t''' Write a python function to find lcm of two positive integers.\n\t>>> lcm(4, 6)\n\t12\n\t>>> lcm(15, 17)\n\t255\n\t>>> lcm(2, 6)\n\t6\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef lcm(x, y):\n ''' Write a python function to find... | |
877 | train | Write a python function to sort the given string. | [
"assert sort_String(\"cba\") == \"abc\"",
"assert sort_String(\"data\") == \"aadt\"",
"assert sort_String(\"zxy\") == \"xyz\""
] | [] | def sort_String(str) :
''' Write a python function to sort the given string.
>>> sort_String('cba')
'abc'
>>> sort_String('data')
'aadt'
>>> sort_String('zxy')
'xyz'
''' | ```python
def sort_String(str) :
''' Write a python function to sort the given string.
>>> sort_String('cba')
'abc'
>>> sort_String('data')
'aadt'
>>> sort_String('zxy')
'xyz'
'''
str = ''.join(sorted(str))
return (str)
``` | [
{
"role": "user",
"content": "def sort_String(str) : \n\t''' Write a python function to sort the given string.\n\t>>> sort_String('cba')\n\t'abc'\n\t>>> sort_String('data')\n\t'aadt'\n\t>>> sort_String('zxy')\n\t'xyz'\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef sort_String(str) ... | |
878 | train | Write a function to check if the given tuple contains only k elements. | [
"assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True",
"assert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True",
"assert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False"
] | [] | def check_tuples(test_tuple, K):
''' Write a function to check if the given tuple contains only k elements.
>>> check_tuples((3, 5, 6, 5, 3, 6), [3, 6, 5])
True
>>> check_tuples((4, 5, 6, 4, 6, 5), [4, 5, 6])
True
>>> check_tuples((9, 8, 7, 6, 8, 9), [9, 8, 1])
False
''' | ```python
def check_tuples(test_tuple, K):
''' Write a function to check if the given tuple contains only k elements.
>>> check_tuples((3, 5, 6, 5, 3, 6), [3, 6, 5])
True
>>> check_tuples((4, 5, 6, 4, 6, 5), [4, 5, 6])
True
>>> check_tuples((9, 8, 7, 6, 8, 9), [9, 8, 1])
False
'''
res = all(ele in K f... | [
{
"role": "user",
"content": "def check_tuples(test_tuple, K):\n\t''' Write a function to check if the given tuple contains only k elements.\n\t>>> check_tuples((3, 5, 6, 5, 3, 6), [3, 6, 5])\n\tTrue\n\t>>> check_tuples((4, 5, 6, 4, 6, 5), [4, 5, 6])\n\tTrue\n\t>>> check_tuples((9, 8, 7, 6, 8, 9), [9, 8, 1]... | |
879 | train | Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex. | [
"assert text_match(\"aabbbbd\") == 'Not matched!'",
"assert text_match(\"aabAbbbc\") == 'Not matched!'",
"assert text_match(\"accddbbjjjb\") == 'Found a match!'"
] | [] | import re
def text_match(text):
''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
>>> text_match('aabbbbd')
'Not matched!'
>>> text_match('aabAbbbc')
'Not matched!'
>>> text_match('accddbbjjjb')
'Found a match!'
''' | ```python
import re
def text_match(text):
''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
>>> text_match('aabbbbd')
'Not matched!'
>>> text_match('aabAbbbc')
'Not matched!'
>>> text_match('accddbbjjjb')
'Found a match!'
'''
patterns = 'a.*... | [
{
"role": "user",
"content": "import re\ndef text_match(text):\n\t''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.\n\t>>> text_match('aabbbbd')\n\t'Not matched!'\n\t>>> text_match('aabAbbbc')\n\t'Not matched!'\n\t>>> text_match('accddbbjjjb')\n\t... | |
880 | train | Write a python function to find number of solutions in quadratic equation. | [
"assert Check_Solution(2,5,2) == \"2 solutions\"",
"assert Check_Solution(1,1,1) == \"No solutions\"",
"assert Check_Solution(1,2,1) == \"1 solution\""
] | [] | def Check_Solution(a,b,c) :
''' Write a python function to find number of solutions in quadratic equation.
>>> Check_Solution(2, 5, 2)
'2 solutions'
>>> Check_Solution(1, 1, 1)
'No solutions'
>>> Check_Solution(1, 2, 1)
'1 solution'
''' | ```python
def Check_Solution(a,b,c) :
''' Write a python function to find number of solutions in quadratic equation.
>>> Check_Solution(2, 5, 2)
'2 solutions'
>>> Check_Solution(1, 1, 1)
'No solutions'
>>> Check_Solution(1, 2, 1)
'1 solution'
'''
if ((b*b) - (4*a*c)) > 0 :
... | [
{
"role": "user",
"content": "def Check_Solution(a,b,c) : \n\t''' Write a python function to find number of solutions in quadratic equation.\n\t>>> Check_Solution(2, 5, 2)\n\t'2 solutions'\n\t>>> Check_Solution(1, 1, 1)\n\t'No solutions'\n\t>>> Check_Solution(1, 2, 1)\n\t'1 solution'\n\t'''"
},
{
"r... | |
881 | train | Write a function to find the sum of first even and odd number of a given list. | [
"assert sum_even_odd([1,3,5,7,4,1,6,8])==5",
"assert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3",
"assert sum_even_odd([1,5,7,9,10])==11"
] | [] | def sum_even_odd(list1):
''' Write a function to find the sum of first even and odd number of a given list.
>>> sum_even_odd([1, 3, 5, 7, 4, 1, 6, 8])
5
>>> sum_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
3
>>> sum_even_odd([1, 5, 7, 9, 10])
11
''' | ```python
def sum_even_odd(list1):
''' Write a function to find the sum of first even and odd number of a given list.
>>> sum_even_odd([1, 3, 5, 7, 4, 1, 6, 8])
5
>>> sum_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
3
>>> sum_even_odd([1, 5, 7, 9, 10])
11
'''
first_even = next((el for e... | [
{
"role": "user",
"content": "def sum_even_odd(list1):\n\t''' Write a function to find the sum of first even and odd number of a given list.\n\t>>> sum_even_odd([1, 3, 5, 7, 4, 1, 6, 8])\n\t5\n\t>>> sum_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n\t3\n\t>>> sum_even_odd([1, 5, 7, 9, 10])\n\t11\n\t'''"
},
... | |
882 | train | Write a function to caluclate perimeter of a parallelogram. | [
"assert parallelogram_perimeter(10,20)==400",
"assert parallelogram_perimeter(15,20)==600",
"assert parallelogram_perimeter(8,9)==144"
] | [] | def parallelogram_perimeter(b,h):
''' Write a function to caluclate perimeter of a parallelogram.
>>> parallelogram_perimeter(10, 20)
400
>>> parallelogram_perimeter(15, 20)
600
>>> parallelogram_perimeter(8, 9)
144
''' | ```python
def parallelogram_perimeter(b,h):
''' Write a function to caluclate perimeter of a parallelogram.
>>> parallelogram_perimeter(10, 20)
400
>>> parallelogram_perimeter(15, 20)
600
>>> parallelogram_perimeter(8, 9)
144
'''
perimeter=2*(b*h)
return perimeter
``` | [
{
"role": "user",
"content": "def parallelogram_perimeter(b,h):\n\t''' Write a function to caluclate perimeter of a parallelogram.\n\t>>> parallelogram_perimeter(10, 20)\n\t400\n\t>>> parallelogram_perimeter(15, 20)\n\t600\n\t>>> parallelogram_perimeter(8, 9)\n\t144\n\t'''"
},
{
"role": "assistant",... | |
883 | train | Write a function to find numbers divisible by m and n from a list of numbers using lambda function. | [
"assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44]",
"assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10]",
"assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20]"
] | [] | def div_of_nums(nums,m,n):
''' Write a function to find numbers divisible by m and n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 2, 4)
[152, 44]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[10]
>>> div_of_nums([10, 15, 14, 13, 18, 12, 20], 10, 5)
... | ```python
def div_of_nums(nums,m,n):
''' Write a function to find numbers divisible by m and n from a list of numbers using lambda function.
>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 2, 4)
[152, 44]
>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)
[10]
>>> div_of_nums([10, 15, 14, 13, 18, 12, 20]... | [
{
"role": "user",
"content": "def div_of_nums(nums,m,n):\n\t''' Write a function to find numbers divisible by m and n from a list of numbers using lambda function.\n\t>>> div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190], 2, 4)\n\t[152, 44]\n\t>>> div_of_nums([1, 2, 3, 5, 7, 8, 10], 2, 5)\n\t[10]\n\t... | |
884 | train | Write a python function to check whether all the bits are within a given range or not. | [
"assert all_Bits_Set_In_The_Given_Range(10,2,1) == True ",
"assert all_Bits_Set_In_The_Given_Range(5,2,4) == False",
"assert all_Bits_Set_In_The_Given_Range(22,2,3) == True "
] | [] | def all_Bits_Set_In_The_Given_Range(n,l,r):
''' Write a python function to check whether all the bits are within a given range or not.
>>> all_Bits_Set_In_The_Given_Range(10, 2, 1)
True
>>> all_Bits_Set_In_The_Given_Range(5, 2, 4)
False
>>> all_Bits_Set_In_The_Given_Range(22, 2, 3)
True
''' | ```python
def all_Bits_Set_In_The_Given_Range(n,l,r):
''' Write a python function to check whether all the bits are within a given range or not.
>>> all_Bits_Set_In_The_Given_Range(10, 2, 1)
True
>>> all_Bits_Set_In_The_Given_Range(5, 2, 4)
False
>>> all_Bits_Set_In_The_Given_Range(22, 2, 3)
... | [
{
"role": "user",
"content": "def all_Bits_Set_In_The_Given_Range(n,l,r): \n\t''' Write a python function to check whether all the bits are within a given range or not.\n\t>>> all_Bits_Set_In_The_Given_Range(10, 2, 1)\n\tTrue\n\t>>> all_Bits_Set_In_The_Given_Range(5, 2, 4)\n\tFalse\n\t>>> all_Bits_Set_In_Th... | |
885 | train | Write a python function to check whether the two given strings are isomorphic to each other or not. | [
"assert is_Isomorphic(\"paper\",\"title\") == True",
"assert is_Isomorphic(\"ab\",\"ba\") == True",
"assert is_Isomorphic(\"ab\",\"aa\") == False"
] | [] | def is_Isomorphic(str1,str2):
''' Write a python function to check whether the two given strings are isomorphic to each other or not.
>>> is_Isomorphic('paper', 'title')
True
>>> is_Isomorphic('ab', 'ba')
True
>>> is_Isomorphic('ab', 'aa')
False
''' | ```python
def is_Isomorphic(str1,str2):
''' Write a python function to check whether the two given strings are isomorphic to each other or not.
>>> is_Isomorphic('paper', 'title')
True
>>> is_Isomorphic('ab', 'ba')
True
>>> is_Isomorphic('ab', 'aa')
False
'''
dict_str1 = {}... | [
{
"role": "user",
"content": "def is_Isomorphic(str1,str2): \n\t''' Write a python function to check whether the two given strings are isomorphic to each other or not.\n\t>>> is_Isomorphic('paper', 'title')\n\tTrue\n\t>>> is_Isomorphic('ab', 'ba')\n\tTrue\n\t>>> is_Isomorphic('ab', 'aa')\n\tFalse\n... | |
886 | train | Write a function to add all the numbers in a list and divide it with the length of the list. | [
"assert sum_num((8, 2, 3, 0, 7))==4.0",
"assert sum_num((-10,-20,-30))==-20.0",
"assert sum_num((19,15,18))==17.333333333333332"
] | [] | def sum_num(numbers):
''' Write a function to add all the numbers in a list and divide it with the length of the list.
>>> sum_num((8, 2, 3, 0, 7))
4.0
>>> sum_num((-10, -20, -30))
-20.0
>>> sum_num((19, 15, 18))
17.333333333333332
''' | ```python
def sum_num(numbers):
''' Write a function to add all the numbers in a list and divide it with the length of the list.
>>> sum_num((8, 2, 3, 0, 7))
4.0
>>> sum_num((-10, -20, -30))
-20.0
>>> sum_num((19, 15, 18))
17.333333333333332
'''
total = 0
for x in numbers:
... | [
{
"role": "user",
"content": "def sum_num(numbers):\n\t''' Write a function to add all the numbers in a list and divide it with the length of the list.\n\t>>> sum_num((8, 2, 3, 0, 7))\n\t4.0\n\t>>> sum_num((-10, -20, -30))\n\t-20.0\n\t>>> sum_num((19, 15, 18))\n\t17.333333333333332\n\t'''"
},
{
"rol... | |
887 | train | Write a python function to check whether the given number is odd or not using bitwise operator. | [
"assert is_odd(5) == True",
"assert is_odd(6) == False",
"assert is_odd(7) == True"
] | [] | def is_odd(n) :
''' Write a python function to check whether the given number is odd or not using bitwise operator.
>>> is_odd(5)
True
>>> is_odd(6)
False
>>> is_odd(7)
True
''' | ```python
def is_odd(n) :
''' Write a python function to check whether the given number is odd or not using bitwise operator.
>>> is_odd(5)
True
>>> is_odd(6)
False
>>> is_odd(7)
True
'''
if (n^1 == n-1) :
return True;
else :
return False;
``` | [
{
"role": "user",
"content": "def is_odd(n) : \n\t''' Write a python function to check whether the given number is odd or not using bitwise operator.\n\t>>> is_odd(5)\n\tTrue\n\t>>> is_odd(6)\n\tFalse\n\t>>> is_odd(7)\n\tTrue\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef is_odd(n)... | |
888 | train | Write a function to substract the elements of the given nested tuples. | [
"assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))",
"assert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))",
"assert substract_elements... | [] | def substract_elements(test_tup1, test_tup2):
''' Write a function to substract the elements of the given nested tuples.
>>> substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3)))
((-5, -4), (1, -4), (1, 8), (-6, 7))
>>> substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((1... | ```python
def substract_elements(test_tup1, test_tup2):
''' Write a function to substract the elements of the given nested tuples.
>>> substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3)))
((-5, -4), (1, -4), (1, 8), (-6, 7))
>>> substract_elements(((13, 4), (14, 6), (13, 10), ... | [
{
"role": "user",
"content": "def substract_elements(test_tup1, test_tup2):\n\t''' Write a function to substract the elements of the given nested tuples.\n\t>>> substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3)))\n\t((-5, -4), (1, -4), (1, 8), (-6, 7))\n\t>>> substract_el... | |
889 | train | Write a function to reverse each list in a given list of lists. | [
"assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]",
"assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]",
"assert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]"
] | [] | def reverse_list_lists(lists):
''' Write a function to reverse each list in a given list of lists.
>>> reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
>>> reverse_list_lists([[1, 2], [2, 3], [3, 4]])
[[2, 1], [3, 2]... | ```python
def reverse_list_lists(lists):
''' Write a function to reverse each list in a given list of lists.
>>> reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
>>> reverse_list_lists([[1, 2], [2, 3], [3,... | [
{
"role": "user",
"content": "def reverse_list_lists(lists):\n\t''' Write a function to reverse each list in a given list of lists.\n\t>>> reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])\n\t[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]\n\t>>> reverse_lis... | |
890 | train | Write a python function to find the index of an extra element present in one sorted array. | [
"assert find_Extra([1,2,3,4],[1,2,3],3) == 3",
"assert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4",
"assert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5"
] | [] | def find_Extra(arr1,arr2,n) :
''' Write a python function to find the index of an extra element present in one sorted array.
>>> find_Extra([1, 2, 3, 4], [1, 2, 3], 3)
3
>>> find_Extra([2, 4, 6, 8, 10], [2, 4, 6, 8], 4)
4
>>> find_Extra([1, 3, 5, 7, 9, 11], [1, 3, 5, 7, 9], 5)
5
''' | ```python
def find_Extra(arr1,arr2,n) :
''' Write a python function to find the index of an extra element present in one sorted array.
>>> find_Extra([1, 2, 3, 4], [1, 2, 3], 3)
3
>>> find_Extra([2, 4, 6, 8, 10], [2, 4, 6, 8], 4)
4
>>> find_Extra([1, 3, 5, 7, 9, 11], [1, 3, 5, 7, 9], 5)
5
... | [
{
"role": "user",
"content": "def find_Extra(arr1,arr2,n) : \n\t''' Write a python function to find the index of an extra element present in one sorted array.\n\t>>> find_Extra([1, 2, 3, 4], [1, 2, 3], 3)\n\t3\n\t>>> find_Extra([2, 4, 6, 8, 10], [2, 4, 6, 8], 4)\n\t4\n\t>>> find_Extra([1, 3, 5, 7, 9, 11], [... | |
891 | train | Write a python function to check whether the given two numbers have same number of digits or not. | [
"assert same_Length(12,1) == False",
"assert same_Length(2,2) == True",
"assert same_Length(10,20) == True"
] | [] | def same_Length(A,B):
''' Write a python function to check whether the given two numbers have same number of digits or not.
>>> same_Length(12, 1)
False
>>> same_Length(2, 2)
True
>>> same_Length(10, 20)
True
''' | ```python
def same_Length(A,B):
''' Write a python function to check whether the given two numbers have same number of digits or not.
>>> same_Length(12, 1)
False
>>> same_Length(2, 2)
True
>>> same_Length(10, 20)
True
'''
while (A > 0 and B > 0):
A = A / 10;
B = B... | [
{
"role": "user",
"content": "def same_Length(A,B): \n\t''' Write a python function to check whether the given two numbers have same number of digits or not.\n\t>>> same_Length(12, 1)\n\tFalse\n\t>>> same_Length(2, 2)\n\tTrue\n\t>>> same_Length(10, 20)\n\tTrue\n\t'''"
},
{
"role": "assistant",
"... | |
892 | train | Write a function to remove multiple spaces in a string. | [
"assert remove_spaces('python program')==('python program')",
"assert remove_spaces('python programming language')==('python programming language')",
"assert remove_spaces('python program')==('python program')"
] | [] | import re
def remove_spaces(text):
''' Write a function to remove multiple spaces in a string.
>>> remove_spaces('python program')
'python program'
>>> remove_spaces('python programming language')
'python programming language'
>>> remove_spaces('python program')
'python program'
''' | ```python
import re
def remove_spaces(text):
''' Write a function to remove multiple spaces in a string.
>>> remove_spaces('python program')
'python program'
>>> remove_spaces('python programming language')
'python programming language'
>>> remove_spaces('python program')
'python progra... | [
{
"role": "user",
"content": "import re\ndef remove_spaces(text):\n\t''' Write a function to remove multiple spaces in a string.\n\t>>> remove_spaces('python program')\n\t'python program'\n\t>>> remove_spaces('python programming language')\n\t'python programming language'\n\t>>> remove_spaces('python ... | |
893 | train | Write a python function to get the last element of each sublist. | [
"assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]",
"assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']",
"assert Extract([[1, 2, 3], [4, 5]]) == [3, 5]"
] | [] | def Extract(lst):
''' Write a python function to get the last element of each sublist.
>>> Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
[3, 5, 9]
>>> Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']])
['z', 'm', 'b', 'v']
>>> Extract([[1, 2, 3], [4, 5]])
[3, 5]
''' | ```python
def Extract(lst):
''' Write a python function to get the last element of each sublist.
>>> Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
[3, 5, 9]
>>> Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']])
['z', 'm', 'b', 'v']
>>> Extract([[1, 2, 3], [4, 5]])
[3, 5]
'''
re... | [
{
"role": "user",
"content": "def Extract(lst): \n\t''' Write a python function to get the last element of each sublist.\n\t>>> Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]])\n\t[3, 5, 9]\n\t>>> Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']])\n\t['z', 'm', 'b', 'v']\n\t>>> Extract([[1, 2, 3], [4, 5]])... | |
894 | train | Write a function to convert the given string of float type into tuple. | [
"assert float_to_tuple(\"1.2, 1.3, 2.3, 2.4, 6.5\") == (1.2, 1.3, 2.3, 2.4, 6.5)",
"assert float_to_tuple(\"2.3, 2.4, 5.6, 5.4, 8.9\") == (2.3, 2.4, 5.6, 5.4, 8.9)",
"assert float_to_tuple(\"0.3, 0.5, 7.8, 9.4\") == (0.3, 0.5, 7.8, 9.4)"
] | [] | def float_to_tuple(test_str):
''' Write a function to convert the given string of float type into tuple.
>>> float_to_tuple('1.2, 1.3, 2.3, 2.4, 6.5')
(1.2, 1.3, 2.3, 2.4, 6.5)
>>> float_to_tuple('2.3, 2.4, 5.6, 5.4, 8.9')
(2.3, 2.4, 5.6, 5.4, 8.9)
>>> float_to_tuple('0.3, 0.5, 7.8, 9.4')
(0.3, 0.5, 7.8, 9.4)
'... | ```python
def float_to_tuple(test_str):
''' Write a function to convert the given string of float type into tuple.
>>> float_to_tuple('1.2, 1.3, 2.3, 2.4, 6.5')
(1.2, 1.3, 2.3, 2.4, 6.5)
>>> float_to_tuple('2.3, 2.4, 5.6, 5.4, 8.9')
(2.3, 2.4, 5.6, 5.4, 8.9)
>>> float_to_tuple('0.3, 0.5, 7.8, 9.4')
(0.3, ... | [
{
"role": "user",
"content": "def float_to_tuple(test_str):\n\t''' Write a function to convert the given string of float type into tuple.\n\t>>> float_to_tuple('1.2, 1.3, 2.3, 2.4, 6.5')\n\t(1.2, 1.3, 2.3, 2.4, 6.5)\n\t>>> float_to_tuple('2.3, 2.4, 5.6, 5.4, 8.9')\n\t(2.3, 2.4, 5.6, 5.4, 8.9)\n\t>>> float_t... | |
895 | train | Write a function to find the maximum sum of subsequences of given array with no adjacent elements. | [
"assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26",
"assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28",
"assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44"
] | [] | def max_sum_subseq(A):
''' Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
>>> max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6])
26
>>> max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7])
28
>>> max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21])
44
''' | ```python
def max_sum_subseq(A):
''' Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
>>> max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6])
26
>>> max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7])
28
>>> max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21])
4... | [
{
"role": "user",
"content": "def max_sum_subseq(A):\n\t''' Write a function to find the maximum sum of subsequences of given array with no adjacent elements.\n\t>>> max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6])\n\t26\n\t>>> max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7])\n\t28\n\t>>> max_sum_subseq([1, 3, 10, ... | |
896 | train | Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples. | [
"assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] ",
"assert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8), (7,9)] ",
"assert sort_list_last([(20,50), (10,20), (40,40)])==[(10,20),(40,40),(20,50)] "
] | [] | def last(n):
''' Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.
>>> sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])
[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
>>> sort_list_last([(9, 8), (4, 7), (3, 5), (7, 9), (1, 2)])
[(1, 2), (... | ```python
def last(n):
''' Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.
>>> sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])
[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
>>> sort_list_last([(9, 8), (4, 7), (3, 5), (7, 9), (1... | [
{
"role": "user",
"content": "def last(n):\n\t''' Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.\n\t>>> sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])\n\t[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]\n\t>>> sort_list_last([(9... | |
897 | train | Write a python function to check whether the word is present in a given sentence or not. | [
"assert is_Word_Present(\"machine learning\",\"machine\") == True",
"assert is_Word_Present(\"easy\",\"fun\") == False",
"assert is_Word_Present(\"python language\",\"code\") == False"
] | [] | def is_Word_Present(sentence,word):
''' Write a python function to check whether the word is present in a given sentence or not.
>>> is_Word_Present('machine learning', 'machine')
True
>>> is_Word_Present('easy', 'fun')
False
>>> is_Word_Present('python language', 'code')
False
''' | ```python
def is_Word_Present(sentence,word):
''' Write a python function to check whether the word is present in a given sentence or not.
>>> is_Word_Present('machine learning', 'machine')
True
>>> is_Word_Present('easy', 'fun')
False
>>> is_Word_Present('python language', 'code')
False
... | [
{
"role": "user",
"content": "def is_Word_Present(sentence,word): \n\t''' Write a python function to check whether the word is present in a given sentence or not.\n\t>>> is_Word_Present('machine learning', 'machine')\n\tTrue\n\t>>> is_Word_Present('easy', 'fun')\n\tFalse\n\t>>> is_Word_Present('python langu... | |
898 | train | Write a function to extract specified number of elements from a given list, which follow each other continuously. | [
"assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4]",
"assert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4]",
"assert extract_elements([0,0,0,0,0],5)==[0]"
] | [] | from itertools import groupby
def extract_elements(numbers, n):
''' Write a function to extract specified number of elements from a given list, which follow each other continuously.
>>> extract_elements([1, 1, 3, 4, 4, 5, 6, 7], 2)
[1, 4]
>>> extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7], 4)
[4]
>>> extract_ele... | ```python
from itertools import groupby
def extract_elements(numbers, n):
''' Write a function to extract specified number of elements from a given list, which follow each other continuously.
>>> extract_elements([1, 1, 3, 4, 4, 5, 6, 7], 2)
[1, 4]
>>> extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7], 4)... | [
{
"role": "user",
"content": "from itertools import groupby\ndef extract_elements(numbers, n):\n\t''' Write a function to extract specified number of elements from a given list, which follow each other continuously.\n\t>>> extract_elements([1, 1, 3, 4, 4, 5, 6, 7], 2)\n\t[1, 4]\n\t>>> extract_elements([0, 1... | |
899 | train | Write a python function to check whether an array can be sorted or not by picking only the corner elements. | [
"assert check([3,2,1,2,3,4],6) == True",
"assert check([2,1,4,5,1],5) == True",
"assert check([1,2,2,1,2,3],6) == True"
] | [] | def check(arr,n):
''' Write a python function to check whether an array can be sorted or not by picking only the corner elements.
>>> check([3, 2, 1, 2, 3, 4], 6)
True
>>> check([2, 1, 4, 5, 1], 5)
True
>>> check([1, 2, 2, 1, 2, 3], 6)
True
''' | ```python
def check(arr,n):
''' Write a python function to check whether an array can be sorted or not by picking only the corner elements.
>>> check([3, 2, 1, 2, 3, 4], 6)
True
>>> check([2, 1, 4, 5, 1], 5)
True
>>> check([1, 2, 2, 1, 2, 3], 6)
True
'''
g = 0
for i in range(1,... | [
{
"role": "user",
"content": "def check(arr,n): \n\t''' Write a python function to check whether an array can be sorted or not by picking only the corner elements.\n\t>>> check([3, 2, 1, 2, 3, 4], 6)\n\tTrue\n\t>>> check([2, 1, 4, 5, 1], 5)\n\tTrue\n\t>>> check([1, 2, 2, 1, 2, 3], 6)\n\tTrue\n\t'''"
},
... | |
900 | train | Write a function where a string will start with a specific number. | [
"assert match_num('5-2345861')==True",
"assert match_num('6-2345861')==False",
"assert match_num('78910')==False"
] | [] | import re
def match_num(string):
''' Write a function where a string will start with a specific number.
>>> match_num('5-2345861')
True
>>> match_num('6-2345861')
False
>>> match_num('78910')
False
''' | ```python
import re
def match_num(string):
''' Write a function where a string will start with a specific number.
>>> match_num('5-2345861')
True
>>> match_num('6-2345861')
False
>>> match_num('78910')
False
'''
text = re.compile(r"^5")
if text.match(string):
return True
... | [
{
"role": "user",
"content": "import re\ndef match_num(string):\n\t''' Write a function where a string will start with a specific number.\n\t>>> match_num('5-2345861')\n\tTrue\n\t>>> match_num('6-2345861')\n\tFalse\n\t>>> match_num('78910')\n\tFalse\n\t'''"
},
{
"role": "assistant",
"content": "... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.