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 |
|---|---|---|---|---|---|---|---|---|
701 | train | Write a function to find the equilibrium index of the given array. | [
"assert equilibrium_index([1, 2, 3, 4, 1, 2, 3]) == 3",
"assert equilibrium_index([-7, 1, 5, 2, -4, 3, 0]) == 3",
"assert equilibrium_index([1, 2, 3]) == -1"
] | [] | def equilibrium_index(arr):
''' Write a function to find the equilibrium index of the given array.
>>> equilibrium_index([1, 2, 3, 4, 1, 2, 3])
3
>>> equilibrium_index([-7, 1, 5, 2, -4, 3, 0])
3
>>> equilibrium_index([1, 2, 3])
-1
''' | ```python
def equilibrium_index(arr):
''' Write a function to find the equilibrium index of the given array.
>>> equilibrium_index([1, 2, 3, 4, 1, 2, 3])
3
>>> equilibrium_index([-7, 1, 5, 2, -4, 3, 0])
3
>>> equilibrium_index([1, 2, 3])
-1
'''
total_sum = sum(arr)
left_sum=0
for i, num in enumera... | [
{
"role": "user",
"content": "def equilibrium_index(arr):\n\t''' Write a function to find the equilibrium index of the given array.\n\t>>> equilibrium_index([1, 2, 3, 4, 1, 2, 3])\n\t3\n\t>>> equilibrium_index([-7, 1, 5, 2, -4, 3, 0])\n\t3\n\t>>> equilibrium_index([1, 2, 3])\n\t-1\n\t'''"
},
{
"role... | |
702 | train | Write a function to find the minimum number of elements that should be removed such that amax-amin<=k. | [
"assert removals([1, 3, 4, 9, 10,11, 12, 17, 20], 9, 4) == 5",
"assert removals([1, 5, 6, 2, 8], 5, 2) == 3",
"assert removals([1, 2, 3 ,4, 5, 6], 6, 3) == 2"
] | [] | def find_ind(key, i, n,
k, arr):
''' Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
>>> removals([1, 3, 4, 9, 10, 11, 12, 17, 20], 9, 4)
5
>>> removals([1, 5, 6, 2, 8], 5, 2)
3
>>> removals([1, 2, 3, 4, 5, 6], 6, 3)
2
''' | ```python
def find_ind(key, i, n,
k, arr):
''' Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
>>> removals([1, 3, 4, 9, 10, 11, 12, 17, 20], 9, 4)
5
>>> removals([1, 5, 6, 2, 8], 5, 2)
3
>>> removals([1, 2, 3, 4, 5, 6], 6, 3)
2
'''
ind = -1
start = i... | [
{
"role": "user",
"content": "def find_ind(key, i, n, \n\t\t\tk, arr):\n\t''' Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.\n\t>>> removals([1, 3, 4, 9, 10, 11, 12, 17, 20], 9, 4)\n\t5\n\t>>> removals([1, 5, 6, 2, 8], 5, 2)\n\t3\n\t>>> removals([1, 2,... | |
703 | train | Write a function to check whether the given key is present in the dictionary or not. | [
"assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},5)==True",
"assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},6)==True",
"assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},10)==False"
] | [] | def is_key_present(d,x):
''' Write a function to check whether the given key is present in the dictionary or not.
>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 5)
True
>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 6)
True
>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: ... | ```python
def is_key_present(d,x):
''' Write a function to check whether the given key is present in the dictionary or not.
>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 5)
True
>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 6)
True
>>> is_key_present({1: 10, 2: 20, 3: 30, 4... | [
{
"role": "user",
"content": "def is_key_present(d,x):\n\t''' Write a function to check whether the given key is present in the dictionary or not.\n\t>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 5)\n\tTrue\n\t>>> is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}, 6)\n\tTrue\n\t>>> ... | |
704 | train | Write a function to calculate the harmonic sum of n-1. | [
"assert harmonic_sum(10)==2.9289682539682538",
"assert harmonic_sum(4)==2.083333333333333",
"assert harmonic_sum(7)==2.5928571428571425 "
] | [] | def harmonic_sum(n):
''' Write a function to calculate the harmonic sum of n-1.
>>> harmonic_sum(10)
2.9289682539682538
>>> harmonic_sum(4)
2.083333333333333
>>> harmonic_sum(7)
2.5928571428571425
''' | ```python
def harmonic_sum(n):
''' Write a function to calculate the harmonic sum of n-1.
>>> harmonic_sum(10)
2.9289682539682538
>>> harmonic_sum(4)
2.083333333333333
>>> harmonic_sum(7)
2.5928571428571425
'''
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1))
``` | [
{
"role": "user",
"content": "def harmonic_sum(n):\n\t''' Write a function to calculate the harmonic sum of n-1.\n\t>>> harmonic_sum(10)\n\t2.9289682539682538\n\t>>> harmonic_sum(4)\n\t2.083333333333333\n\t>>> harmonic_sum(7)\n\t2.5928571428571425\n\t'''"
},
{
"role": "assistant",
"content": "``... | |
705 | train | Write a function to sort a list of lists by length and value. | [
"assert sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])==[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]",
"assert sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])==[[1], [7], [2, 3], [10, 11], [4, 5, 6]]",
"assert sort_sublists([[\"python\"],[\"java\",\"C\",\"C++\"],[\"DBMS\"],[\"SQL\"... | [] | def sort_sublists(list1):
''' Write a function to sort a list of lists by length and value.
>>> sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])
[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]
>>> sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])
[[1], [7], [2, 3], [10, 11], [4, 5, 6]]
>>> ... | ```python
def sort_sublists(list1):
''' Write a function to sort a list of lists by length and value.
>>> sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])
[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]
>>> sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])
[[1], [7],... | [
{
"role": "user",
"content": "def sort_sublists(list1):\n\t''' Write a function to sort a list of lists by length and value.\n\t>>> sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])\n\t[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]\n\t>>> sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11... | |
706 | train | Write a function to find whether an array is subset of another array. | [
"assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True",
"assert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True",
"assert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False"
] | [] | def is_subset(arr1, m, arr2, n):
''' Write a function to find whether an array is subset of another array.
>>> is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4)
True
>>> is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3)
True
>>> is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3)
False
''' | ```python
def is_subset(arr1, m, arr2, n):
''' Write a function to find whether an array is subset of another array.
>>> is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4)
True
>>> is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3)
True
>>> is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3)
False
'''
hashset = se... | [
{
"role": "user",
"content": "def is_subset(arr1, m, arr2, n): \n\t''' Write a function to find whether an array is subset of another array.\n\t>>> is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4)\n\tTrue\n\t>>> is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3)\n\tTrue\n\t>>> is_subset([10, 5, 2, 23, 19],... | |
707 | train | Write a python function to count the total set bits from 1 to n. | [
"assert count_Set_Bits(16) == 33",
"assert count_Set_Bits(2) == 2",
"assert count_Set_Bits(14) == 28"
] | [] | def count_Set_Bits(n) :
''' Write a python function to count the total set bits from 1 to n.
>>> count_Set_Bits(16)
33
>>> count_Set_Bits(2)
2
>>> count_Set_Bits(14)
28
''' | ```python
def count_Set_Bits(n) :
''' Write a python function to count the total set bits from 1 to n.
>>> count_Set_Bits(16)
33
>>> count_Set_Bits(2)
2
>>> count_Set_Bits(14)
28
'''
n += 1;
powerOf2 = 2;
cnt = n // 2;
while (powerOf2 <= n) :
totalPairs =... | [
{
"role": "user",
"content": "def count_Set_Bits(n) : \n\t''' Write a python function to count the total set bits from 1 to n.\n\t>>> count_Set_Bits(16)\n\t33\n\t>>> count_Set_Bits(2)\n\t2\n\t>>> count_Set_Bits(14)\n\t28\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef count_Set_Bit... | |
708 | train | Write a python function to convert a string to a list. | [
"assert Convert('python program') == ['python','program']",
"assert Convert('Data Analysis') ==['Data','Analysis']",
"assert Convert('Hadoop Training') == ['Hadoop','Training']"
] | [] | def Convert(string):
''' Write a python function to convert a string to a list.
>>> Convert('python program')
['python', 'program']
>>> Convert('Data Analysis')
['Data', 'Analysis']
>>> Convert('Hadoop Training')
['Hadoop', 'Training']
''' | ```python
def Convert(string):
''' Write a python function to convert a string to a list.
>>> Convert('python program')
['python', 'program']
>>> Convert('Data Analysis')
['Data', 'Analysis']
>>> Convert('Hadoop Training')
['Hadoop', 'Training']
'''
li = list(string.split(" "))
... | [
{
"role": "user",
"content": "def Convert(string): \n\t''' Write a python function to convert a string to a list.\n\t>>> Convert('python program')\n\t['python', 'program']\n\t>>> Convert('Data Analysis')\n\t['Data', 'Analysis']\n\t>>> Convert('Hadoop Training')\n\t['Hadoop', 'Training']\n\t'''"
},
{
... | |
709 | train | Write a function to count unique keys for each value present in the tuple. | [
"assert get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)] ) == '{4: 4, 2: 3, 1: 2}'",
"assert get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)] ) == '{5: 4, 3: 3, 2: 2}'",
"assert get_unique([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11)... | [] | from collections import defaultdict
def get_unique(test_list):
''' Write a function to count unique keys for each value present in the tuple.
>>> get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)])
'{4: 4, 2: 3, 1: 2}'
>>> get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2),... | ```python
from collections import defaultdict
def get_unique(test_list):
''' Write a function to count unique keys for each value present in the tuple.
>>> get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)])
'{4: 4, 2: 3, 1: 2}'
>>> get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (... | [
{
"role": "user",
"content": "from collections import defaultdict\ndef get_unique(test_list):\n\t''' Write a function to count unique keys for each value present in the tuple.\n\t>>> get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)])\n\t'{4: 4, 2: 3, 1: 2}'\n\t>>> get_uniq... | |
710 | train | Write a function to access the initial and last data of the given tuple record. | [
"assert front_and_rear((10, 4, 5, 6, 7)) == (10, 7)",
"assert front_and_rear((1, 2, 3, 4, 5)) == (1, 5)",
"assert front_and_rear((6, 7, 8, 9, 10)) == (6, 10)"
] | [] | def front_and_rear(test_tup):
''' Write a function to access the initial and last data of the given tuple record.
>>> front_and_rear((10, 4, 5, 6, 7))
(10, 7)
>>> front_and_rear((1, 2, 3, 4, 5))
(1, 5)
>>> front_and_rear((6, 7, 8, 9, 10))
(6, 10)
''' | ```python
def front_and_rear(test_tup):
''' Write a function to access the initial and last data of the given tuple record.
>>> front_and_rear((10, 4, 5, 6, 7))
(10, 7)
>>> front_and_rear((1, 2, 3, 4, 5))
(1, 5)
>>> front_and_rear((6, 7, 8, 9, 10))
(6, 10)
'''
res = (test_tup[0], test_tup[-1])
retur... | [
{
"role": "user",
"content": "def front_and_rear(test_tup):\n\t''' Write a function to access the initial and last data of the given tuple record.\n\t>>> front_and_rear((10, 4, 5, 6, 7))\n\t(10, 7)\n\t>>> front_and_rear((1, 2, 3, 4, 5))\n\t(1, 5)\n\t>>> front_and_rear((6, 7, 8, 9, 10))\n\t(6, 10)\n\t'''"
... | |
711 | train | Write a python function to check whether the product of digits of a number at even and odd places is equal or not. | [
"assert product_Equal(2841) == True",
"assert product_Equal(1234) == False",
"assert product_Equal(1212) == False"
] | [] | def product_Equal(n):
''' Write a python function to check whether the product of digits of a number at even and odd places is equal or not.
>>> product_Equal(2841)
True
>>> product_Equal(1234)
False
>>> product_Equal(1212)
False
''' | ```python
def product_Equal(n):
''' Write a python function to check whether the product of digits of a number at even and odd places is equal or not.
>>> product_Equal(2841)
True
>>> product_Equal(1234)
False
>>> product_Equal(1212)
False
'''
if n < 10:
return False
pr... | [
{
"role": "user",
"content": "def product_Equal(n): \n\t''' Write a python function to check whether the product of digits of a number at even and odd places is equal or not.\n\t>>> product_Equal(2841)\n\tTrue\n\t>>> product_Equal(1234)\n\tFalse\n\t>>> product_Equal(1212)\n\tFalse\n\t'''"
},
{
"role... | |
712 | train | Write a function to remove duplicates from a list of lists. | [
"assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]] ",
"assert remove_duplicate([\"a\", \"b\", \"a\", \"c\", \"c\"] )==[\"a\", \"b\", \"c\"]",
"assert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]"
] | [] | import itertools
def remove_duplicate(list1):
''' Write a function to remove duplicates from a list of lists.
>>> remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])
[[10, 20], [30, 56, 25], [33], [40]]
>>> remove_duplicate(['a', 'b', 'a', 'c', 'c'])
['a', 'b', 'c']
>>> remove_duplicate([1, 3, ... | ```python
import itertools
def remove_duplicate(list1):
''' Write a function to remove duplicates from a list of lists.
>>> remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])
[[10, 20], [30, 56, 25], [33], [40]]
>>> remove_duplicate(['a', 'b', 'a', 'c', 'c'])
['a', 'b', 'c']
>>> remove_duplica... | [
{
"role": "user",
"content": "import itertools\ndef remove_duplicate(list1):\n\t''' Write a function to remove duplicates from a list of lists.\n\t>>> remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])\n\t[[10, 20], [30, 56, 25], [33], [40]]\n\t>>> remove_duplicate(['a', 'b', 'a', 'c', '... | |
713 | train | Write a function to check if the given tuple contains all valid values or not. | [
"assert check_valid((True, True, True, True) ) == True",
"assert check_valid((True, False, True, True) ) == False",
"assert check_valid((True, True, True, True) ) == True"
] | [] | def check_valid(test_tup):
''' Write a function to check if the given tuple contains all valid values or not.
>>> check_valid((True, True, True, True))
True
>>> check_valid((True, False, True, True))
False
>>> check_valid((True, True, True, True))
True
''' | ```python
def check_valid(test_tup):
''' Write a function to check if the given tuple contains all valid values or not.
>>> check_valid((True, True, True, True))
True
>>> check_valid((True, False, True, True))
False
>>> check_valid((True, True, True, True))
True
'''
res = not any(map(lambda ele: not e... | [
{
"role": "user",
"content": "def check_valid(test_tup):\n\t''' Write a function to check if the given tuple contains all valid values or not.\n\t>>> check_valid((True, True, True, True))\n\tTrue\n\t>>> check_valid((True, False, True, True))\n\tFalse\n\t>>> check_valid((True, True, True, True))\n\tTrue\n\t'... | |
714 | train | Write a python function to count the number of distinct power of prime factor of given number. | [
"assert count_Fac(24) == 3",
"assert count_Fac(12) == 2",
"assert count_Fac(4) == 1"
] | [] | def count_Fac(n):
''' Write a python function to count the number of distinct power of prime factor of given number.
>>> count_Fac(24)
3
>>> count_Fac(12)
2
>>> count_Fac(4)
1
''' | ```python
def count_Fac(n):
''' Write a python function to count the number of distinct power of prime factor of given number.
>>> count_Fac(24)
3
>>> count_Fac(12)
2
>>> count_Fac(4)
1
'''
m = n
count = 0
i = 2
while((i * i) <= m):
total = 0
while (n ... | [
{
"role": "user",
"content": "def count_Fac(n): \n\t''' Write a python function to count the number of distinct power of prime factor of given number.\n\t>>> count_Fac(24)\n\t3\n\t>>> count_Fac(12)\n\t2\n\t>>> count_Fac(4)\n\t1\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef count_... | |
715 | train | Write a function to convert the given string of integers into a tuple. | [
"assert str_to_tuple(\"1, -5, 4, 6, 7\") == (1, -5, 4, 6, 7)",
"assert str_to_tuple(\"1, 2, 3, 4, 5\") == (1, 2, 3, 4, 5)",
"assert str_to_tuple(\"4, 6, 9, 11, 13, 14\") == (4, 6, 9, 11, 13, 14)"
] | [] | def str_to_tuple(test_str):
''' Write a function to convert the given string of integers into a tuple.
>>> str_to_tuple('1, -5, 4, 6, 7')
(1, -5, 4, 6, 7)
>>> str_to_tuple('1, 2, 3, 4, 5')
(1, 2, 3, 4, 5)
>>> str_to_tuple('4, 6, 9, 11, 13, 14')
(4, 6, 9, 11, 13, 14)
''' | ```python
def str_to_tuple(test_str):
''' Write a function to convert the given string of integers into a tuple.
>>> str_to_tuple('1, -5, 4, 6, 7')
(1, -5, 4, 6, 7)
>>> str_to_tuple('1, 2, 3, 4, 5')
(1, 2, 3, 4, 5)
>>> str_to_tuple('4, 6, 9, 11, 13, 14')
(4, 6, 9, 11, 13, 14)
'''
res = tuple(map(int, ... | [
{
"role": "user",
"content": "def str_to_tuple(test_str):\n\t''' Write a function to convert the given string of integers into a tuple.\n\t>>> str_to_tuple('1, -5, 4, 6, 7')\n\t(1, -5, 4, 6, 7)\n\t>>> str_to_tuple('1, 2, 3, 4, 5')\n\t(1, 2, 3, 4, 5)\n\t>>> str_to_tuple('4, 6, 9, 11, 13, 14')\n\t(4, 6, 9, 11... | |
716 | train | Write a function to find the perimeter of a rombus. | [
"assert rombus_perimeter(10)==40",
"assert rombus_perimeter(5)==20",
"assert rombus_perimeter(4)==16"
] | [] | def rombus_perimeter(a):
''' Write a function to find the perimeter of a rombus.
>>> rombus_perimeter(10)
40
>>> rombus_perimeter(5)
20
>>> rombus_perimeter(4)
16
''' | ```python
def rombus_perimeter(a):
''' Write a function to find the perimeter of a rombus.
>>> rombus_perimeter(10)
40
>>> rombus_perimeter(5)
20
>>> rombus_perimeter(4)
16
'''
perimeter=4*a
return perimeter
``` | [
{
"role": "user",
"content": "def rombus_perimeter(a):\n\t''' Write a function to find the perimeter of a rombus.\n\t>>> rombus_perimeter(10)\n\t40\n\t>>> rombus_perimeter(5)\n\t20\n\t>>> rombus_perimeter(4)\n\t16\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef rombus_perimeter(a):\... | |
717 | train | Write a function to calculate the standard deviation. | [
"assert sd_calc([4, 2, 5, 8, 6])== 2.23606797749979",
"assert sd_calc([1,2,3,4,5,6,7])==2.160246899469287",
"assert sd_calc([5,9,10,15,6,4])==4.070217029430577"
] | [] | import math
import sys
def sd_calc(data):
''' Write a function to calculate the standard deviation.
>>> sd_calc([4, 2, 5, 8, 6])
2.23606797749979
>>> sd_calc([1, 2, 3, 4, 5, 6, 7])
2.160246899469287
>>> sd_calc([5, 9, 10, 15, 6, 4])
4.070217029430577
''' | ```python
import math
import sys
def sd_calc(data):
''' Write a function to calculate the standard deviation.
>>> sd_calc([4, 2, 5, 8, 6])
2.23606797749979
>>> sd_calc([1, 2, 3, 4, 5, 6, 7])
2.160246899469287
>>> sd_calc([5, 9, 10, 15, 6, 4])
4.070217029430577
'''
n = len(data)
i... | [
{
"role": "user",
"content": "import math\nimport sys\ndef sd_calc(data):\n\t''' Write a function to calculate the standard deviation.\n\t>>> sd_calc([4, 2, 5, 8, 6])\n\t2.23606797749979\n\t>>> sd_calc([1, 2, 3, 4, 5, 6, 7])\n\t2.160246899469287\n\t>>> sd_calc([5, 9, 10, 15, 6, 4])\n\t4.070217029430577\n\t'... | |
718 | train | Write a function to create a list taking alternate elements from another given list. | [
"assert alternate_elements([\"red\", \"black\", \"white\", \"green\", \"orange\"])==['red', 'white', 'orange']",
"assert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]",
"assert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]"
] | [] | def alternate_elements(list1):
''' Write a function to create a list taking alternate elements from another given list.
>>> alternate_elements(['red', 'black', 'white', 'green', 'orange'])
['red', 'white', 'orange']
>>> alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])
[2, 3, 0, 8, 4]
>>> alternate_elements([1, ... | ```python
def alternate_elements(list1):
''' Write a function to create a list taking alternate elements from another given list.
>>> alternate_elements(['red', 'black', 'white', 'green', 'orange'])
['red', 'white', 'orange']
>>> alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])
[2, 3, 0, 8, 4]
... | [
{
"role": "user",
"content": "def alternate_elements(list1):\n\t''' Write a function to create a list taking alternate elements from another given list.\n\t>>> alternate_elements(['red', 'black', 'white', 'green', 'orange'])\n\t['red', 'white', 'orange']\n\t>>> alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4,... | |
719 | train | Write a function that matches a string that has an a followed by zero or more b's. | [
"assert text_match(\"ac\")==('Found a match!')",
"assert text_match(\"dc\")==('Not matched!')",
"assert text_match(\"abba\")==('Found a match!')"
] | [] | import re
def text_match(text):
''' Write a function that matches a string that has an a followed by zero or more b's.
>>> text_match('ac')
'Found a match!'
>>> text_match('dc')
'Not matched!'
>>> text_match('abba')
'Found a match!'
''' | ```python
import re
def text_match(text):
''' Write a function that matches a string that has an a followed by zero or more b's.
>>> text_match('ac')
'Found a match!'
>>> text_match('dc')
'Not matched!'
>>> text_match('abba')
'Found a match!'
'''
p... | [
{
"role": "user",
"content": "import re\ndef text_match(text):\n\t''' Write a function that matches a string that has an a followed by zero or more b's.\n\t>>> text_match('ac')\n\t'Found a match!'\n\t>>> text_match('dc')\n\t'Not matched!'\n\t>>> text_match('abba')\n\t'Found a match!'\n\t'''"
},
{
"r... | |
720 | train | Write a function to add a dictionary to the tuple. | [
"assert add_dict_to_tuple((4, 5, 6), {\"MSAM\" : 1, \"is\" : 2, \"best\" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})",
"assert add_dict_to_tuple((1, 2, 3), {\"UTS\" : 2, \"is\" : 3, \"Worst\" : 4} ) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4})",
"assert add_dict_to_tuple((8, 9, 10), {\"POS\" : 3, \"is... | [] | def add_dict_to_tuple(test_tup, test_dict):
''' Write a function to add a dictionary to the tuple.
>>> add_dict_to_tuple((4, 5, 6), {'MSAM': 1, 'is': 2, 'best': 3})
(4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})
>>> add_dict_to_tuple((1, 2, 3), {'UTS': 2, 'is': 3, 'Worst': 4})
(1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4}... | ```python
def add_dict_to_tuple(test_tup, test_dict):
''' Write a function to add a dictionary to the tuple.
>>> add_dict_to_tuple((4, 5, 6), {'MSAM': 1, 'is': 2, 'best': 3})
(4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})
>>> add_dict_to_tuple((1, 2, 3), {'UTS': 2, 'is': 3, 'Worst': 4})
(1, 2, 3, {'UTS': 2, 'is':... | [
{
"role": "user",
"content": "def add_dict_to_tuple(test_tup, test_dict):\n\t''' Write a function to add a dictionary to the tuple.\n\t>>> add_dict_to_tuple((4, 5, 6), {'MSAM': 1, 'is': 2, 'best': 3})\n\t(4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})\n\t>>> add_dict_to_tuple((1, 2, 3), {'UTS': 2, 'is': 3, 'Wors... | |
721 | train | Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n. | [
"assert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2",
"assert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2",
"assert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2 "
] | [] | M = 100
def maxAverageOfPath(cost, N):
''' Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.
>>> maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3)
5.2
>>> maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3)
6.2
>>> maxAverageOfPath(... | ```python
M = 100
def maxAverageOfPath(cost, N):
''' Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.
>>> maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3)
5.2
>>> maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3)
6.2
>>> maxAver... | [
{
"role": "user",
"content": "M = 100\ndef maxAverageOfPath(cost, N): \n\t''' Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.\n\t>>> maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3)\n\t5.2\n\t>>> maxAverageOfPath([[2, 3, 4], [7,... | |
722 | train | Write a function to filter the height and width of students which are stored in a dictionary. | [
"assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},6.0,70)=={'Cierra Vega': (6.2, 70)}",
"assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.9,67)=={'Cierra ... | [] | def filter_data(students,h,w):
''' Write a function to filter the height and width of students which are stored in a dictionary.
>>> filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 6.0, 70)
{'Cierra Vega': (6.2, 70)}
>>> filter_data({'Cierra ... | ```python
def filter_data(students,h,w):
''' Write a function to filter the height and width of students which are stored in a dictionary.
>>> filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 6.0, 70)
{'Cierra Vega': (6.2, 70)}
>>>... | [
{
"role": "user",
"content": "def filter_data(students,h,w):\n\t''' Write a function to filter the height and width of students which are stored in a dictionary.\n\t>>> filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}, 6.0, 70)\n\t{'Cie... | |
723 | train | Write a function to count the same pair in two given lists using map function. | [
"assert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4",
"assert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11",
"assert count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==1"
] | [] | from operator import eq
def count_same_pair(nums1, nums2):
''' Write a function to count the same pair in two given lists using map function.
>>> count_same_pair([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 3, 1, 2, 6, 7, 9])
4
>>> count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8], [2, 1, 2, -1, -5, 6, 4, -3, -2, 3, ... | ```python
from operator import eq
def count_same_pair(nums1, nums2):
''' Write a function to count the same pair in two given lists using map function.
>>> count_same_pair([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 3, 1, 2, 6, 7, 9])
4
>>> count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8], [2, 1, 2, -1,... | [
{
"role": "user",
"content": "from operator import eq\ndef count_same_pair(nums1, nums2):\n\t''' Write a function to count the same pair in two given lists using map function.\n\t>>> count_same_pair([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 3, 1, 2, 6, 7, 9])\n\t4\n\t>>> count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -... | |
724 | train | Write a function to calculate the sum of all digits of the base to the specified power. | [
"assert power_base_sum(2,100)==115",
"assert power_base_sum(8,10)==37",
"assert power_base_sum(8,15)==62"
] | [] | def power_base_sum(base, power):
''' Write a function to calculate the sum of all digits of the base to the specified power.
>>> power_base_sum(2, 100)
115
>>> power_base_sum(8, 10)
37
>>> power_base_sum(8, 15)
62
''' | ```python
def power_base_sum(base, power):
''' Write a function to calculate the sum of all digits of the base to the specified power.
>>> power_base_sum(2, 100)
115
>>> power_base_sum(8, 10)
37
>>> power_base_sum(8, 15)
62
'''
return sum([int(i) for i in str(pow(base, power))])
``` | [
{
"role": "user",
"content": "def power_base_sum(base, power):\n\t''' Write a function to calculate the sum of all digits of the base to the specified power.\n\t>>> power_base_sum(2, 100)\n\t115\n\t>>> power_base_sum(8, 10)\n\t37\n\t>>> power_base_sum(8, 15)\n\t62\n\t'''"
},
{
"role": "assistant",
... | |
725 | train | Write a function to extract values between quotation marks of the given string by using regex. | [
"assert extract_quotation('Cortex \"A53\" Based \"multi\" tasking \"Processor\"') == ['A53', 'multi', 'Processor']",
"assert extract_quotation('Cast your \"favorite\" entertainment \"apps\"') == ['favorite', 'apps']",
"assert extract_quotation('Watch content \"4k Ultra HD\" resolution with \"HDR 10\" Support') ... | [] | import re
def extract_quotation(text1):
''' Write a function to extract values between quotation marks of the given string by using regex.
>>> extract_quotation('Cortex "A53" Based "multi" tasking "Processor"')
['A53', 'multi', 'Processor']
>>> extract_quotation('Cast your "favorite" entertainment "apps"')
['favor... | ```python
import re
def extract_quotation(text1):
''' Write a function to extract values between quotation marks of the given string by using regex.
>>> extract_quotation('Cortex "A53" Based "multi" tasking "Processor"')
['A53', 'multi', 'Processor']
>>> extract_quotation('Cast your "favorite" entertainment "ap... | [
{
"role": "user",
"content": "import re\ndef extract_quotation(text1):\n\t''' Write a function to extract values between quotation marks of the given string by using regex.\n\t>>> extract_quotation('Cortex \"A53\" Based \"multi\" tasking \"Processor\"')\n\t['A53', 'multi', 'Processor']\n\t>>> extract_quotat... | |
726 | train | Write a function to multiply the adjacent elements of the given tuple. | [
"assert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)",
"assert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42)",
"assert multiply_elements((12, 13, 14, 9, 15)) == (156, 182, 126, 135)"
] | [] | def multiply_elements(test_tup):
''' Write a function to multiply the adjacent elements of the given tuple.
>>> multiply_elements((1, 5, 7, 8, 10))
(5, 35, 56, 80)
>>> multiply_elements((2, 4, 5, 6, 7))
(8, 20, 30, 42)
>>> multiply_elements((12, 13, 14, 9, 15))
(156, 182, 126, 135)
''' | ```python
def multiply_elements(test_tup):
''' Write a function to multiply the adjacent elements of the given tuple.
>>> multiply_elements((1, 5, 7, 8, 10))
(5, 35, 56, 80)
>>> multiply_elements((2, 4, 5, 6, 7))
(8, 20, 30, 42)
>>> multiply_elements((12, 13, 14, 9, 15))
(156, 182, 126, 135)
'''
res =... | [
{
"role": "user",
"content": "def multiply_elements(test_tup):\n\t''' Write a function to multiply the adjacent elements of the given tuple.\n\t>>> multiply_elements((1, 5, 7, 8, 10))\n\t(5, 35, 56, 80)\n\t>>> multiply_elements((2, 4, 5, 6, 7))\n\t(8, 20, 30, 42)\n\t>>> multiply_elements((12, 13, 14, 9, 15)... | |
727 | train | Write a function to remove all characters except letters and numbers using regex | [
"assert remove_char(\"123abcjw:, .@! eiw\") == '123abcjweiw'",
"assert remove_char(\"Hello1234:, ! Howare33u\") == 'Hello1234Howare33u'",
"assert remove_char(\"Cool543Triks@:, Make@987Trips\") == 'Cool543TriksMake987Trips' "
] | [] | import re
def remove_char(S):
''' Write a function to remove all characters except letters and numbers using regex
>>> remove_char('123abcjw:, .@! eiw')
'123abcjweiw'
>>> remove_char('Hello1234:, ! Howare33u')
'Hello1234Howare33u'
>>> remove_char('Cool543Triks@:, Make@987Trips')
'Cool543TriksMake987Trips'
''' | ```python
import re
def remove_char(S):
''' Write a function to remove all characters except letters and numbers using regex
>>> remove_char('123abcjw:, .@! eiw')
'123abcjweiw'
>>> remove_char('Hello1234:, ! Howare33u')
'Hello1234Howare33u'
>>> remove_char('Cool543Triks@:, Make@987Trips')
'Cool543TriksMak... | [
{
"role": "user",
"content": "import re\ndef remove_char(S):\n\t''' Write a function to remove all characters except letters and numbers using regex\n\t>>> remove_char('123abcjw:, .@! eiw')\n\t'123abcjweiw'\n\t>>> remove_char('Hello1234:, ! Howare33u')\n\t'Hello1234Howare33u'\n\t>>> remove_char('Cool543Trik... | |
728 | train | Write a function to sum elements in two lists. | [
"assert sum_list([10,20,30],[15,25,35])==[25,45,65]",
"assert sum_list([1,2,3],[5,6,7])==[6,8,10]",
"assert sum_list([15,20,30],[15,45,75])==[30,65,105]"
] | [] | def sum_list(lst1,lst2):
''' Write a function to sum elements in two lists.
>>> sum_list([10, 20, 30], [15, 25, 35])
[25, 45, 65]
>>> sum_list([1, 2, 3], [5, 6, 7])
[6, 8, 10]
>>> sum_list([15, 20, 30], [15, 45, 75])
[30, 65, 105]
''' | ```python
def sum_list(lst1,lst2):
''' Write a function to sum elements in two lists.
>>> sum_list([10, 20, 30], [15, 25, 35])
[25, 45, 65]
>>> sum_list([1, 2, 3], [5, 6, 7])
[6, 8, 10]
>>> sum_list([15, 20, 30], [15, 45, 75])
[30, 65, 105]
'''
res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] ... | [
{
"role": "user",
"content": "def sum_list(lst1,lst2):\n\t''' Write a function to sum elements in two lists.\n\t>>> sum_list([10, 20, 30], [15, 25, 35])\n\t[25, 45, 65]\n\t>>> sum_list([1, 2, 3], [5, 6, 7])\n\t[6, 8, 10]\n\t>>> sum_list([15, 20, 30], [15, 45, 75])\n\t[30, 65, 105]\n\t'''"
},
{
"role... | |
729 | train | Write a function to add two lists using map and lambda function. | [
"assert add_list([1, 2, 3],[4,5,6])==[5, 7, 9]",
"assert add_list([1,2],[3,4])==[4,6]",
"assert add_list([10,20],[50,70])==[60,90]"
] | [] | def add_list(nums1,nums2):
''' Write a function to add two lists using map and lambda function.
>>> add_list([1, 2, 3], [4, 5, 6])
[5, 7, 9]
>>> add_list([1, 2], [3, 4])
[4, 6]
>>> add_list([10, 20], [50, 70])
[60, 90]
''' | ```python
def add_list(nums1,nums2):
''' Write a function to add two lists using map and lambda function.
>>> add_list([1, 2, 3], [4, 5, 6])
[5, 7, 9]
>>> add_list([1, 2], [3, 4])
[4, 6]
>>> add_list([10, 20], [50, 70])
[60, 90]
'''
result = map(lambda x, y: x + y, nums1, nums2)
return list(result)
... | [
{
"role": "user",
"content": "def add_list(nums1,nums2):\n\t''' Write a function to add two lists using map and lambda function.\n\t>>> add_list([1, 2, 3], [4, 5, 6])\n\t[5, 7, 9]\n\t>>> add_list([1, 2], [3, 4])\n\t[4, 6]\n\t>>> add_list([10, 20], [50, 70])\n\t[60, 90]\n\t'''"
},
{
"role": "assistan... | |
730 | train | Write a function to remove consecutive duplicates of a given list. | [
"assert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]",
"assert consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[10, 15, 19, 18, 17, 26, 17, 18, 10]",
"assert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==['a', 'b... | [] | from itertools import groupby
def consecutive_duplicates(nums):
''' Write a function to remove consecutive duplicates of a given list.
>>> consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]
>>> consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18... | ```python
from itertools import groupby
def consecutive_duplicates(nums):
''' Write a function to remove consecutive duplicates of a given list.
>>> consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]
>>> consecutive_duplicates([10, 10, 15, 19, 18, ... | [
{
"role": "user",
"content": "from itertools import groupby\ndef consecutive_duplicates(nums):\n\t''' Write a function to remove consecutive duplicates of a given list.\n\t>>> consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])\n\t[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]\n\t>>> consecutive_dup... | |
731 | train | Write a function to find the lateral surface area of a cone. | [
"assert lateralsurface_cone(5,12)==204.20352248333654",
"assert lateralsurface_cone(10,15)==566.3586699569488",
"assert lateralsurface_cone(19,17)==1521.8090132193388"
] | [] | import math
def lateralsurface_cone(r,h):
''' Write a function to find the lateral surface area of a cone.
>>> lateralsurface_cone(5, 12)
204.20352248333654
>>> lateralsurface_cone(10, 15)
566.3586699569488
>>> lateralsurface_cone(19, 17)
1521.8090132193388
''' | ```python
import math
def lateralsurface_cone(r,h):
''' Write a function to find the lateral surface area of a cone.
>>> lateralsurface_cone(5, 12)
204.20352248333654
>>> lateralsurface_cone(10, 15)
566.3586699569488
>>> lateralsurface_cone(19, 17)
1521.8090132193388
'''
l = math.sqrt(r * r + h * h)
... | [
{
"role": "user",
"content": "import math\ndef lateralsurface_cone(r,h):\n\t''' Write a function to find the lateral surface area of a cone.\n\t>>> lateralsurface_cone(5, 12)\n\t204.20352248333654\n\t>>> lateralsurface_cone(10, 15)\n\t566.3586699569488\n\t>>> lateralsurface_cone(19, 17)\n\t1521.809013219338... | |
732 | train | Write a function to replace all occurrences of spaces, commas, or dots with a colon. | [
"assert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:')",
"assert replace_specialchar('a b c,d e f')==('a:b:c:d:e:f')",
"assert replace_specialchar('ram reshma,ram rahim')==('ram:reshma:ram:rahim')"
] | [] | import re
def replace_specialchar(text):
''' Write a function to replace all occurrences of spaces, commas, or dots with a colon.
>>> replace_specialchar('Python language, Programming language.')
'Python:language::Programming:language:'
>>> replace_specialchar('a b c,d e f')
'a:b:c:d:e:f'
>>> replace_specialchar(... | ```python
import re
def replace_specialchar(text):
''' Write a function to replace all occurrences of spaces, commas, or dots with a colon.
>>> replace_specialchar('Python language, Programming language.')
'Python:language::Programming:language:'
>>> replace_specialchar('a b c,d e f')
'a:b:c:d:e:f'
>>> replace_sp... | [
{
"role": "user",
"content": "import re\ndef replace_specialchar(text):\n\t''' Write a function to replace all occurrences of spaces, commas, or dots with a colon.\n\t>>> replace_specialchar('Python language, Programming language.')\n\t'Python:language::Programming:language:'\n\t>>> replace_specialchar('a b... | |
733 | train | Write a function to find the index of the first occurrence of a given number in a sorted array. | [
"assert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1",
"assert find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2",
"assert find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4"
] | [] | def find_first_occurrence(A, x):
''' Write a function to find the index of the first occurrence of a given number in a sorted array.
>>> find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5)
1
>>> find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5)
2
>>> find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9... | ```python
def find_first_occurrence(A, x):
''' Write a function to find the index of the first occurrence of a given number in a sorted array.
>>> find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5)
1
>>> find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5)
2
>>> find_first_occurrence([... | [
{
"role": "user",
"content": "def find_first_occurrence(A, x):\n\t''' Write a function to find the index of the first occurrence of a given number in a sorted array.\n\t>>> find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5)\n\t1\n\t>>> find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5)\n\t2\n\t>... | |
734 | train | Write a python function to find sum of products of all possible subarrays. | [
"assert sum_Of_Subarray_Prod([1,2,3],3) == 20",
"assert sum_Of_Subarray_Prod([1,2],2) == 5",
"assert sum_Of_Subarray_Prod([1,2,3,4],4) == 84"
] | [] | def sum_Of_Subarray_Prod(arr,n):
''' Write a python function to find sum of products of all possible subarrays.
>>> sum_Of_Subarray_Prod([1, 2, 3], 3)
20
>>> sum_Of_Subarray_Prod([1, 2], 2)
5
>>> sum_Of_Subarray_Prod([1, 2, 3, 4], 4)
84
''' | ```python
def sum_Of_Subarray_Prod(arr,n):
''' Write a python function to find sum of products of all possible subarrays.
>>> sum_Of_Subarray_Prod([1, 2, 3], 3)
20
>>> sum_Of_Subarray_Prod([1, 2], 2)
5
>>> sum_Of_Subarray_Prod([1, 2, 3, 4], 4)
84
'''
ans = 0
res = 0
i = n - 1... | [
{
"role": "user",
"content": "def sum_Of_Subarray_Prod(arr,n):\n\t''' Write a python function to find sum of products of all possible subarrays.\n\t>>> sum_Of_Subarray_Prod([1, 2, 3], 3)\n\t20\n\t>>> sum_Of_Subarray_Prod([1, 2], 2)\n\t5\n\t>>> sum_Of_Subarray_Prod([1, 2, 3, 4], 4)\n\t84\n\t'''"
},
{
... | |
735 | train | Write a python function to toggle bits of the number except the first and the last bit. | [
"assert toggle_middle_bits(9) == 15",
"assert toggle_middle_bits(10) == 12",
"assert toggle_middle_bits(11) == 13"
] | [] | def set_middle_bits(n):
''' Write a python function to toggle bits of the number except the first and the last bit.
>>> toggle_middle_bits(9)
15
>>> toggle_middle_bits(10)
12
>>> toggle_middle_bits(11)
13
''' | ```python
def set_middle_bits(n):
''' Write a python function to toggle bits of the number except the first and the last bit.
>>> toggle_middle_bits(9)
15
>>> toggle_middle_bits(10)
12
>>> toggle_middle_bits(11)
13
'''
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >>... | [
{
"role": "user",
"content": "def set_middle_bits(n): \n\t''' Write a python function to toggle bits of the number except the first and the last bit.\n\t>>> toggle_middle_bits(9)\n\t15\n\t>>> toggle_middle_bits(10)\n\t12\n\t>>> toggle_middle_bits(11)\n\t13\n\t'''"
},
{
"role": "assistant",
"con... | |
736 | train | Write a function to locate the left insertion point for a specified value in sorted order. | [
"assert left_insertion([1,2,4,5],6)==4",
"assert left_insertion([1,2,4,5],3)==2",
"assert left_insertion([1,2,4,5],7)==4"
] | [] | import bisect
def left_insertion(a, x):
''' Write a function to locate the left insertion point for a specified value in sorted order.
>>> left_insertion([1, 2, 4, 5], 6)
4
>>> left_insertion([1, 2, 4, 5], 3)
2
>>> left_insertion([1, 2, 4, 5], 7)
4
''' | ```python
import bisect
def left_insertion(a, x):
''' Write a function to locate the left insertion point for a specified value in sorted order.
>>> left_insertion([1, 2, 4, 5], 6)
4
>>> left_insertion([1, 2, 4, 5], 3)
2
>>> left_insertion([1, 2, 4, 5], 7)
4
'''
i = bisect.bisect_lef... | [
{
"role": "user",
"content": "import bisect\ndef left_insertion(a, x):\n\t''' Write a function to locate the left insertion point for a specified value in sorted order.\n\t>>> left_insertion([1, 2, 4, 5], 6)\n\t4\n\t>>> left_insertion([1, 2, 4, 5], 3)\n\t2\n\t>>> left_insertion([1, 2, 4, 5], 7)\n\t4\n\t'''"... | |
737 | train | Write a function to check whether the given string is starting with a vowel or not using regex. | [
"assert check_str(\"annie\") == 'Valid'",
"assert check_str(\"dawood\") == 'Invalid'",
"assert check_str(\"Else\") == 'Valid'"
] | [] | import re
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
def check_str(string):
''' Write a function to check whether the given string is starting with a vowel or not using regex.
>>> check_str('annie')
'Valid'
>>> check_str('dawood')
'Invalid'
>>> check_str('Else')
'Valid'
''' | ```python
import re
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
def check_str(string):
''' Write a function to check whether the given string is starting with a vowel or not using regex.
>>> check_str('annie')
'Valid'
>>> check_str('dawood')
'Invalid'
>>> check_str('Else')
'Valid'
'''
if(re.search(regex, string)): ... | [
{
"role": "user",
"content": "import re \nregex = '^[aeiouAEIOU][A-Za-z0-9_]*'\ndef check_str(string): \n\t''' Write a function to check whether the given string is starting with a vowel or not using regex.\n\t>>> check_str('annie')\n\t'Valid'\n\t>>> check_str('dawood')\n\t'Invalid'\n\t>>> check_str('Else')... | |
738 | train | Write a function to calculate the geometric sum of n-1. | [
"assert geometric_sum(7) == 1.9921875",
"assert geometric_sum(4) == 1.9375",
"assert geometric_sum(8) == 1.99609375"
] | [] | def geometric_sum(n):
''' Write a function to calculate the geometric sum of n-1.
>>> geometric_sum(7)
1.9921875
>>> geometric_sum(4)
1.9375
>>> geometric_sum(8)
1.99609375
''' | ```python
def geometric_sum(n):
''' Write a function to calculate the geometric sum of n-1.
>>> geometric_sum(7)
1.9921875
>>> geometric_sum(4)
1.9375
>>> geometric_sum(8)
1.99609375
'''
if n < 0:
return 0
else:
return 1 / (pow(2, n)) + geometric_sum(n - 1)
``` | [
{
"role": "user",
"content": "def geometric_sum(n):\n\t''' Write a function to calculate the geometric sum of n-1.\n\t>>> geometric_sum(7)\n\t1.9921875\n\t>>> geometric_sum(4)\n\t1.9375\n\t>>> geometric_sum(8)\n\t1.99609375\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef geometric_s... | |
739 | train | Write a python function to find the index of smallest triangular number with n digits. | [
"assert find_Index(2) == 4",
"assert find_Index(3) == 14",
"assert find_Index(4) == 45"
] | [] | import math
def find_Index(n):
''' Write a python function to find the index of smallest triangular number with n digits.
>>> find_Index(2)
4
>>> find_Index(3)
14
>>> find_Index(4)
45
''' | ```python
import math
def find_Index(n):
''' Write a python function to find the index of smallest triangular number with n digits.
>>> find_Index(2)
4
>>> find_Index(3)
14
>>> find_Index(4)
45
'''
x = math.sqrt(2 * math.pow(10,(n - 1)));
return round(x);
``` | [
{
"role": "user",
"content": "import math\ndef find_Index(n): \n\t''' Write a python function to find the index of smallest triangular number with n digits.\n\t>>> find_Index(2)\n\t4\n\t>>> find_Index(3)\n\t14\n\t>>> find_Index(4)\n\t45\n\t'''"
},
{
"role": "assistant",
"content": "```python\nim... | |
740 | train | Write a function to convert the given tuple to a key-value dictionary using adjacent elements. | [
"assert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5}",
"assert tuple_to_dict((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6}",
"assert tuple_to_dict((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}"
] | [] | def tuple_to_dict(test_tup):
''' Write a function to convert the given tuple to a key-value dictionary using adjacent elements.
>>> tuple_to_dict((1, 5, 7, 10, 13, 5))
{1: 5, 7: 10, 13: 5}
>>> tuple_to_dict((1, 2, 3, 4, 5, 6))
{1: 2, 3: 4, 5: 6}
>>> tuple_to_dict((7, 8, 9, 10, 11, 12))
{7: 8, 9: 10, 11: 12}
''' | ```python
def tuple_to_dict(test_tup):
''' Write a function to convert the given tuple to a key-value dictionary using adjacent elements.
>>> tuple_to_dict((1, 5, 7, 10, 13, 5))
{1: 5, 7: 10, 13: 5}
>>> tuple_to_dict((1, 2, 3, 4, 5, 6))
{1: 2, 3: 4, 5: 6}
>>> tuple_to_dict((7, 8, 9, 10, 11, 12))
{7: 8, 9:... | [
{
"role": "user",
"content": "def tuple_to_dict(test_tup):\n\t''' Write a function to convert the given tuple to a key-value dictionary using adjacent elements.\n\t>>> tuple_to_dict((1, 5, 7, 10, 13, 5))\n\t{1: 5, 7: 10, 13: 5}\n\t>>> tuple_to_dict((1, 2, 3, 4, 5, 6))\n\t{1: 2, 3: 4, 5: 6}\n\t>>> tuple_to_d... | |
741 | train | Write a python function to check whether all the characters are same or not. | [
"assert all_Characters_Same(\"python\") == False",
"assert all_Characters_Same(\"aaa\") == True",
"assert all_Characters_Same(\"data\") == False"
] | [] | def all_Characters_Same(s) :
''' Write a python function to check whether all the characters are same or not.
>>> all_Characters_Same('python')
False
>>> all_Characters_Same('aaa')
True
>>> all_Characters_Same('data')
False
''' | ```python
def all_Characters_Same(s) :
''' Write a python function to check whether all the characters are same or not.
>>> all_Characters_Same('python')
False
>>> all_Characters_Same('aaa')
True
>>> all_Characters_Same('data')
False
'''
n = len(s)
for i in range(1,n) :
i... | [
{
"role": "user",
"content": "def all_Characters_Same(s) :\n\t''' Write a python function to check whether all the characters are same or not.\n\t>>> all_Characters_Same('python')\n\tFalse\n\t>>> all_Characters_Same('aaa')\n\tTrue\n\t>>> all_Characters_Same('data')\n\tFalse\n\t'''"
},
{
"role": "ass... | |
742 | train | Write a function to caluclate the area of a tetrahedron. | [
"assert area_tetrahedron(3)==15.588457268119894",
"assert area_tetrahedron(20)==692.8203230275509",
"assert area_tetrahedron(10)==173.20508075688772"
] | [] | import math
def area_tetrahedron(side):
''' Write a function to caluclate the area of a tetrahedron.
>>> area_tetrahedron(3)
15.588457268119894
>>> area_tetrahedron(20)
692.8203230275509
>>> area_tetrahedron(10)
173.20508075688772
''' | ```python
import math
def area_tetrahedron(side):
''' Write a function to caluclate the area of a tetrahedron.
>>> area_tetrahedron(3)
15.588457268119894
>>> area_tetrahedron(20)
692.8203230275509
>>> area_tetrahedron(10)
173.20508075688772
'''
area = math.sqrt(3)*(side*side)
return area
``` | [
{
"role": "user",
"content": "import math\ndef area_tetrahedron(side):\n\t''' Write a function to caluclate the area of a tetrahedron.\n\t>>> area_tetrahedron(3)\n\t15.588457268119894\n\t>>> area_tetrahedron(20)\n\t692.8203230275509\n\t>>> area_tetrahedron(10)\n\t173.20508075688772\n\t'''"
},
{
"rol... | |
743 | train | Write a function to rotate a given list by specified number of items to the right direction. | [
"assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[8, 9, 10, 1, 2, 3, 4, 5, 6]",
"assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]",
"assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8]"
] | [] | def rotate_right(list1,m,n):
''' Write a function to rotate a given list by specified number of items to the right direction.
>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 4)
[8, 9, 10, 1, 2, 3, 4, 5, 6]
>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2, 2)
[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
>>> rotate_righ... | ```python
def rotate_right(list1,m,n):
''' Write a function to rotate a given list by specified number of items to the right direction.
>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 4)
[8, 9, 10, 1, 2, 3, 4, 5, 6]
>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2, 2)
[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
... | [
{
"role": "user",
"content": "def rotate_right(list1,m,n):\n\t''' Write a function to rotate a given list by specified number of items to the right direction.\n\t>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 4)\n\t[8, 9, 10, 1, 2, 3, 4, 5, 6]\n\t>>> rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2, 2)... | |
744 | train | Write a function to check if the given tuple has any none value or not. | [
"assert check_none((10, 4, 5, 6, None)) == True",
"assert check_none((7, 8, 9, 11, 14)) == False",
"assert check_none((1, 2, 3, 4, None)) == True"
] | [] | def check_none(test_tup):
''' Write a function to check if the given tuple has any none value or not.
>>> check_none((10, 4, 5, 6, None))
True
>>> check_none((7, 8, 9, 11, 14))
False
>>> check_none((1, 2, 3, 4, None))
True
''' | ```python
def check_none(test_tup):
''' Write a function to check if the given tuple has any none value or not.
>>> check_none((10, 4, 5, 6, None))
True
>>> check_none((7, 8, 9, 11, 14))
False
>>> check_none((1, 2, 3, 4, None))
True
'''
res = any(map(lambda ele: ele is None, test_tup))
return (res)
... | [
{
"role": "user",
"content": "def check_none(test_tup):\n\t''' Write a function to check if the given tuple has any none value or not.\n\t>>> check_none((10, 4, 5, 6, None))\n\tTrue\n\t>>> check_none((7, 8, 9, 11, 14))\n\tFalse\n\t>>> check_none((1, 2, 3, 4, None))\n\tTrue\n\t'''"
},
{
"role": "assi... | |
745 | train | Write a function to find numbers within a given range where every number is divisible by every digit it contains. | [
"assert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]",
"assert divisible_by_digits(1,15)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15]",
"assert divisible_by_digits(20,25)==[22, 24]"
] | [] | def divisible_by_digits(startnum, endnum):
''' Write a function to find numbers within a given range where every number is divisible by every digit it contains.
>>> divisible_by_digits(1, 22)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
>>> divisible_by_digits(1, 15)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15]
>>> div... | ```python
def divisible_by_digits(startnum, endnum):
''' Write a function to find numbers within a given range where every number is divisible by every digit it contains.
>>> divisible_by_digits(1, 22)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
>>> divisible_by_digits(1, 15)
[1, 2, 3, 4, 5, 6, 7, 8... | [
{
"role": "user",
"content": "def divisible_by_digits(startnum, endnum):\n\t''' Write a function to find numbers within a given range where every number is divisible by every digit it contains.\n\t>>> divisible_by_digits(1, 22)\n\t[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n\t>>> divisible_by_digits(1, 15)... | |
746 | train | Write a function to find area of a sector. | [
"assert sector_area(4,45)==6.285714285714286",
"assert sector_area(9,45)==31.82142857142857",
"assert sector_area(9,360)==None"
] | [] | def sector_area(r,a):
''' Write a function to find area of a sector.
>>> sector_area(4, 45)
6.285714285714286
>>> sector_area(9, 45)
31.82142857142857
>>> sector_area(9, 360)
None
''' | ```python
def sector_area(r,a):
''' Write a function to find area of a sector.
>>> sector_area(4, 45)
6.285714285714286
>>> sector_area(9, 45)
31.82142857142857
>>> sector_area(9, 360)
None
'''
pi=22/7
if a >= 360:
return None
sectorarea = (pi*r**2) * (a/360)
retu... | [
{
"role": "user",
"content": "def sector_area(r,a):\n\t''' Write a function to find area of a sector.\n\t>>> sector_area(4, 45)\n\t6.285714285714286\n\t>>> sector_area(9, 45)\n\t31.82142857142857\n\t>>> sector_area(9, 360)\n\tNone\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef sect... | |
747 | train | Write a function to find the longest common subsequence for the given three string sequence. | [
"assert lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) == 2",
"assert lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) == 5 ",
"assert lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) == 3"
] | [] | def lcs_of_three(X, Y, Z, m, n, o):
''' Write a function to find the longest common subsequence for the given three string sequence.
>>> lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5)
2
>>> lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13)
5
>>> lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5)... | ```python
def lcs_of_three(X, Y, Z, m, n, o):
''' Write a function to find the longest common subsequence for the given three string sequence.
>>> lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5)
2
>>> lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13)
5
>>> lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea'... | [
{
"role": "user",
"content": "def lcs_of_three(X, Y, Z, m, n, o): \n\t''' Write a function to find the longest common subsequence for the given three string sequence.\n\t>>> lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5)\n\t2\n\t>>> lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13)\n\t5\n\t>... | |
748 | train | Write a function to put spaces between words starting with capital letters in a given string by using regex. | [
"assert capital_words_spaces(\"Python\") == 'Python'",
"assert capital_words_spaces(\"PythonProgrammingExamples\") == 'Python Programming Examples'",
"assert capital_words_spaces(\"GetReadyToBeCodingFreak\") == 'Get Ready To Be Coding Freak'"
] | [] | import re
def capital_words_spaces(str1):
''' Write a function to put spaces between words starting with capital letters in a given string by using regex.
>>> capital_words_spaces('Python')
'Python'
>>> capital_words_spaces('PythonProgrammingExamples')
'Python Programming Examples'
>>> capital_words_spaces('GetRe... | ```python
import re
def capital_words_spaces(str1):
''' Write a function to put spaces between words starting with capital letters in a given string by using regex.
>>> capital_words_spaces('Python')
'Python'
>>> capital_words_spaces('PythonProgrammingExamples')
'Python Programming Examples'
>>> capital_wor... | [
{
"role": "user",
"content": "import re\ndef capital_words_spaces(str1):\n\t''' Write a function to put spaces between words starting with capital letters in a given string by using regex.\n\t>>> capital_words_spaces('Python')\n\t'Python'\n\t>>> capital_words_spaces('PythonProgrammingExamples')\n\t'Python P... | |
749 | train | Write a function to sort a given list of strings of numbers numerically. | [
"assert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200]",
"assert sort_numeric_strings(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2'])==[1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9]",
"assert sort_n... | [] | def sort_numeric_strings(nums_str):
''' Write a function to sort a given list of strings of numbers numerically.
>>> sort_numeric_strings(['4', '12', '45', '7', '0', '100', '200', '-12', '-500'])
[-500, -12, 0, 4, 7, 12, 45, 100, 200]
>>> sort_numeric_strings(['2', '3', '8', '4', '7', '9', '8', '2', '6', '5', '1', ... | ```python
def sort_numeric_strings(nums_str):
''' Write a function to sort a given list of strings of numbers numerically.
>>> sort_numeric_strings(['4', '12', '45', '7', '0', '100', '200', '-12', '-500'])
[-500, -12, 0, 4, 7, 12, 45, 100, 200]
>>> sort_numeric_strings(['2', '3', '8', '4', '7', '9', '8'... | [
{
"role": "user",
"content": "def sort_numeric_strings(nums_str):\n\t''' Write a function to sort a given list of strings of numbers numerically.\n\t>>> sort_numeric_strings(['4', '12', '45', '7', '0', '100', '200', '-12', '-500'])\n\t[-500, -12, 0, 4, 7, 12, 45, 100, 200]\n\t>>> sort_numeric_strings(['2', ... | |
750 | train | Write a function to add the given tuple to the given list. | [
"assert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]",
"assert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11]",
"assert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]"
] | [] | def add_tuple(test_list, test_tup):
''' Write a function to add the given tuple to the given list.
>>> add_tuple([5, 6, 7], (9, 10))
[5, 6, 7, 9, 10]
>>> add_tuple([6, 7, 8], (10, 11))
[6, 7, 8, 10, 11]
>>> add_tuple([7, 8, 9], (11, 12))
[7, 8, 9, 11, 12]
''' | ```python
def add_tuple(test_list, test_tup):
''' Write a function to add the given tuple to the given list.
>>> add_tuple([5, 6, 7], (9, 10))
[5, 6, 7, 9, 10]
>>> add_tuple([6, 7, 8], (10, 11))
[6, 7, 8, 10, 11]
>>> add_tuple([7, 8, 9], (11, 12))
[7, 8, 9, 11, 12]
'''
test_list += test_tup
return (... | [
{
"role": "user",
"content": "def add_tuple(test_list, test_tup):\n\t''' Write a function to add the given tuple to the given list.\n\t>>> add_tuple([5, 6, 7], (9, 10))\n\t[5, 6, 7, 9, 10]\n\t>>> add_tuple([6, 7, 8], (10, 11))\n\t[6, 7, 8, 10, 11]\n\t>>> add_tuple([7, 8, 9], (11, 12))\n\t[7, 8, 9, 11, 12]\n... | |
751 | train | Write a function to check if the given array represents min heap or not. | [
"assert check_min_heap([1, 2, 3, 4, 5, 6], 0) == True",
"assert check_min_heap([2, 3, 4, 5, 10, 15], 0) == True",
"assert check_min_heap([2, 10, 4, 5, 3, 15], 0) == False"
] | [] | def check_min_heap(arr, i):
''' Write a function to check if the given array represents min heap or not.
>>> check_min_heap([1, 2, 3, 4, 5, 6], 0)
True
>>> check_min_heap([2, 3, 4, 5, 10, 15], 0)
True
>>> check_min_heap([2, 10, 4, 5, 3, 15], 0)
False
''' | ```python
def check_min_heap(arr, i):
''' Write a function to check if the given array represents min heap or not.
>>> check_min_heap([1, 2, 3, 4, 5, 6], 0)
True
>>> check_min_heap([2, 3, 4, 5, 10, 15], 0)
True
>>> check_min_heap([2, 10, 4, 5, 3, 15], 0)
False
'''
if 2 * i + 2 > len(... | [
{
"role": "user",
"content": "def check_min_heap(arr, i):\n\t''' Write a function to check if the given array represents min heap or not.\n\t>>> check_min_heap([1, 2, 3, 4, 5, 6], 0)\n\tTrue\n\t>>> check_min_heap([2, 3, 4, 5, 10, 15], 0)\n\tTrue\n\t>>> check_min_heap([2, 10, 4, 5, 3, 15], 0)\n\tFalse\n\t'''... | |
752 | train | Write a function to find the nth jacobsthal number. | [
"assert jacobsthal_num(5) == 11",
"assert jacobsthal_num(2) == 1",
"assert jacobsthal_num(4) == 5"
] | [] | def jacobsthal_num(n):
''' Write a function to find the nth jacobsthal number.
>>> jacobsthal_num(5)
11
>>> jacobsthal_num(2)
1
>>> jacobsthal_num(4)
5
''' | ```python
def jacobsthal_num(n):
''' Write a function to find the nth jacobsthal number.
>>> jacobsthal_num(5)
11
>>> jacobsthal_num(2)
1
>>> jacobsthal_num(4)
5
'''
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = 1
for i in range(2, n+1):
dp[i] = dp[i - 1] + 2 * dp[i - 2]
return dp[n]
``` | [
{
"role": "user",
"content": "def jacobsthal_num(n): \n\t''' Write a function to find the nth jacobsthal number.\n\t>>> jacobsthal_num(5)\n\t11\n\t>>> jacobsthal_num(2)\n\t1\n\t>>> jacobsthal_num(4)\n\t5\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef jacobsthal_num(n): \n\t''' Writ... | |
753 | train | Write a function to find minimum k records from tuple list. | [
"assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]",
"assert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]",
"assert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)... | [] | def min_k(test_list, K):
''' Write a function to find minimum k records from tuple list.
>>> min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2)
[('Akash', 2), ('Akshat', 4)]
>>> min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3)
[('Akash', 3), ('Angat', 5), ('Nepin', 9)]
>>... | ```python
def min_k(test_list, K):
''' Write a function to find minimum k records from tuple list.
>>> min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2)
[('Akash', 2), ('Akshat', 4)]
>>> min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3)
[('Akash', 3), ('Angat', 5), ('... | [
{
"role": "user",
"content": "def min_k(test_list, K):\n\t''' Write a function to find minimum k records from tuple list.\n\t>>> min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2)\n\t[('Akash', 2), ('Akshat', 4)]\n\t>>> min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], ... | |
754 | train | Write a function to find common index elements from three lists. | [
"assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7]",
"assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7])==[1, 6]",
"assert extract_index_list([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 5]"
] | [] | def extract_index_list(l1, l2, l3):
''' Write a function to find common index elements from three lists.
>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 7], [0, 1, 2, 3, 4, 5, 7])
[1, 7]
>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 6, 5], [0, 1, 2, 3, 4, 6, 7])
[1, 6]
>>> extract... | ```python
def extract_index_list(l1, l2, l3):
''' Write a function to find common index elements from three lists.
>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 7], [0, 1, 2, 3, 4, 5, 7])
[1, 7]
>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 6, 5], [0, 1, 2, 3, 4, 6, 7]... | [
{
"role": "user",
"content": "def extract_index_list(l1, l2, l3):\n\t''' Write a function to find common index elements from three lists.\n\t>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 7], [0, 1, 2, 3, 4, 5, 7])\n\t[1, 7]\n\t>>> extract_index_list([1, 1, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, ... | |
755 | train | Write a function to find the second smallest number in a list. | [
"assert second_smallest([1, 2, -8, -2, 0, -2])==-2",
"assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5",
"assert second_smallest([2,2])==None"
] | [] | def second_smallest(numbers):
''' Write a function to find the second smallest number in a list.
>>> second_smallest([1, 2, -8, -2, 0, -2])
-2
>>> second_smallest([1, 1, -0.5, 0, 2, -2, -2])
-0.5
>>> second_smallest([2, 2])
None
''' | ```python
def second_smallest(numbers):
''' Write a function to find the second smallest number in a list.
>>> second_smallest([1, 2, -8, -2, 0, -2])
-2
>>> second_smallest([1, 1, -0.5, 0, 2, -2, -2])
-0.5
>>> second_smallest([2, 2])
None
'''
if (len(numbers)<2):
return
if ((len(numbers)==2) an... | [
{
"role": "user",
"content": "def second_smallest(numbers):\n\t''' Write a function to find the second smallest number in a list.\n\t>>> second_smallest([1, 2, -8, -2, 0, -2])\n\t-2\n\t>>> second_smallest([1, 1, -0.5, 0, 2, -2, -2])\n\t-0.5\n\t>>> second_smallest([2, 2])\n\tNone\n\t'''"
},
{
"role":... | |
756 | train | Write a function that matches a string that has an a followed by zero or one 'b'. | [
"assert text_match_zero_one(\"ac\")==('Found a match!')",
"assert text_match_zero_one(\"dc\")==('Not matched!')",
"assert text_match_zero_one(\"abbbba\")==('Found a match!')"
] | [] | import re
def text_match_zero_one(text):
''' Write a function that matches a string that has an a followed by zero or one 'b'.
>>> text_match_zero_one('ac')
'Found a match!'
>>> text_match_zero_one('dc')
'Not matched!'
>>> text_match_zero_one('abbbba')
'Found a match!'
''' | ```python
import re
def text_match_zero_one(text):
''' Write a function that matches a string that has an a followed by zero or one 'b'.
>>> text_match_zero_one('ac')
'Found a match!'
>>> text_match_zero_one('dc')
'Not matched!'
>>> text_match_zero_one('abbbba')
'... | [
{
"role": "user",
"content": "import re\ndef text_match_zero_one(text):\n\t''' Write a function that matches a string that has an a followed by zero or one 'b'.\n\t>>> text_match_zero_one('ac')\n\t'Found a match!'\n\t>>> text_match_zero_one('dc')\n\t'Not matched!'\n\t>>> text_match_zero_one('abbbba')\n\t'Fo... | |
757 | train | Write a function to count the pairs of reverse strings in the given string list. | [
"assert count_reverse_pairs([\"julia\", \"best\", \"tseb\", \"for\", \"ailuj\"])== '2'",
"assert count_reverse_pairs([\"geeks\", \"best\", \"for\", \"skeeg\"]) == '1'",
"assert count_reverse_pairs([\"makes\", \"best\", \"sekam\", \"for\", \"rof\"]) == '2' "
] | [] | def count_reverse_pairs(test_list):
''' Write a function to count the pairs of reverse strings in the given string list.
>>> count_reverse_pairs(['julia', 'best', 'tseb', 'for', 'ailuj'])
'2'
>>> count_reverse_pairs(['geeks', 'best', 'for', 'skeeg'])
'1'
>>> count_reverse_pairs(['makes', 'best', 'sekam', 'for', '... | ```python
def count_reverse_pairs(test_list):
''' Write a function to count the pairs of reverse strings in the given string list.
>>> count_reverse_pairs(['julia', 'best', 'tseb', 'for', 'ailuj'])
'2'
>>> count_reverse_pairs(['geeks', 'best', 'for', 'skeeg'])
'1'
>>> count_reverse_pairs(['makes', 'best', '... | [
{
"role": "user",
"content": "def count_reverse_pairs(test_list):\n\t''' Write a function to count the pairs of reverse strings in the given string list.\n\t>>> count_reverse_pairs(['julia', 'best', 'tseb', 'for', 'ailuj'])\n\t'2'\n\t>>> count_reverse_pairs(['geeks', 'best', 'for', 'skeeg'])\n\t'1'\n\t>>> c... | |
758 | train | Write a function to count number of unique lists within a list. | [
"assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]] )=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}",
"assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}",
"assert unique_sublists([[1... | [] | def unique_sublists(list1):
''' Write a function to count number of unique lists within a list.
>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])
{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
>>> unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])
{('g... | ```python
def unique_sublists(list1):
''' Write a function to count number of unique lists within a list.
>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])
{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
>>> unique_sublists([['green', 'orange'], ['black'], ['green', 'orang... | [
{
"role": "user",
"content": "def unique_sublists(list1):\n\t''' Write a function to count number of unique lists within a list.\n\t>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])\n\t{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}\n\t>>> unique_sublists([['green', 'orange'],... | |
759 | train | Write a function to check a decimal with a precision of 2. | [
"assert is_decimal('123.11')==True",
"assert is_decimal('e666.86')==False",
"assert is_decimal('3.124587')==False"
] | [] | def is_decimal(num):
''' Write a function to check a decimal with a precision of 2.
>>> is_decimal('123.11')
True
>>> is_decimal('e666.86')
False
>>> is_decimal('3.124587')
False
''' | ```python
def is_decimal(num):
''' Write a function to check a decimal with a precision of 2.
>>> is_decimal('123.11')
True
>>> is_decimal('e666.86')
False
>>> is_decimal('3.124587')
False
'''
import re
dnumre = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
result = dnumre.searc... | [
{
"role": "user",
"content": "def is_decimal(num):\n\t''' Write a function to check a decimal with a precision of 2.\n\t>>> is_decimal('123.11')\n\tTrue\n\t>>> is_decimal('e666.86')\n\tFalse\n\t>>> is_decimal('3.124587')\n\tFalse\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef is_de... | |
760 | train | Write a python function to check whether an array contains only one distinct element or not. | [
"assert unique_Element([1,1,1],3) == 'YES'",
"assert unique_Element([1,2,1,2],4) == 'NO'",
"assert unique_Element([1,2,3,4,5],5) == 'NO'"
] | [] | def unique_Element(arr,n):
''' Write a python function to check whether an array contains only one distinct element or not.
>>> unique_Element([1, 1, 1], 3)
'YES'
>>> unique_Element([1, 2, 1, 2], 4)
'NO'
>>> unique_Element([1, 2, 3, 4, 5], 5)
'NO'
''' | ```python
def unique_Element(arr,n):
''' Write a python function to check whether an array contains only one distinct element or not.
>>> unique_Element([1, 1, 1], 3)
'YES'
>>> unique_Element([1, 2, 1, 2], 4)
'NO'
>>> unique_Element([1, 2, 3, 4, 5], 5)
'NO'
'''
s = set(arr)
if (l... | [
{
"role": "user",
"content": "def unique_Element(arr,n):\n\t''' Write a python function to check whether an array contains only one distinct element or not.\n\t>>> unique_Element([1, 1, 1], 3)\n\t'YES'\n\t>>> unique_Element([1, 2, 1, 2], 4)\n\t'NO'\n\t>>> unique_Element([1, 2, 3, 4, 5], 5)\n\t'NO'\n\t'''"
... | |
761 | train | Write a function to caluclate arc length of an angle. | [
"assert arc_length(9,45)==3.5357142857142856",
"assert arc_length(9,480)==None",
"assert arc_length(5,270)==11.785714285714285"
] | [] | def arc_length(d,a):
''' Write a function to caluclate arc length of an angle.
>>> arc_length(9, 45)
3.5357142857142856
>>> arc_length(9, 480)
None
>>> arc_length(5, 270)
11.785714285714285
''' | ```python
def arc_length(d,a):
''' Write a function to caluclate arc length of an angle.
>>> arc_length(9, 45)
3.5357142857142856
>>> arc_length(9, 480)
None
>>> arc_length(5, 270)
11.785714285714285
'''
pi=22/7
if a >= 360:
return None
arclength = (pi*d) * (a/360)
... | [
{
"role": "user",
"content": "def arc_length(d,a):\n\t''' Write a function to caluclate arc length of an angle.\n\t>>> arc_length(9, 45)\n\t3.5357142857142856\n\t>>> arc_length(9, 480)\n\tNone\n\t>>> arc_length(5, 270)\n\t11.785714285714285\n\t'''"
},
{
"role": "assistant",
"content": "```python... | |
762 | train | Write a function to check whether the given month number contains 30 days or not. | [
"assert check_monthnumber_number(6)==True",
"assert check_monthnumber_number(2)==False",
"assert check_monthnumber_number(12)==False"
] | [] | def check_monthnumber_number(monthnum3):
''' Write a function to check whether the given month number contains 30 days or not.
>>> check_monthnumber_number(6)
True
>>> check_monthnumber_number(2)
False
>>> check_monthnumber_number(12)
False
''' | ```python
def check_monthnumber_number(monthnum3):
''' Write a function to check whether the given month number contains 30 days or not.
>>> check_monthnumber_number(6)
True
>>> check_monthnumber_number(2)
False
>>> check_monthnumber_number(12)
False
'''
if(monthnum3==4 or monthnum3==6 or monthnum3==9... | [
{
"role": "user",
"content": "def check_monthnumber_number(monthnum3):\n\t''' Write a function to check whether the given month number contains 30 days or not.\n\t>>> check_monthnumber_number(6)\n\tTrue\n\t>>> check_monthnumber_number(2)\n\tFalse\n\t>>> check_monthnumber_number(12)\n\tFalse\n\t'''"
},
{... | |
763 | train | Write a python function to find the minimum difference between any two elements in a given array. | [
"assert find_Min_Diff((1,5,3,19,18,25),6) == 1",
"assert find_Min_Diff((4,3,2,6),4) == 1",
"assert find_Min_Diff((30,5,20,9),4) == 4"
] | [] | def find_Min_Diff(arr,n):
''' Write a python function to find the minimum difference between any two elements in a given array.
>>> find_Min_Diff((1, 5, 3, 19, 18, 25), 6)
1
>>> find_Min_Diff((4, 3, 2, 6), 4)
1
>>> find_Min_Diff((30, 5, 20, 9), 4)
4
''' | ```python
def find_Min_Diff(arr,n):
''' Write a python function to find the minimum difference between any two elements in a given array.
>>> find_Min_Diff((1, 5, 3, 19, 18, 25), 6)
1
>>> find_Min_Diff((4, 3, 2, 6), 4)
1
>>> find_Min_Diff((30, 5, 20, 9), 4)
4
'''
arr = sorted(arr)
... | [
{
"role": "user",
"content": "def find_Min_Diff(arr,n): \n\t''' Write a python function to find the minimum difference between any two elements in a given array.\n\t>>> find_Min_Diff((1, 5, 3, 19, 18, 25), 6)\n\t1\n\t>>> find_Min_Diff((4, 3, 2, 6), 4)\n\t1\n\t>>> find_Min_Diff((30, 5, 20, 9), 4)\n\t4\n\t'''... | |
764 | train | Write a python function to count numeric values in a given string. | [
"assert number_ctr('program2bedone') == 1",
"assert number_ctr('3wonders') ==1",
"assert number_ctr('123') == 3"
] | [] | def number_ctr(str):
''' Write a python function to count numeric values in a given string.
>>> number_ctr('program2bedone')
1
>>> number_ctr('3wonders')
1
>>> number_ctr('123')
3
''' | ```python
def number_ctr(str):
''' Write a python function to count numeric values in a given string.
>>> number_ctr('program2bedone')
1
>>> number_ctr('3wonders')
1
>>> number_ctr('123')
3
'''
number_ctr= 0
for i in range(len(str)):
if str[i] >= '0'... | [
{
"role": "user",
"content": "def number_ctr(str):\n\t''' Write a python function to count numeric values in a given string.\n\t>>> number_ctr('program2bedone')\n\t1\n\t>>> number_ctr('3wonders')\n\t1\n\t>>> number_ctr('123')\n\t3\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef numb... | |
765 | train | Write a function to find nth polite number. | [
"assert is_polite(7) == 11",
"assert is_polite(4) == 7",
"assert is_polite(9) == 13"
] | [] | import math
def is_polite(n):
''' Write a function to find nth polite number.
>>> is_polite(7)
11
>>> is_polite(4)
7
>>> is_polite(9)
13
''' | ```python
import math
def is_polite(n):
''' Write a function to find nth polite number.
>>> is_polite(7)
11
>>> is_polite(4)
7
>>> is_polite(9)
13
'''
n = n + 1
return (int)(n+(math.log((n + math.log(n, 2)), 2)))
``` | [
{
"role": "user",
"content": "import math\ndef is_polite(n): \n\t''' Write a function to find nth polite number.\n\t>>> is_polite(7)\n\t11\n\t>>> is_polite(4)\n\t7\n\t>>> is_polite(9)\n\t13\n\t'''"
},
{
"role": "assistant",
"content": "```python\nimport math\ndef is_polite(n): \n\t''' Write a fu... | |
766 | train | Write a function to iterate over all pairs of consecutive items in a given list. | [
"assert pair_wise([1,1,2,3,3,4,4,5])==[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]",
"assert pair_wise([1,5,7,9,10])==[(1, 5), (5, 7), (7, 9), (9, 10)]",
"assert pair_wise([1,2,3,4,5,6,7,8,9,10])==[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10)]"
] | [] | def pair_wise(l1):
''' Write a function to iterate over all pairs of consecutive items in a given list.
>>> pair_wise([1, 1, 2, 3, 3, 4, 4, 5])
[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]
>>> pair_wise([1, 5, 7, 9, 10])
[(1, 5), (5, 7), (7, 9), (9, 10)]
>>> pair_wise([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
... | ```python
def pair_wise(l1):
''' Write a function to iterate over all pairs of consecutive items in a given list.
>>> pair_wise([1, 1, 2, 3, 3, 4, 4, 5])
[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]
>>> pair_wise([1, 5, 7, 9, 10])
[(1, 5), (5, 7), (7, 9), (9, 10)]
>>> pair_wise([1, 2... | [
{
"role": "user",
"content": "def pair_wise(l1):\n\t''' Write a function to iterate over all pairs of consecutive items in a given list.\n\t>>> pair_wise([1, 1, 2, 3, 3, 4, 4, 5])\n\t[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]\n\t>>> pair_wise([1, 5, 7, 9, 10])\n\t[(1, 5), (5, 7), (7, 9), (9, 1... | |
767 | train | Write a python function to count the number of pairs whose sum is equal to ‘sum’. | [
"assert get_Pairs_Count([1,1,1,1],4,2) == 6",
"assert get_Pairs_Count([1,5,7,-1,5],5,6) == 3",
"assert get_Pairs_Count([1,-2,3],3,1) == 1"
] | [] | def get_Pairs_Count(arr,n,sum):
''' Write a python function to count the number of pairs whose sum is equal to ‘sum’.
>>> get_Pairs_Count([1, 1, 1, 1], 4, 2)
6
>>> get_Pairs_Count([1, 5, 7, -1, 5], 5, 6)
3
>>> get_Pairs_Count([1, -2, 3], 3, 1)
1
''' | ```python
def get_Pairs_Count(arr,n,sum):
''' Write a python function to count the number of pairs whose sum is equal to ‘sum’.
>>> get_Pairs_Count([1, 1, 1, 1], 4, 2)
6
>>> get_Pairs_Count([1, 5, 7, -1, 5], 5, 6)
3
>>> get_Pairs_Count([1, -2, 3], 3, 1)
1
'''
count = 0
for i in... | [
{
"role": "user",
"content": "def get_Pairs_Count(arr,n,sum):\n\t''' Write a python function to count the number of pairs whose sum is equal to ‘sum’.\n\t>>> get_Pairs_Count([1, 1, 1, 1], 4, 2)\n\t6\n\t>>> get_Pairs_Count([1, 5, 7, -1, 5], 5, 6)\n\t3\n\t>>> get_Pairs_Count([1, -2, 3], 3, 1)\n\t1\n\t'''"
}... | |
768 | train | Write a python function to check for odd parity of a given number. | [
"assert check_Odd_Parity(13) == True",
"assert check_Odd_Parity(21) == True",
"assert check_Odd_Parity(18) == False"
] | [] | def check_Odd_Parity(x):
''' Write a python function to check for odd parity of a given number.
>>> check_Odd_Parity(13)
True
>>> check_Odd_Parity(21)
True
>>> check_Odd_Parity(18)
False
''' | ```python
def check_Odd_Parity(x):
''' Write a python function to check for odd parity of a given number.
>>> check_Odd_Parity(13)
True
>>> check_Odd_Parity(21)
True
>>> check_Odd_Parity(18)
False
'''
parity = 0
while (x != 0):
x = x & (x - 1)
parity += 1
i... | [
{
"role": "user",
"content": "def check_Odd_Parity(x): \n\t''' Write a python function to check for odd parity of a given number.\n\t>>> check_Odd_Parity(13)\n\tTrue\n\t>>> check_Odd_Parity(21)\n\tTrue\n\t>>> check_Odd_Parity(18)\n\tFalse\n\t'''"
},
{
"role": "assistant",
"content": "```python\n... | |
769 | train | Write a python function to get the difference between two lists. | [
"assert (Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])) == [10, 20, 30, 15]",
"assert (Diff([1,2,3,4,5], [6,7,1])) == [2,3,4,5,6,7]",
"assert (Diff([1,2,3], [6,7,1])) == [2,3,6,7]"
] | [] | def Diff(li1,li2):
''' Write a python function to get the difference between two lists.
>>> Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])
[10, 20, 30, 15]
>>> Diff([1, 2, 3, 4, 5], [6, 7, 1])
[2, 3, 4, 5, 6, 7]
>>> Diff([1, 2, 3], [6, 7, 1])
[2, 3, 6, 7]
''' | ```python
def Diff(li1,li2):
''' Write a python function to get the difference between two lists.
>>> Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])
[10, 20, 30, 15]
>>> Diff([1, 2, 3, 4, 5], [6, 7, 1])
[2, 3, 4, 5, 6, 7]
>>> Diff([1, 2, 3], [6, 7, 1])
[2, 3, 6, 7]
'''
return (list... | [
{
"role": "user",
"content": "def Diff(li1,li2):\n\t''' Write a python function to get the difference between two lists.\n\t>>> Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])\n\t[10, 20, 30, 15]\n\t>>> Diff([1, 2, 3, 4, 5], [6, 7, 1])\n\t[2, 3, 4, 5, 6, 7]\n\t>>> Diff([1, 2, 3], [6, 7, 1])\n\t[2, 3, 6, 7]... | |
770 | train | Write a python function to find the sum of fourth power of first n odd natural numbers. | [
"assert odd_Num_Sum(2) == 82",
"assert odd_Num_Sum(3) == 707",
"assert odd_Num_Sum(4) == 3108"
] | [] | def odd_Num_Sum(n) :
''' Write a python function to find the sum of fourth power of first n odd natural numbers.
>>> odd_Num_Sum(2)
82
>>> odd_Num_Sum(3)
707
>>> odd_Num_Sum(4)
3108
''' | ```python
def odd_Num_Sum(n) :
''' Write a python function to find the sum of fourth power of first n odd natural numbers.
>>> odd_Num_Sum(2)
82
>>> odd_Num_Sum(3)
707
>>> odd_Num_Sum(4)
3108
'''
j = 0
sm = 0
for i in range(1,n + 1) :
j = (2*i-1)
sm = sm + ... | [
{
"role": "user",
"content": "def odd_Num_Sum(n) : \n\t''' Write a python function to find the sum of fourth power of first n odd natural numbers.\n\t>>> odd_Num_Sum(2)\n\t82\n\t>>> odd_Num_Sum(3)\n\t707\n\t>>> odd_Num_Sum(4)\n\t3108\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef o... | |
771 | train | Write a function to check if the given expression is balanced or not. | [
"assert check_expression(\"{()}[{}]\") == True",
"assert check_expression(\"{()}[{]\") == False",
"assert check_expression(\"{()}[{}][]({})\") == True"
] | [] | from collections import deque
def check_expression(exp):
''' Write a function to check if the given expression is balanced or not.
>>> check_expression('{()}[{}]')
True
>>> check_expression('{()}[{]')
False
>>> check_expression('{()}[{}][]({})')
True
''' | ```python
from collections import deque
def check_expression(exp):
''' Write a function to check if the given expression is balanced or not.
>>> check_expression('{()}[{}]')
True
>>> check_expression('{()}[{]')
False
>>> check_expression('{()}[{}][]({})')
True
'''
if len(exp) & 1:
... | [
{
"role": "user",
"content": "from collections import deque\ndef check_expression(exp):\n\t''' Write a function to check if the given expression is balanced or not.\n\t>>> check_expression('{()}[{}]')\n\tTrue\n\t>>> check_expression('{()}[{]')\n\tFalse\n\t>>> check_expression('{()}[{}][]({})')\n\tTrue\n\t''... | |
772 | train | Write a function to remove all the words with k length in the given string. | [
"assert remove_length('The person is most value tet', 3) == 'person is most value'",
"assert remove_length('If you told me about this ok', 4) == 'If you me about ok'",
"assert remove_length('Forces of darkeness is come into the play', 4) == 'Forces of darkeness is the'"
] | [] | def remove_length(test_str, K):
''' Write a function to remove all the words with k length in the given string.
>>> remove_length('The person is most value tet', 3)
'person is most value'
>>> remove_length('If you told me about this ok', 4)
'If you me about ok'
>>> remove_length('Forces of darkeness is come into ... | ```python
def remove_length(test_str, K):
''' Write a function to remove all the words with k length in the given string.
>>> remove_length('The person is most value tet', 3)
'person is most value'
>>> remove_length('If you told me about this ok', 4)
'If you me about ok'
>>> remove_length('Forces of darkene... | [
{
"role": "user",
"content": "def remove_length(test_str, K):\n\t''' Write a function to remove all the words with k length in the given string.\n\t>>> remove_length('The person is most value tet', 3)\n\t'person is most value'\n\t>>> remove_length('If you told me about this ok', 4)\n\t'If you me about ok'\n... | |
773 | train | Write a function to find the occurrence and position of the substrings within a string. | [
"assert occurance_substring('python programming, python language','python')==('python', 0, 6)",
"assert occurance_substring('python programming,programming language','programming')==('programming', 7, 18)",
"assert occurance_substring('python programming,programming language','language')==('language', 31, 39)"
... | [] | import re
def occurance_substring(text,pattern):
''' Write a function to find the occurrence and position of the substrings within a string.
>>> occurance_substring('python programming, python language', 'python')
('python', 0, 6)
>>> occurance_substring('python programming,programming language', 'programming')
('... | ```python
import re
def occurance_substring(text,pattern):
''' Write a function to find the occurrence and position of the substrings within a string.
>>> occurance_substring('python programming, python language', 'python')
('python', 0, 6)
>>> occurance_substring('python programming,programming language', 'program... | [
{
"role": "user",
"content": "import re\ndef occurance_substring(text,pattern):\n\t''' Write a function to find the occurrence and position of the substrings within a string.\n\t>>> occurance_substring('python programming, python language', 'python')\n\t('python', 0, 6)\n\t>>> occurance_substring('python pr... | |
774 | train | Write a function to check if the string is a valid email address or not using regex. | [
"assert check_email(\"ankitrai326@gmail.com\") == 'Valid Email'",
"assert check_email(\"my.ownsite@ourearth.org\") == 'Valid Email'",
"assert check_email(\"ankitaoie326.com\") == 'Invalid Email'"
] | [] | import re
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
def check_email(email):
''' Write a function to check if the string is a valid email address or not using regex.
>>> check_email('ankitrai326@gmail.com')
'Valid Email'
>>> check_email('my.ownsite@ourearth.org')
'Valid Email'
>>> check_email('ankitao... | ```python
import re
regex = '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'
def check_email(email):
''' Write a function to check if the string is a valid email address or not using regex.
>>> check_email('ankitrai326@gmail.com')
'Valid Email'
>>> check_email('my.ownsite@ourearth.org')
'Valid Email'
>>> check_e... | [
{
"role": "user",
"content": "import re \nregex = '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'\ndef check_email(email): \n\t''' Write a function to check if the string is a valid email address or not using regex.\n\t>>> check_email('ankitrai326@gmail.com')\n\t'Valid Email'\n\t>>> check_email('my.ownsite@... | |
775 | train | Write a python function to check whether every odd index contains odd numbers of a given list. | [
"assert odd_position([2,1,4,3,6,7,6,3]) == True",
"assert odd_position([4,1,2]) == True",
"assert odd_position([1,2,3]) == False"
] | [] | def odd_position(nums):
''' Write a python function to check whether every odd index contains odd numbers of a given list.
>>> odd_position([2, 1, 4, 3, 6, 7, 6, 3])
True
>>> odd_position([4, 1, 2])
True
>>> odd_position([1, 2, 3])
False
''' | ```python
def odd_position(nums):
''' Write a python function to check whether every odd index contains odd numbers of a given list.
>>> odd_position([2, 1, 4, 3, 6, 7, 6, 3])
True
>>> odd_position([4, 1, 2])
True
>>> odd_position([1, 2, 3])
False
'''
return all(nums[i]%2==i%2 for i in range(len(nums)))
``` | [
{
"role": "user",
"content": "def odd_position(nums):\n\t''' Write a python function to check whether every odd index contains odd numbers of a given list.\n\t>>> odd_position([2, 1, 4, 3, 6, 7, 6, 3])\n\tTrue\n\t>>> odd_position([4, 1, 2])\n\tTrue\n\t>>> odd_position([1, 2, 3])\n\tFalse\n\t'''"
},
{
... | |
776 | train | Write a function to count those characters which have vowels as their neighbors in the given string. | [
"assert count_vowels('bestinstareels') == 7",
"assert count_vowels('partofthejourneyistheend') == 12",
"assert count_vowels('amazonprime') == 5"
] | [] | def count_vowels(test_str):
''' Write a function to count those characters which have vowels as their neighbors in the given string.
>>> count_vowels('bestinstareels')
7
>>> count_vowels('partofthejourneyistheend')
12
>>> count_vowels('amazonprime')
5
''' | ```python
def count_vowels(test_str):
''' Write a function to count those characters which have vowels as their neighbors in the given string.
>>> count_vowels('bestinstareels')
7
>>> count_vowels('partofthejourneyistheend')
12
>>> count_vowels('amazonprime')
5
'''
res = 0
vow_list = ['a', 'e', 'i',... | [
{
"role": "user",
"content": "def count_vowels(test_str):\n\t''' Write a function to count those characters which have vowels as their neighbors in the given string.\n\t>>> count_vowels('bestinstareels')\n\t7\n\t>>> count_vowels('partofthejourneyistheend')\n\t12\n\t>>> count_vowels('amazonprime')\n\t5\n\t''... | |
777 | train | Write a python function to find the sum of non-repeated elements in a given array. | [
"assert find_Sum([1,2,3,1,1,4,5,6],8) == 21",
"assert find_Sum([1,10,9,4,2,10,10,45,4],9) == 71",
"assert find_Sum([12,10,9,45,2,10,10,45,10],9) == 78"
] | [] | def find_Sum(arr,n):
''' Write a python function to find the sum of non-repeated elements in a given array.
>>> find_Sum([1, 2, 3, 1, 1, 4, 5, 6], 8)
21
>>> find_Sum([1, 10, 9, 4, 2, 10, 10, 45, 4], 9)
71
>>> find_Sum([12, 10, 9, 45, 2, 10, 10, 45, 10], 9)
78
''' | ```python
def find_Sum(arr,n):
''' Write a python function to find the sum of non-repeated elements in a given array.
>>> find_Sum([1, 2, 3, 1, 1, 4, 5, 6], 8)
21
>>> find_Sum([1, 10, 9, 4, 2, 10, 10, 45, 4], 9)
71
>>> find_Sum([12, 10, 9, 45, 2, 10, 10, 45, 10], 9)
78
'''
arr.sort(... | [
{
"role": "user",
"content": "def find_Sum(arr,n): \n\t''' Write a python function to find the sum of non-repeated elements in a given array.\n\t>>> find_Sum([1, 2, 3, 1, 1, 4, 5, 6], 8)\n\t21\n\t>>> find_Sum([1, 10, 9, 4, 2, 10, 10, 45, 4], 9)\n\t71\n\t>>> find_Sum([12, 10, 9, 45, 2, 10, 10, 45, 10], 9)\n\... | |
778 | train | Write a function to pack consecutive duplicates of a given list elements into sublists. | [
"assert pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])==[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]",
"assert pack_consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[[10, 10], [15], [19], [18, 18], [17], [26, 26], [17], [18], [10]]"... | [] | from itertools import groupby
def pack_consecutive_duplicates(list1):
''' Write a function to pack consecutive duplicates of a given list elements into sublists.
>>> pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])
[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]
>... | ```python
from itertools import groupby
def pack_consecutive_duplicates(list1):
''' Write a function to pack consecutive duplicates of a given list elements into sublists.
>>> pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])
[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [... | [
{
"role": "user",
"content": "from itertools import groupby\ndef pack_consecutive_duplicates(list1):\n\t''' Write a function to pack consecutive duplicates of a given list elements into sublists.\n\t>>> pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])\n\t[[0, 0], [1], [2], [3], ... | |
779 | train | Write a function to count the number of unique lists within a list. | [
"assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}",
"assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}",
"assert unique_sublists([[1,... | [] | def unique_sublists(list1):
''' Write a function to count the number of unique lists within a list.
>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])
{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
>>> unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])
... | ```python
def unique_sublists(list1):
''' Write a function to count the number of unique lists within a list.
>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])
{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
>>> unique_sublists([['green', 'orange'], ['black'], ['green', 'o... | [
{
"role": "user",
"content": "def unique_sublists(list1):\n\t''' Write a function to count the number of unique lists within a list.\n\t>>> unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])\n\t{(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}\n\t>>> unique_sublists([['green', 'orang... | |
780 | train | Write a function to find the combinations of sums with tuples in the given tuple list. | [
"assert find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]",
"assert find_combinations([(3, 5), (7, 8), (6, 2), (7, 11)]) == [(10, 13), (9, 7), (10, 16), (13, 10), (14, 19), (13, 13)]",
"assert find_combinations([(4, 6), (8, 9), (7, 3), (8, 12)]) == [... | [] | from itertools import combinations
def find_combinations(test_list):
''' Write a function to find the combinations of sums with tuples in the given tuple list.
>>> find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)])
[(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]
>>> find_combinations([(3, 5), (7, 8), (6, ... | ```python
from itertools import combinations
def find_combinations(test_list):
''' Write a function to find the combinations of sums with tuples in the given tuple list.
>>> find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)])
[(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]
>>> find_combinations([(3, 5)... | [
{
"role": "user",
"content": "from itertools import combinations\ndef find_combinations(test_list):\n\t''' Write a function to find the combinations of sums with tuples in the given tuple list.\n\t>>> find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)])\n\t[(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, ... | |
781 | train | Write a python function to check whether the count of divisors is even or odd. | [
"assert count_Divisors(10) == \"Even\"",
"assert count_Divisors(100) == \"Odd\"",
"assert count_Divisors(125) == \"Even\""
] | [] | import math
def count_Divisors(n) :
''' Write a python function to check whether the count of divisors is even or odd.
>>> count_Divisors(10)
'Even'
>>> count_Divisors(100)
'Odd'
>>> count_Divisors(125)
'Even'
''' | ```python
import math
def count_Divisors(n) :
''' Write a python function to check whether the count of divisors is even or odd.
>>> count_Divisors(10)
'Even'
>>> count_Divisors(100)
'Odd'
>>> count_Divisors(125)
'Even'
'''
count = 0
for i in range(1, (int)(math.sqrt(n)) + 2) : ... | [
{
"role": "user",
"content": "import math\ndef count_Divisors(n) : \n\t''' Write a python function to check whether the count of divisors is even or odd.\n\t>>> count_Divisors(10)\n\t'Even'\n\t>>> count_Divisors(100)\n\t'Odd'\n\t>>> count_Divisors(125)\n\t'Even'\n\t'''"
},
{
"role": "assistant",
... | |
782 | train | Write a python function to find the sum of all odd length subarrays. | [
"assert Odd_Length_Sum([1,2,4]) == 14",
"assert Odd_Length_Sum([1,2,1,2]) == 15",
"assert Odd_Length_Sum([1,7]) == 8"
] | [] | def Odd_Length_Sum(arr):
''' Write a python function to find the sum of all odd length subarrays.
>>> Odd_Length_Sum([1, 2, 4])
14
>>> Odd_Length_Sum([1, 2, 1, 2])
15
>>> Odd_Length_Sum([1, 7])
8
''' | ```python
def Odd_Length_Sum(arr):
''' Write a python function to find the sum of all odd length subarrays.
>>> Odd_Length_Sum([1, 2, 4])
14
>>> Odd_Length_Sum([1, 2, 1, 2])
15
>>> Odd_Length_Sum([1, 7])
8
'''
Sum = 0
l = len(arr)
for i in range(l):
Sum += ((((i + 1) ... | [
{
"role": "user",
"content": "def Odd_Length_Sum(arr):\n\t''' Write a python function to find the sum of all odd length subarrays.\n\t>>> Odd_Length_Sum([1, 2, 4])\n\t14\n\t>>> Odd_Length_Sum([1, 2, 1, 2])\n\t15\n\t>>> Odd_Length_Sum([1, 7])\n\t8\n\t'''"
},
{
"role": "assistant",
"content": "```... | |
783 | train | Write a function to convert rgb color to hsv color. | [
"assert rgb_to_hsv(255, 255, 255)==(0, 0.0, 100.0)",
"assert rgb_to_hsv(0, 215, 0)==(120.0, 100.0, 84.31372549019608)",
"assert rgb_to_hsv(10, 215, 110)==(149.26829268292684, 95.34883720930233, 84.31372549019608)"
] | [] | def rgb_to_hsv(r, g, b):
''' Write a function to convert rgb color to hsv color.
>>> rgb_to_hsv(255, 255, 255)
(0, 0.0, 100.0)
>>> rgb_to_hsv(0, 215, 0)
(120.0, 100.0, 84.31372549019608)
>>> rgb_to_hsv(10, 215, 110)
(149.26829268292684, 95.34883720930233, 84.31372549019608)
''' | ```python
def rgb_to_hsv(r, g, b):
''' Write a function to convert rgb color to hsv color.
>>> rgb_to_hsv(255, 255, 255)
(0, 0.0, 100.0)
>>> rgb_to_hsv(0, 215, 0)
(120.0, 100.0, 84.31372549019608)
>>> rgb_to_hsv(10, 215, 110)
(149.26829268292684, 95.34883720930233, 84.31372549019608)
'''... | [
{
"role": "user",
"content": "def rgb_to_hsv(r, g, b):\n\t''' Write a function to convert rgb color to hsv color.\n\t>>> rgb_to_hsv(255, 255, 255)\n\t(0, 0.0, 100.0)\n\t>>> rgb_to_hsv(0, 215, 0)\n\t(120.0, 100.0, 84.31372549019608)\n\t>>> rgb_to_hsv(10, 215, 110)\n\t(149.26829268292684, 95.34883720930233, 8... | |
784 | train | Write a function to find the product of first even and odd number of a given list. | [
"assert mul_even_odd([1,3,5,7,4,1,6,8])==4",
"assert mul_even_odd([1,2,3,4,5,6,7,8,9,10])==2",
"assert mul_even_odd([1,5,7,9,10])==10"
] | [] | def mul_even_odd(list1):
''' Write a function to find the product of first even and odd number of a given list.
>>> mul_even_odd([1, 3, 5, 7, 4, 1, 6, 8])
4
>>> mul_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
2
>>> mul_even_odd([1, 5, 7, 9, 10])
10
''' | ```python
def mul_even_odd(list1):
''' Write a function to find the product of first even and odd number of a given list.
>>> mul_even_odd([1, 3, 5, 7, 4, 1, 6, 8])
4
>>> mul_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
2
>>> mul_even_odd([1, 5, 7, 9, 10])
10
'''
first_even = next((el f... | [
{
"role": "user",
"content": "def mul_even_odd(list1):\n\t''' Write a function to find the product of first even and odd number of a given list.\n\t>>> mul_even_odd([1, 3, 5, 7, 4, 1, 6, 8])\n\t4\n\t>>> mul_even_odd([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n\t2\n\t>>> mul_even_odd([1, 5, 7, 9, 10])\n\t10\n\t'''"
... | |
785 | train | Write a function to convert tuple string to integer tuple. | [
"assert tuple_str_int(\"(7, 8, 9)\") == (7, 8, 9)",
"assert tuple_str_int(\"(1, 2, 3)\") == (1, 2, 3)",
"assert tuple_str_int(\"(4, 5, 6)\") == (4, 5, 6)"
] | [] | def tuple_str_int(test_str):
''' Write a function to convert tuple string to integer tuple.
>>> tuple_str_int('(7, 8, 9)')
(7, 8, 9)
>>> tuple_str_int('(1, 2, 3)')
(1, 2, 3)
>>> tuple_str_int('(4, 5, 6)')
(4, 5, 6)
''' | ```python
def tuple_str_int(test_str):
''' Write a function to convert tuple string to integer tuple.
>>> tuple_str_int('(7, 8, 9)')
(7, 8, 9)
>>> tuple_str_int('(1, 2, 3)')
(1, 2, 3)
>>> tuple_str_int('(4, 5, 6)')
(4, 5, 6)
'''
res = tuple(int(num) for num in test_str.replace('(', '').replace(')', ''... | [
{
"role": "user",
"content": "def tuple_str_int(test_str):\n\t''' Write a function to convert tuple string to integer tuple.\n\t>>> tuple_str_int('(7, 8, 9)')\n\t(7, 8, 9)\n\t>>> tuple_str_int('(1, 2, 3)')\n\t(1, 2, 3)\n\t>>> tuple_str_int('(4, 5, 6)')\n\t(4, 5, 6)\n\t'''"
},
{
"role": "assistant",
... | |
786 | train | Write a function to locate the right insertion point for a specified value in sorted order. | [
"assert right_insertion([1,2,4,5],6)==4",
"assert right_insertion([1,2,4,5],3)==2",
"assert right_insertion([1,2,4,5],7)==4"
] | [] | import bisect
def right_insertion(a, x):
''' Write a function to locate the right insertion point for a specified value in sorted order.
>>> right_insertion([1, 2, 4, 5], 6)
4
>>> right_insertion([1, 2, 4, 5], 3)
2
>>> right_insertion([1, 2, 4, 5], 7)
4
''' | ```python
import bisect
def right_insertion(a, x):
''' Write a function to locate the right insertion point for a specified value in sorted order.
>>> right_insertion([1, 2, 4, 5], 6)
4
>>> right_insertion([1, 2, 4, 5], 3)
2
>>> right_insertion([1, 2, 4, 5], 7)
4
'''
i = bisect.bisec... | [
{
"role": "user",
"content": "import bisect\ndef right_insertion(a, x):\n\t''' Write a function to locate the right insertion point for a specified value in sorted order.\n\t>>> right_insertion([1, 2, 4, 5], 6)\n\t4\n\t>>> right_insertion([1, 2, 4, 5], 3)\n\t2\n\t>>> right_insertion([1, 2, 4, 5], 7)\n\t4\n\... | |
787 | train | Write a function that matches a string that has an a followed by three 'b'. | [
"assert text_match_three(\"ac\")==('Not matched!')",
"assert text_match_three(\"dc\")==('Not matched!')",
"assert text_match_three(\"abbbba\")==('Found a match!')"
] | [] | import re
def text_match_three(text):
''' Write a function that matches a string that has an a followed by three 'b'.
>>> text_match_three('ac')
'Not matched!'
>>> text_match_three('dc')
'Not matched!'
>>> text_match_three('abbbba')
'Found a match!'
''' | ```python
import re
def text_match_three(text):
''' Write a function that matches a string that has an a followed by three 'b'.
>>> text_match_three('ac')
'Not matched!'
>>> text_match_three('dc')
'Not matched!'
>>> text_match_three('abbbba')
'Found a match!'
... | [
{
"role": "user",
"content": "import re\ndef text_match_three(text):\n\t''' Write a function that matches a string that has an a followed by three 'b'.\n\t>>> text_match_three('ac')\n\t'Not matched!'\n\t>>> text_match_three('dc')\n\t'Not matched!'\n\t>>> text_match_three('abbbba')\n\t'Found a match!'\n\t'''... | |
788 | train | Write a function to create a new tuple from the given string and list. | [
"assert new_tuple([\"WEB\", \"is\"], \"best\") == ('WEB', 'is', 'best')",
"assert new_tuple([\"We\", \"are\"], \"Developers\") == ('We', 'are', 'Developers')",
"assert new_tuple([\"Part\", \"is\"], \"Wrong\") == ('Part', 'is', 'Wrong')"
] | [] | def new_tuple(test_list, test_str):
''' Write a function to create a new tuple from the given string and list.
>>> new_tuple(['WEB', 'is'], 'best')
('WEB', 'is', 'best')
>>> new_tuple(['We', 'are'], 'Developers')
('We', 'are', 'Developers')
>>> new_tuple(['Part', 'is'], 'Wrong')
('Part', 'is', 'Wrong')
''' | ```python
def new_tuple(test_list, test_str):
''' Write a function to create a new tuple from the given string and list.
>>> new_tuple(['WEB', 'is'], 'best')
('WEB', 'is', 'best')
>>> new_tuple(['We', 'are'], 'Developers')
('We', 'are', 'Developers')
>>> new_tuple(['Part', 'is'], 'Wrong')
('Part', 'is', '... | [
{
"role": "user",
"content": "def new_tuple(test_list, test_str):\n\t''' Write a function to create a new tuple from the given string and list.\n\t>>> new_tuple(['WEB', 'is'], 'best')\n\t('WEB', 'is', 'best')\n\t>>> new_tuple(['We', 'are'], 'Developers')\n\t('We', 'are', 'Developers')\n\t>>> new_tuple(['Par... | |
789 | train | Write a function to calculate the perimeter of a regular polygon. | [
"assert perimeter_polygon(4,20)==80",
"assert perimeter_polygon(10,15)==150",
"assert perimeter_polygon(9,7)==63"
] | [] | from math import tan, pi
def perimeter_polygon(s,l):
''' Write a function to calculate the perimeter of a regular polygon.
>>> perimeter_polygon(4, 20)
80
>>> perimeter_polygon(10, 15)
150
>>> perimeter_polygon(9, 7)
63
''' | ```python
from math import tan, pi
def perimeter_polygon(s,l):
''' Write a function to calculate the perimeter of a regular polygon.
>>> perimeter_polygon(4, 20)
80
>>> perimeter_polygon(10, 15)
150
>>> perimeter_polygon(9, 7)
63
'''
perimeter = s*l
return perimeter
``` | [
{
"role": "user",
"content": "from math import tan, pi\ndef perimeter_polygon(s,l):\n\t''' Write a function to calculate the perimeter of a regular polygon.\n\t>>> perimeter_polygon(4, 20)\n\t80\n\t>>> perimeter_polygon(10, 15)\n\t150\n\t>>> perimeter_polygon(9, 7)\n\t63\n\t'''"
},
{
"role": "assist... | |
790 | train | Write a python function to check whether every even index contains even numbers of a given list. | [
"assert even_position([3,2,1]) == False",
"assert even_position([1,2,3]) == False",
"assert even_position([2,1,4]) == True"
] | [] | def even_position(nums):
''' Write a python function to check whether every even index contains even numbers of a given list.
>>> even_position([3, 2, 1])
False
>>> even_position([1, 2, 3])
False
>>> even_position([2, 1, 4])
True
''' | ```python
def even_position(nums):
''' Write a python function to check whether every even index contains even numbers of a given list.
>>> even_position([3, 2, 1])
False
>>> even_position([1, 2, 3])
False
>>> even_position([2, 1, 4])
True
'''
return all(nums[i]%2==i%2 for i in range(len(nums)))
``` | [
{
"role": "user",
"content": "def even_position(nums):\n\t''' Write a python function to check whether every even index contains even numbers of a given list.\n\t>>> even_position([3, 2, 1])\n\tFalse\n\t>>> even_position([1, 2, 3])\n\tFalse\n\t>>> even_position([2, 1, 4])\n\tTrue\n\t'''"
},
{
"role"... | |
791 | train | Write a function to remove the nested record from the given tuple. | [
"assert remove_nested((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10)",
"assert remove_nested((2, 6, 8, (5, 7), 11)) == (2, 6, 8, 11)",
"assert remove_nested((3, 7, 9, (6, 8), 12)) == (3, 7, 9, 12)"
] | [] | def remove_nested(test_tup):
''' Write a function to remove the nested record from the given tuple.
>>> remove_nested((1, 5, 7, (4, 6), 10))
(1, 5, 7, 10)
>>> remove_nested((2, 6, 8, (5, 7), 11))
(2, 6, 8, 11)
>>> remove_nested((3, 7, 9, (6, 8), 12))
(3, 7, 9, 12)
''' | ```python
def remove_nested(test_tup):
''' Write a function to remove the nested record from the given tuple.
>>> remove_nested((1, 5, 7, (4, 6), 10))
(1, 5, 7, 10)
>>> remove_nested((2, 6, 8, (5, 7), 11))
(2, 6, 8, 11)
>>> remove_nested((3, 7, 9, (6, 8), 12))
(3, 7, 9, 12)
'''
res = tuple()
for cou... | [
{
"role": "user",
"content": "def remove_nested(test_tup):\n\t''' Write a function to remove the nested record from the given tuple.\n\t>>> remove_nested((1, 5, 7, (4, 6), 10))\n\t(1, 5, 7, 10)\n\t>>> remove_nested((2, 6, 8, (5, 7), 11))\n\t(2, 6, 8, 11)\n\t>>> remove_nested((3, 7, 9, (6, 8), 12))\n\t(3, 7,... | |
792 | train | Write a python function to count the number of lists in a given number of lists. | [
"assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4",
"assert count_list([[1,2],[2,3],[4,5]]) == 3",
"assert count_list([[1,0],[2,0]]) == 2"
] | [] | def count_list(input_list):
''' Write a python function to count the number of lists in a given number of lists.
>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])
4
>>> count_list([[1, 2], [2, 3], [4, 5]])
3
>>> count_list([[1, 0], [2, 0]])
2
''' | ```python
def count_list(input_list):
''' Write a python function to count the number of lists in a given number of lists.
>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])
4
>>> count_list([[1, 2], [2, 3], [4, 5]])
3
>>> count_list([[1, 0], [2, 0]])
2
'''
return len(input_lis... | [
{
"role": "user",
"content": "def count_list(input_list): \n\t''' Write a python function to count the number of lists in a given number of lists.\n\t>>> count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]])\n\t4\n\t>>> count_list([[1, 2], [2, 3], [4, 5]])\n\t3\n\t>>> count_list([[1, 0], [2, 0]])\n\t2\n\t'''"... | |
793 | train | Write a python function to find the last position of an element in a sorted array. | [
"assert last([1,2,3],1,3) == 0",
"assert last([1,1,1,2,3,4],1,6) == 2",
"assert last([2,3,2,3,6,8,9],3,8) == 3"
] | [] | def last(arr,x,n):
''' Write a python function to find the last position of an element in a sorted array.
>>> last([1, 2, 3], 1, 3)
0
>>> last([1, 1, 1, 2, 3, 4], 1, 6)
2
>>> last([2, 3, 2, 3, 6, 8, 9], 3, 8)
3
''' | ```python
def last(arr,x,n):
''' Write a python function to find the last position of an element in a sorted array.
>>> last([1, 2, 3], 1, 3)
0
>>> last([1, 1, 1, 2, 3, 4], 1, 6)
2
>>> last([2, 3, 2, 3, 6, 8, 9], 3, 8)
3
'''
low = 0
high = n - 1
res = -1
while (low <= h... | [
{
"role": "user",
"content": "def last(arr,x,n):\n\t''' Write a python function to find the last position of an element in a sorted array.\n\t>>> last([1, 2, 3], 1, 3)\n\t0\n\t>>> last([1, 1, 1, 2, 3, 4], 1, 6)\n\t2\n\t>>> last([2, 3, 2, 3, 6, 8, 9], 3, 8)\n\t3\n\t'''"
},
{
"role": "assistant",
... | |
794 | train | Write a function that matches a string that has an 'a' followed by anything, ending in 'b'. | [
"assert text_starta_endb(\"aabbbb\")==('Found a match!')",
"assert text_starta_endb(\"aabAbbbc\")==('Not matched!')",
"assert text_starta_endb(\"accddbbjjj\")==('Not matched!')"
] | [] | import re
def text_starta_endb(text):
''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.
>>> text_starta_endb('aabbbb')
'Found a match!'
>>> text_starta_endb('aabAbbbc')
'Not matched!'
>>> text_starta_endb('accddbbjjj')
'Not matched!'
''' | ```python
import re
def text_starta_endb(text):
''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.
>>> text_starta_endb('aabbbb')
'Found a match!'
>>> text_starta_endb('aabAbbbc')
'Not matched!'
>>> text_starta_endb('accddbbjjj... | [
{
"role": "user",
"content": "import re\ndef text_starta_endb(text):\n\t''' Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.\n\t>>> text_starta_endb('aabbbb')\n\t'Found a match!'\n\t>>> text_starta_endb('aabAbbbc')\n\t'Not matched!'\n\t>>> text_starta_endb('accddbb... | |
795 | train | Write a function to find the n - cheap price items from a given dataset using heap queue algorithm. | [
"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-1', 'price': 101.1}]",
"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2)==[{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}]",
"ass... | [] | import heapq
def cheap_items(items,n):
''' Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.
>>> cheap_items([{'name': 'Item-1', 'price': 101.1}, {'name': 'Item-2', 'price': 555.22}], 1)
[{'name': 'Item-1', 'price': 101.1}]
>>> cheap_items([{'name': 'Item-1', 'price... | ```python
import heapq
def cheap_items(items,n):
''' Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.
>>> cheap_items([{'name': 'Item-1', 'price': 101.1}, {'name': 'Item-2', 'price': 555.22}], 1)
[{'name': 'Item-1', 'price': 101.1}]
>>> cheap_items([{'name': 'I... | [
{
"role": "user",
"content": "import heapq\ndef cheap_items(items,n):\n\t''' Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.\n\t>>> cheap_items([{'name': 'Item-1', 'price': 101.1}, {'name': 'Item-2', 'price': 555.22}], 1)\n\t[{'name': 'Item-1', 'price': 10... | |
796 | train | Write function to find the sum of all items in the given dictionary. | [
"assert return_sum({'a': 100, 'b':200, 'c':300}) == 600",
"assert return_sum({'a': 25, 'b':18, 'c':45}) == 88",
"assert return_sum({'a': 36, 'b':39, 'c':49}) == 124"
] | [] | def return_sum(dict):
''' Write function to find the sum of all items in the given dictionary.
>>> return_sum({'a': 100, 'b': 200, 'c': 300})
600
>>> return_sum({'a': 25, 'b': 18, 'c': 45})
88
>>> return_sum({'a': 36, 'b': 39, 'c': 49})
124
''' | ```python
def return_sum(dict):
''' Write function to find the sum of all items in the given dictionary.
>>> return_sum({'a': 100, 'b': 200, 'c': 300})
600
>>> return_sum({'a': 25, 'b': 18, 'c': 45})
88
>>> return_sum({'a': 36, 'b': 39, 'c': 49})
124
'''
sum = 0
for i in dict.values():
sum = sum... | [
{
"role": "user",
"content": "def return_sum(dict):\n\t''' Write function to find the sum of all items in the given dictionary.\n\t>>> return_sum({'a': 100, 'b': 200, 'c': 300})\n\t600\n\t>>> return_sum({'a': 25, 'b': 18, 'c': 45})\n\t88\n\t>>> return_sum({'a': 36, 'b': 39, 'c': 49})\n\t124\n\t'''"
},
{... | |
797 | train | Write a python function to find the sum of all odd natural numbers within the range l and r. | [
"assert sum_in_Range(2,5) == 8",
"assert sum_in_Range(5,7) == 12",
"assert sum_in_Range(7,13) == 40"
] | [] | def sum_Odd(n):
''' Write a python function to find the sum of all odd natural numbers within the range l and r.
>>> sum_in_Range(2, 5)
8
>>> sum_in_Range(5, 7)
12
>>> sum_in_Range(7, 13)
40
''' | ```python
def sum_Odd(n):
''' Write a python function to find the sum of all odd natural numbers within the range l and r.
>>> sum_in_Range(2, 5)
8
>>> sum_in_Range(5, 7)
12
>>> sum_in_Range(7, 13)
40
'''
terms = (n + 1)//2
sum1 = terms * terms
return sum1
def sum_in_Rang... | [
{
"role": "user",
"content": "def sum_Odd(n): \n\t''' Write a python function to find the sum of all odd natural numbers within the range l and r.\n\t>>> sum_in_Range(2, 5)\n\t8\n\t>>> sum_in_Range(5, 7)\n\t12\n\t>>> sum_in_Range(7, 13)\n\t40\n\t'''"
},
{
"role": "assistant",
"content": "```pyth... | |
798 | train | Write a python function to find the sum of an array. | [
"assert _sum([1, 2, 3]) == 6",
"assert _sum([15, 12, 13, 10]) == 50",
"assert _sum([0, 1, 2]) == 3"
] | [] | def _sum(arr):
''' Write a python function to find the sum of an array.
>>> _sum([1, 2, 3])
6
>>> _sum([15, 12, 13, 10])
50
>>> _sum([0, 1, 2])
3
''' | ```python
def _sum(arr):
''' Write a python function to find the sum of an array.
>>> _sum([1, 2, 3])
6
>>> _sum([15, 12, 13, 10])
50
>>> _sum([0, 1, 2])
3
'''
sum=0
for i in arr:
sum = sum + i
return(sum)
``` | [
{
"role": "user",
"content": "def _sum(arr): \n\t''' Write a python function to find the sum of an array.\n\t>>> _sum([1, 2, 3])\n\t6\n\t>>> _sum([15, 12, 13, 10])\n\t50\n\t>>> _sum([0, 1, 2])\n\t3\n\t'''"
},
{
"role": "assistant",
"content": "```python\ndef _sum(arr): \n ''' Write a python... | |
799 | train | Write a python function to left rotate the bits of a given number. | [
"assert left_Rotate(16,2) == 64",
"assert left_Rotate(10,2) == 40",
"assert left_Rotate(99,3) == 792"
] | [] | INT_BITS = 32
def left_Rotate(n,d):
''' Write a python function to left rotate the bits of a given number.
>>> left_Rotate(16, 2)
64
>>> left_Rotate(10, 2)
40
>>> left_Rotate(99, 3)
792
''' | ```python
INT_BITS = 32
def left_Rotate(n,d):
''' Write a python function to left rotate the bits of a given number.
>>> left_Rotate(16, 2)
64
>>> left_Rotate(10, 2)
40
>>> left_Rotate(99, 3)
792
'''
return (n << d)|(n >> (INT_BITS - d))
``` | [
{
"role": "user",
"content": "INT_BITS = 32\ndef left_Rotate(n,d): \n\t''' Write a python function to left rotate the bits of a given number.\n\t>>> left_Rotate(16, 2)\n\t64\n\t>>> left_Rotate(10, 2)\n\t40\n\t>>> left_Rotate(99, 3)\n\t792\n\t'''"
},
{
"role": "assistant",
"content": "```python... | |
800 | train | Write a function to remove all whitespaces from a string. | [
"assert remove_all_spaces('python program')==('pythonprogram')",
"assert remove_all_spaces('python programming language')==('pythonprogramminglanguage')",
"assert remove_all_spaces('python program')==('pythonprogram')"
] | [] | import re
def remove_all_spaces(text):
''' Write a function to remove all whitespaces from a string.
>>> remove_all_spaces('python program')
'pythonprogram'
>>> remove_all_spaces('python programming language')
'pythonprogramminglanguage'
>>> remove_all_spaces('python program')
'pythonpr... | ```python
import re
def remove_all_spaces(text):
''' Write a function to remove all whitespaces from a string.
>>> remove_all_spaces('python program')
'pythonprogram'
>>> remove_all_spaces('python programming language')
'pythonprogramminglanguage'
>>> remove_all_spaces('python program')
... | [
{
"role": "user",
"content": "import re\ndef remove_all_spaces(text):\n\t''' Write a function to remove all whitespaces from a string.\n\t>>> remove_all_spaces('python program')\n\t'pythonprogram'\n\t>>> remove_all_spaces('python programming language')\n\t'pythonprogramminglanguage'\n\t>>> remove_all_... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.