| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the longest chain which can be formed from the given set of pairs.\n\n Your code should pass these tests:\n\n['assert max_chain_length([Pair(5, 24), Pair(15, 25),Pair(27, 40), Pair(50, 60)], 4) == 3', 'assert max_chain_length([Pair(1, 2), Pair(3, 4),Pair(5, 6), Pair(7, 8)], 4) == 4', 'assert max_chain_length([Pair(19, 10), Pair(11, 12),Pair(13, 14), Pair(15, 16), Pair(31, 54)], 5) == 5']\n[BEGIN]\n", "completion": "class Pair(object): \r\n\tdef __init__(self, a, b): \r\n\t\tself.a = a \r\n\t\tself.b = b \r\ndef max_chain_length(arr, n): \r\n\tmax = 0\r\n\tmcl = [1 for i in range(n)] \r\n\tfor i in range(1, n): \r\n\t\tfor j in range(0, i): \r\n\t\t\tif (arr[i].a > arr[j].b and\r\n\t\t\t\tmcl[i] < mcl[j] + 1): \r\n\t\t\t\tmcl[i] = mcl[j] + 1\r\n\tfor i in range(n): \r\n\t\tif (max < mcl[i]): \r\n\t\t\tmax = mcl[i] \r\n\treturn max\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the first repeated character in a given string.\n\n Your code should pass these tests:\n\n['assert first_repeated_char(\"abcabc\") == \"a\"', 'assert first_repeated_char(\"abc\") == \"None\"', 'assert first_repeated_char(\"123123\") == \"1\"']\n[BEGIN]\n", "completion": "def first_repeated_char(str1):\r\n for index,c in enumerate(str1):\r\n if str1[:index+1].count(c) > 1:\r\n return c \r\n return \"None\"\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to get a lucid number smaller than or equal to n.\n\n Your code should pass these tests:\n\n['assert get_ludic(10) == [1, 2, 3, 5, 7]', 'assert get_ludic(25) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]', 'assert get_ludic(45) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43]']\n[BEGIN]\n", "completion": "def get_ludic(n):\r\n\tludics = []\r\n\tfor i in range(1, n + 1):\r\n\t\tludics.append(i)\r\n\tindex = 1\r\n\twhile(index != len(ludics)):\r\n\t\tfirst_ludic = ludics[index]\r\n\t\tremove_index = index + first_ludic\r\n\t\twhile(remove_index < len(ludics)):\r\n\t\t\tludics.remove(ludics[remove_index])\r\n\t\t\tremove_index = remove_index + first_ludic - 1\r\n\t\tindex += 1\r\n\treturn ludics\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to reverse words in a given string.\n\n Your code should pass these tests:\n\n['assert reverse_words(\"python program\")==(\"program python\")', 'assert reverse_words(\"java language\")==(\"language java\")', 'assert reverse_words(\"indian man\")==(\"man indian\")']\n[BEGIN]\n", "completion": "def reverse_words(s):\r\n return ' '.join(reversed(s.split()))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given integer is a prime number.\n\n Your code should pass these tests:\n\n['assert prime_num(13)==True', 'assert prime_num(7)==True', 'assert prime_num(-1010)==False']\n[BEGIN]\n", "completion": "def prime_num(num):\r\n if num >=1:\r\n for i in range(2, num//2):\r\n if (num % i) == 0:\r\n return False\r\n else:\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert degrees to radians.\n\n Your code should pass these tests:\n\n['assert radian_degree(90)==1.5707963267948966', 'assert radian_degree(60)==1.0471975511965976', 'assert radian_degree(120)==2.0943951023931953']\n[BEGIN]\n", "completion": "import math\r\ndef radian_degree(degree):\r\n radian = degree*(math.pi/180)\r\n return radian\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to search a literals string in a string and also find the location within the original string where the pattern occurs by using regex.\n\n Your code should pass these tests:\n\n[\"assert find_literals('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19)\", \"assert find_literals('Its been a very crazy procedure right', 'crazy') == ('crazy', 16, 21)\", \"assert find_literals('Hardest choices required strongest will', 'will') == ('will', 35, 39)\"]\n[BEGIN]\n", "completion": "import re\r\npattern = 'fox'\r\ntext = 'The quick brown fox jumps over the lazy dog.'\r\ndef find_literals(text, pattern):\r\n match = re.search(pattern, text)\r\n s = match.start()\r\n e = match.end()\r\n return (match.re.pattern, s, e)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find nth bell number.\n\n Your code should pass these tests:\n\n['assert bell_Number(2) == 2', 'assert bell_Number(3) == 5', 'assert bell_Number(4) == 15']\n[BEGIN]\n", "completion": "def bell_Number(n): \r\n bell = [[0 for i in range(n+1)] for j in range(n+1)] \r\n bell[0][0] = 1\r\n for i in range(1, n+1):\r\n bell[i][0] = bell[i-1][i-1]\r\n for j in range(1, i+1): \r\n bell[i][j] = bell[i-1][j-1] + bell[i][j-1] \r\n return bell[n][0] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find minimum possible value for the given periodic function.\n\n Your code should pass these tests:\n\n['assert floor_Min(10,20,30) == 15', 'assert floor_Min(1,2,1) == 0', 'assert floor_Min(11,10,9) == 9']\n[BEGIN]\n", "completion": "def floor_Min(A,B,N):\r\n x = max(B - 1,N)\r\n return (A*x) // B\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to remove the k'th element from a given list.\n\n Your code should pass these tests:\n\n['assert remove_kth_element([1,1,2,3,4,4,5,1],3)==[1, 1, 3, 4, 4, 5, 1]', 'assert remove_kth_element([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4],4)==[0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]', 'assert remove_kth_element([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10],5)==[10,10,15,19, 18, 17, 26, 26, 17, 18, 10]']\n[BEGIN]\n", "completion": "def remove_kth_element(list1, L):\r\n return list1[:L-1] + list1[L:]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum of nth column from the given tuple list.\n\n Your code should pass these tests:\n\n['assert max_of_nth([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 19', 'assert max_of_nth([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 10', 'assert max_of_nth([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 1) == 11']\n[BEGIN]\n", "completion": "def max_of_nth(test_list, N):\r\n res = max([sub[N] for sub in test_list])\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to merge the first and last elements separately in a list of lists.\n\n Your code should pass these tests:\n\n[\"assert merge([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']]\", 'assert merge([[1, 2], [3, 4], [5, 6], [7, 8]]) == [[1, 3, 5, 7], [2, 4, 6, 8]]', \"assert merge([['x', 'y','z' ], ['a', 'b','c'], ['m', 'n','o']]) == [['x', 'a', 'm'], ['y', 'b', 'n'],['z', 'c','o']]\"]\n[BEGIN]\n", "completion": "def merge(lst): \r\n return [list(ele) for ele in list(zip(*lst))] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum value in record list as tuple attribute in the given tuple list.\n\n Your code should pass these tests:\n\n[\"assert maximum_value([('key1', [3, 4, 5]), ('key2', [1, 4, 2]), ('key3', [9, 3])]) == [('key1', 5), ('key2', 4), ('key3', 9)]\", \"assert maximum_value([('key1', [4, 5, 6]), ('key2', [2, 5, 3]), ('key3', [10, 4])]) == [('key1', 6), ('key2', 5), ('key3', 10)]\", \"assert maximum_value([('key1', [5, 6, 7]), ('key2', [3, 6, 4]), ('key3', [11, 5])]) == [('key1', 7), ('key2', 6), ('key3', 11)]\"]\n[BEGIN]\n", "completion": "def maximum_value(test_list):\r\n res = [(key, max(lst)) for key, lst in test_list]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the cumulative sum of all the values that are present in the given tuple list.\n\n Your code should pass these tests:\n\n['assert cummulative_sum([(1, 3), (5, 6, 7), (2, 6)]) == 30', 'assert cummulative_sum([(2, 4), (6, 7, 8), (3, 7)]) == 37', 'assert cummulative_sum([(3, 5), (7, 8, 9), (4, 8)]) == 44']\n[BEGIN]\n", "completion": "def cummulative_sum(test_list):\r\n res = sum(map(sum, test_list))\r\n return (res)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find average value of the numbers in a given tuple of tuples.\n\n Your code should pass these tests:\n\n['assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25]', 'assert average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))== [25.5, -18.0, 3.75]', 'assert average_tuple( ((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 320), (10, 20, 30, 40)))==[305.0, 342.5, 270.0, 232.5]']\n[BEGIN]\n", "completion": "def average_tuple(nums):\r\n result = [sum(x) / len(x) for x in zip(*nums)]\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to perfom the modulo of tuple elements in the given two tuples.\n\n Your code should pass these tests:\n\n['assert tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1)', 'assert tuple_modulo((11, 5, 6, 7), (6, 7, 8, 6)) == (5, 5, 6, 1)', 'assert tuple_modulo((12, 6, 7, 8), (7, 8, 9, 7)) == (5, 6, 7, 1)']\n[BEGIN]\n", "completion": "def tuple_modulo(test_tup1, test_tup2):\r\n res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) \r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.\n\n Your code should pass these tests:\n\n['assert min_Jumps(3,4,11)==3.5', 'assert min_Jumps(3,4,0)==0', 'assert min_Jumps(11,14,11)==1']\n[BEGIN]\n", "completion": "def min_Jumps(a, b, d): \r\n temp = a \r\n a = min(a, b) \r\n b = max(temp, b) \r\n if (d >= b): \r\n return (d + b - 1) / b \r\n if (d == 0): \r\n return 0\r\n if (d == a): \r\n return 1\r\n else:\r\n return 2\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to divide two lists using map and lambda function.\n\n Your code should pass these tests:\n\n['assert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]', 'assert div_list([3,2],[1,4])==[3.0, 0.5]', 'assert div_list([90,120],[50,70])==[1.8, 1.7142857142857142]']\n[BEGIN]\n", "completion": "def div_list(nums1,nums2):\r\n result = map(lambda x, y: x / y, nums1, nums2)\r\n return list(result)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to move all the numbers in it to the given string.\n\n Your code should pass these tests:\n\n[\"assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'\", \"assert move_num('Avengers124Assemble') == 'AvengersAssemble124'\", \"assert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'\"]\n[BEGIN]\n", "completion": "def move_num(test_str):\r\n res = ''\r\n dig = ''\r\n for ele in test_str:\r\n if ele.isdigit():\r\n dig += ele\r\n else:\r\n res += ele\r\n res += dig\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the largest subset where each pair is divisible.\n\n Your code should pass these tests:\n\n['assert largest_subset([ 1, 3, 6, 13, 17, 18 ], 6) == 4', 'assert largest_subset([10, 5, 3, 15, 20], 5) == 3', 'assert largest_subset([18, 1, 3, 6, 13, 17], 6) == 4']\n[BEGIN]\n", "completion": "def largest_subset(a, n):\r\n\tdp = [0 for i in range(n)]\r\n\tdp[n - 1] = 1; \r\n\tfor i in range(n - 2, -1, -1):\r\n\t\tmxm = 0;\r\n\t\tfor j in range(i + 1, n):\r\n\t\t\tif a[j] % a[i] == 0 or a[i] % a[j] == 0:\r\n\t\t\t\tmxm = max(mxm, dp[j])\r\n\t\tdp[i] = 1 + mxm\r\n\treturn max(dp)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to increment the numeric values in the given strings by k.\n\n Your code should pass these tests:\n\n['assert increment_numerics([\"MSM\", \"234\", \"is\", \"98\", \"123\", \"best\", \"4\"] , 6) == [\\'MSM\\', \\'240\\', \\'is\\', \\'104\\', \\'129\\', \\'best\\', \\'10\\']', 'assert increment_numerics([\"Dart\", \"356\", \"is\", \"88\", \"169\", \"Super\", \"6\"] , 12) == [\\'Dart\\', \\'368\\', \\'is\\', \\'100\\', \\'181\\', \\'Super\\', \\'18\\']', 'assert increment_numerics([\"Flutter\", \"451\", \"is\", \"44\", \"96\", \"Magnificent\", \"12\"] , 33) == [\\'Flutter\\', \\'484\\', \\'is\\', \\'77\\', \\'129\\', \\'Magnificent\\', \\'45\\']']\n[BEGIN]\n", "completion": "def increment_numerics(test_list, K):\r\n res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]\r\n return res \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the median of two sorted arrays of same size.\n\n Your code should pass these tests:\n\n['assert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0', 'assert get_median([2, 4, 8, 9], [7, 13, 19, 28], 4) == 8.5', 'assert get_median([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6) == 25.0']\n[BEGIN]\n", "completion": "def get_median(arr1, arr2, n):\r\n i = 0\r\n j = 0\r\n m1 = -1\r\n m2 = -1\r\n count = 0\r\n while count < n + 1:\r\n count += 1\r\n if i == n:\r\n m1 = m2\r\n m2 = arr2[0]\r\n break\r\n elif j == n:\r\n m1 = m2\r\n m2 = arr1[0]\r\n break\r\n if arr1[i] <= arr2[j]:\r\n m1 = m2\r\n m2 = arr1[i]\r\n i += 1\r\n else:\r\n m1 = m2\r\n m2 = arr2[j]\r\n j += 1\r\n return (m1 + m2)/2\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the n-th power of individual elements in a list using lambda function.\n\n Your code should pass these tests:\n\n['assert nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]', 'assert nth_nums([10,20,30],3)==([1000, 8000, 27000])', 'assert nth_nums([12,15],5)==([248832, 759375])']\n[BEGIN]\n", "completion": "def nth_nums(nums,n):\r\n nth_nums = list(map(lambda x: x ** n, nums))\r\n return nth_nums\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to convert the given string to upper case.\n\n Your code should pass these tests:\n\n['assert is_upper(\"person\") ==\"PERSON\"', 'assert is_upper(\"final\") == \"FINAL\"', 'assert is_upper(\"Valid\") == \"VALID\"']\n[BEGIN]\n", "completion": "def is_upper(string):\r\n return (string.upper())\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to interchange first and last elements in a given list.\n\n Your code should pass these tests:\n\n['assert swap_List([1,2,3]) == [3,2,1]', 'assert swap_List([1,2,3,4,4]) == [4,2,3,4,1]', 'assert swap_List([4,5,6]) == [6,5,4]']\n[BEGIN]\n", "completion": "def swap_List(newList): \r\n size = len(newList) \r\n temp = newList[0] \r\n newList[0] = newList[size - 1] \r\n newList[size - 1] = temp \r\n return newList \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the largest triangle that can be inscribed in the semicircle.\n\n Your code should pass these tests:\n\n['assert triangle_area(0) == 0', 'assert triangle_area(-1) == -1', 'assert triangle_area(2) == 4']\n[BEGIN]\n", "completion": "def triangle_area(r) : \r\n if r < 0 : \r\n return -1\r\n return r * r \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the smallest missing number from the given array.\n\n Your code should pass these tests:\n\n['assert find_First_Missing([0,1,2,3],0,3) == 4', 'assert find_First_Missing([0,1,2,6,9],0,4) == 3', 'assert find_First_Missing([2,3,5,8,9],0,4) == 0']\n[BEGIN]\n", "completion": "def find_First_Missing(array,start,end): \r\n if (start > end): \r\n return end + 1\r\n if (start != array[start]): \r\n return start; \r\n mid = int((start + end) / 2) \r\n if (array[mid] == mid): \r\n return find_First_Missing(array,mid+1,end) \r\n return find_First_Missing(array,start,mid) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.\n\n Your code should pass these tests:\n\n['assert replace_spaces(\"My Name is Dawood\") == \\'My%20Name%20is%20Dawood\\'', 'assert replace_spaces(\"I am a Programmer\") == \\'I%20am%20a%20Programmer\\'', 'assert replace_spaces(\"I love Coding\") == \\'I%20love%20Coding\\'']\n[BEGIN]\n", "completion": "MAX=1000;\r\ndef replace_spaces(string):\r\n string=string.strip()\r\n i=len(string)\r\n space_count=string.count(' ')\r\n new_length = i + space_count*2\r\n if new_length > MAX:\r\n return -1\r\n index = new_length-1\r\n string=list(string)\r\n for f in range(i-2, new_length-2):\r\n string.append('0')\r\n for j in range(i-1, 0, -1):\r\n if string[j] == ' ':\r\n string[index] = '0'\r\n string[index-1] = '2'\r\n string[index-2] = '%'\r\n index=index-3\r\n else:\r\n string[index] = string[j]\r\n index -= 1\r\n return ''.join(string)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find even numbers from a mixed list.\n\n Your code should pass these tests:\n\n['assert Split([1,2,3,4,5]) == [2,4]', 'assert Split([4,5,6,7,8,0,1]) == [4,6,8,0]', 'assert Split ([8,12,15,19]) == [8,12]']\n[BEGIN]\n", "completion": "def Split(list): \r\n ev_li = [] \r\n for i in list: \r\n if (i % 2 == 0): \r\n ev_li.append(i) \r\n return ev_li\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract all the adjacent coordinates of the given coordinate tuple.\n\n Your code should pass these tests:\n\n['assert get_coordinates((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]', 'assert get_coordinates((4, 5)) ==[[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]]', 'assert get_coordinates((5, 6)) == [[4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7]]']\n[BEGIN]\n", "completion": "def adjac(ele, sub = []): \r\n if not ele: \r\n yield sub \r\n else: \r\n yield from [idx for j in range(ele[0] - 1, ele[0] + 2) \r\n for idx in adjac(ele[1:], sub + [j])] \r\ndef get_coordinates(test_tup):\r\n res = list(adjac(test_tup))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to replace whitespaces with an underscore and vice versa in a given string by using regex.\n\n Your code should pass these tests:\n\n[\"assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'\", \"assert replace_spaces('The Avengers') == 'The_Avengers'\", \"assert replace_spaces('Fast and Furious') == 'Fast_and_Furious'\"]\n[BEGIN]\n", "completion": "import re\r\ntext = 'Python Exercises'\r\ndef replace_spaces(text):\r\n text =text.replace (\" \", \"_\")\r\n return (text)\r\n text =text.replace (\"_\", \" \")\r\n return (text)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to move all zeroes to the end of the given list.\n\n Your code should pass these tests:\n\n['assert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]', 'assert move_zero([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0]', 'assert move_zero([0,1,0,1,1]) == [1,1,1,0,0]']\n[BEGIN]\n", "completion": "def move_zero(num_list):\r\n a = [0 for i in range(num_list.count(0))]\r\n x = [ i for i in num_list if i != 0]\r\n x.extend(a)\r\n return (x)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of xor of all pairs of numbers in the given array.\n\n Your code should pass these tests:\n\n['assert pair_OR_Sum([5,9,7,6],4) == 47', 'assert pair_OR_Sum([7,3,5],3) == 12', 'assert pair_OR_Sum([7,3],2) == 4']\n[BEGIN]\n", "completion": "def pair_OR_Sum(arr,n) : \r\n ans = 0 \r\n for i in range(0,n) : \r\n for j in range(i + 1,n) : \r\n ans = ans + (arr[i] ^ arr[j]) \r\n return ans \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of fourth power of first n even natural numbers.\n\n Your code should pass these tests:\n\n['assert even_Power_Sum(2) == 272', 'assert even_Power_Sum(3) == 1568', 'assert even_Power_Sum(4) == 5664']\n[BEGIN]\n", "completion": "def even_Power_Sum(n): \r\n sum = 0; \r\n for i in range(1,n + 1): \r\n j = 2*i; \r\n sum = sum + (j*j*j*j); \r\n return sum; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to push all values into a heap and then pop off the smallest values one at a time.\n\n Your code should pass these tests:\n\n['assert heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]', 'assert heap_sort([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]', 'assert heap_sort( [7, 1, 9, 5])==[1,5,7,9]']\n[BEGIN]\n", "completion": "import heapq as hq\r\ndef heap_sort(iterable):\r\n h = []\r\n for value in iterable:\r\n hq.heappush(h, value)\r\n return [hq.heappop(h) for i in range(len(h))]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check if roots of a quadratic equation are reciprocal of each other or not.\n\n Your code should pass these tests:\n\n['assert Check_Solution(2,0,2) == \"Yes\"', 'assert Check_Solution(2,-5,2) == \"Yes\"', 'assert Check_Solution(1,2,3) == \"No\"']\n[BEGIN]\n", "completion": "def Check_Solution(a,b,c): \r\n if (a == c): \r\n return (\"Yes\"); \r\n else: \r\n return (\"No\"); \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given amount has no profit and no loss\n\n Your code should pass these tests:\n\n['assert noprofit_noloss(1500,1200)==False', 'assert noprofit_noloss(100,100)==True', 'assert noprofit_noloss(2000,5000)==False']\n[BEGIN]\n", "completion": "def noprofit_noloss(actual_cost,sale_amount): \r\n if(sale_amount == actual_cost):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate wind chill index.\n\n Your code should pass these tests:\n\n['assert wind_chill(120,35)==40', 'assert wind_chill(40,70)==86', 'assert wind_chill(10,100)==116']\n[BEGIN]\n", "completion": "import math\r\ndef wind_chill(v,t):\r\n windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)\r\n return int(round(windchill, 0))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.\n\n Your code should pass these tests:\n\n[\"assert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16\", 'assert sample_nam([\"php\", \"res\", \"Python\", \"abcd\", \"Java\", \"aaa\"])==10', 'assert sample_nam([\"abcd\", \"Python\", \"abba\", \"aba\"])==6']\n[BEGIN]\n", "completion": "def sample_nam(sample_names):\r\n sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))\r\n return len(''.join(sample_names))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove the parenthesis area in a string.\n\n Your code should pass these tests:\n\n['assert remove_parenthesis([\"python (chrome)\"])==(\"python\")', 'assert remove_parenthesis([\"string(.abc)\"])==(\"string\")', 'assert remove_parenthesis([\"alpha(num)\"])==(\"alpha\")']\n[BEGIN]\n", "completion": "import re\r\ndef remove_parenthesis(items):\r\n for item in items:\r\n return (re.sub(r\" ?\\([^)]+\\)\", \"\", item))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the nth nonagonal number.\n\n Your code should pass these tests:\n\n['assert is_nonagonal(10) == 325', 'assert is_nonagonal(15) == 750', 'assert is_nonagonal(18) == 1089']\n[BEGIN]\n", "completion": "def is_nonagonal(n): \r\n\treturn int(n * (7 * n - 5) / 2) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove similar rows from the given tuple matrix.\n\n Your code should pass these tests:\n\n['assert remove_similar_row([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]] ) == {((2, 2), (4, 6)), ((3, 2), (4, 5))}', 'assert remove_similar_row([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]] ) == {((4, 3), (5, 6)), ((3, 3), (5, 7))}', 'assert remove_similar_row([[(6, 7), (5, 4)], [(4, 4), (6, 8)], [(5, 4), (6, 7)]] ) =={((4, 4), (6, 8)), ((5, 4), (6, 7))}']\n[BEGIN]\n", "completion": "def remove_similar_row(test_list):\r\n res = set(sorted([tuple(sorted(set(sub))) for sub in test_list]))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a word containing 'z', not at the start or end of the word.\n\n Your code should pass these tests:\n\n['assert text_match_wordz_middle(\"pythonzabc.\")==(\\'Found a match!\\')', 'assert text_match_wordz_middle(\"xyzabc.\")==(\\'Found a match!\\')', 'assert text_match_wordz_middle(\" lang .\")==(\\'Not matched!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_match_wordz_middle(text):\r\n patterns = '\\Bz\\B'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to reverse an array upto a given position.\n\n Your code should pass these tests:\n\n['assert reverse_Array_Upto_K([1, 2, 3, 4, 5, 6],4) == [4, 3, 2, 1, 5, 6]', 'assert reverse_Array_Upto_K([4, 5, 6, 7], 2) == [5, 4, 6, 7]', 'assert reverse_Array_Upto_K([9, 8, 7, 6, 5],3) == [7, 8, 9, 6, 5]']\n[BEGIN]\n", "completion": "def reverse_Array_Upto_K(input, k): \r\n return (input[k-1::-1] + input[k:]) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the product of it\u2019s kth index in the given tuples.\n\n Your code should pass these tests:\n\n['assert find_k_product([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 665', 'assert find_k_product([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 280', 'assert find_k_product([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0) == 210']\n[BEGIN]\n", "completion": "def get_product(val) : \r\n\tres = 1\r\n\tfor ele in val: \r\n\t\tres *= ele \r\n\treturn res \r\ndef find_k_product(test_list, K):\r\n res = get_product([sub[K] for sub in test_list])\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count number of cubes of size k in a cube of size n.\n\n Your code should pass these tests:\n\n['assert No_of_cubes(2,1) == 8', 'assert No_of_cubes(5,2) == 64', 'assert No_of_cubes(1,1) == 1']\n[BEGIN]\n", "completion": "def No_of_cubes(N,K):\r\n No = 0\r\n No = (N - K + 1)\r\n No = pow(No, 3)\r\n return No\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to split a string at uppercase letters.\n\n Your code should pass these tests:\n\n['assert split_upperstring(\"PythonProgramLanguage\")==[\\'Python\\',\\'Program\\',\\'Language\\']', 'assert split_upperstring(\"PythonProgram\")==[\\'Python\\',\\'Program\\']', 'assert split_upperstring(\"ProgrammingLanguage\")==[\\'Programming\\',\\'Language\\']']\n[BEGIN]\n", "completion": "import re\r\ndef split_upperstring(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list.\n\n Your code should pass these tests:\n\n['assert exchange_elements([0,1,2,3,4,5])==[1, 0, 3, 2, 5, 4] ', 'assert exchange_elements([5,6,7,8,9,10])==[6,5,8,7,10,9] ', 'assert exchange_elements([25,35,45,55,75,95])==[35,25,55,45,95,75] ']\n[BEGIN]\n", "completion": "from itertools import zip_longest, chain, tee\r\ndef exchange_elements(lst):\r\n lst1, lst2 = tee(iter(lst), 2)\r\n return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to calculate the sum of the numbers in a list between the indices of a specified range.\n\n Your code should pass these tests:\n\n['assert sum_Range_list([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12],8,10) == 29', 'assert sum_Range_list([1,2,3,4,5],1,2) == 5', 'assert sum_Range_list([1,0,1,2,5,6],4,5) == 11']\n[BEGIN]\n", "completion": "def sum_Range_list(nums, m, n): \r\n sum_range = 0 \r\n for i in range(m, n+1, 1): \r\n sum_range += nums[i] \r\n return sum_range \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given two arrays are equal or not.\n\n Your code should pass these tests:\n\n['assert are_Equal([1,2,3],[3,2,1],3,3) == True', 'assert are_Equal([1,1,1],[2,2,2],3,3) == False', 'assert are_Equal([8,9],[4,5,6],2,3) == False']\n[BEGIN]\n", "completion": "def are_Equal(arr1,arr2,n,m):\r\n if (n != m):\r\n return False\r\n arr1.sort()\r\n arr2.sort()\r\n for i in range(0,n - 1):\r\n if (arr1[i] != arr2[i]):\r\n return False\r\n return True\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if one tuple is a subset of another tuple.\n\n Your code should pass these tests:\n\n['assert check_subset((10, 4, 5, 6), (5, 10)) == True', 'assert check_subset((1, 2, 3, 4), (5, 6)) == False', 'assert check_subset((7, 8, 9, 10), (10, 8)) == True']\n[BEGIN]\n", "completion": "def check_subset(test_tup1, test_tup2):\r\n res = set(test_tup2).issubset(test_tup1)\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.\n\n Your code should pass these tests:\n\n[\"assert matrix_to_list([[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]]) == '[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]'\", \"assert matrix_to_list([[(5, 6), (8, 9)], [(11, 14), (19, 18)], [(1, 5), (11, 2)]]) == '[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]'\", \"assert matrix_to_list([[(6, 7), (9, 10)], [(12, 15), (20, 21)], [(23, 7), (15, 8)]]) == '[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]'\"]\n[BEGIN]\n", "completion": "def matrix_to_list(test_list):\r\n temp = [ele for sub in test_list for ele in sub]\r\n res = list(zip(*temp))\r\n return (str(res))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to group a sequence of key-value pairs into a dictionary of lists using collections module.\n\n Your code should pass these tests:\n\n[\"assert grouping_dictionary([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])== ({'yellow': [1, 3], 'blue': [2, 4], 'red': [1]})\", \"assert grouping_dictionary([('yellow', 10), ('blue', 20), ('yellow', 30), ('blue', 40), ('red', 10)])== ({'yellow': [10, 30], 'blue': [20, 40], 'red': [10]})\", \"assert grouping_dictionary([('yellow', 15), ('blue', 25), ('yellow', 35), ('blue', 45), ('red', 15)])== ({'yellow': [15, 35], 'blue': [25, 45], 'red': [15]})\"]\n[BEGIN]\n", "completion": "from collections import defaultdict\r\ndef grouping_dictionary(l):\r\n d = defaultdict(list)\r\n for k, v in l:\r\n d[k].append(v)\r\n return d\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the perimeter of a rectangle.\n\n Your code should pass these tests:\n\n['assert rectangle_perimeter(10,20)==60', 'assert rectangle_perimeter(10,5)==30', 'assert rectangle_perimeter(4,2)==12']\n[BEGIN]\n", "completion": "def rectangle_perimeter(l,b):\r\n perimeter=2*(l+b)\r\n return perimeter\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of fifth power of n natural numbers.\n\n Your code should pass these tests:\n\n['assert fifth_Power_Sum(2) == 33', 'assert fifth_Power_Sum(4) == 1300', 'assert fifth_Power_Sum(3) == 276']\n[BEGIN]\n", "completion": "def fifth_Power_Sum(n) : \r\n sm = 0 \r\n for i in range(1,n+1) : \r\n sm = sm + (i*i*i*i*i) \r\n return sm \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the minimum sum of absolute differences of two arrays.\n\n Your code should pass these tests:\n\n['assert find_Min_Sum([3,2,1],[2,1,3],3) == 0', 'assert find_Min_Sum([1,2,3],[4,5,6],3) == 9', 'assert find_Min_Sum([4,1,8,7],[2,3,6,5],4) == 6']\n[BEGIN]\n", "completion": "def find_Min_Sum(a,b,n): \r\n a.sort() \r\n b.sort() \r\n sum = 0 \r\n for i in range(n): \r\n sum = sum + abs(a[i] - b[i]) \r\n return sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the first digit in factorial of a given number.\n\n Your code should pass these tests:\n\n['assert first_Digit(5) == 1', 'assert first_Digit(10) == 3', 'assert first_Digit(7) == 5']\n[BEGIN]\n", "completion": "import math \r\ndef first_Digit(n) : \r\n fact = 1\r\n for i in range(2,n + 1) : \r\n fact = fact * i \r\n while (fact % 10 == 0) : \r\n fact = int(fact / 10) \r\n while (fact >= 10) : \r\n fact = int(fact / 10) \r\n return math.floor(fact) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the item with maximum occurrences in a given list.\n\n Your code should pass these tests:\n\n['assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2])==2', 'assert max_occurrences([1, 3,5, 7,1, 3,13, 15, 17,5, 7,9,1, 11])==1', 'assert max_occurrences([1, 2, 3,2, 4, 5,1, 1, 1])==1']\n[BEGIN]\n", "completion": "def max_occurrences(list1):\r\n max_val = 0\r\n result = list1[0] \r\n for i in list1:\r\n occu = list1.count(i)\r\n if occu > max_val:\r\n max_val = occu\r\n result = i \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to print duplicants from a list of integers.\n\n Your code should pass these tests:\n\n['assert Repeat([10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]) == [20, 30, -20, 60]', 'assert Repeat([-1, 1, -1, 8]) == [-1]', 'assert Repeat([1, 2, 3, 1, 2,]) == [1, 2]']\n[BEGIN]\n", "completion": "def Repeat(x): \r\n _size = len(x) \r\n repeated = [] \r\n for i in range(_size): \r\n k = i + 1\r\n for j in range(k, _size): \r\n if x[i] == x[j] and x[i] not in repeated: \r\n repeated.append(x[i]) \r\n return repeated \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to choose points from two ranges such that no point lies in both the ranges.\n\n Your code should pass these tests:\n\n['assert find_Points(5,10,1,5) == (1,10)', 'assert find_Points(3,5,7,9) == (3,9)', 'assert find_Points(1,5,2,8) == (1,8)']\n[BEGIN]\n", "completion": "def find_Points(l1,r1,l2,r2): \r\n x = min(l1,l2) if (l1 != l2) else -1\r\n y = max(r1,r2) if (r1 != r2) else -1\r\n return (x,y)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum sum that can be formed which has no three consecutive elements present.\n\n Your code should pass these tests:\n\n['assert max_sum_of_three_consecutive([100, 1000, 100, 1000, 1], 5) == 2101', 'assert max_sum_of_three_consecutive([3000, 2000, 1000, 3, 10], 5) == 5013', 'assert max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27']\n[BEGIN]\n", "completion": "def max_sum_of_three_consecutive(arr, n): \r\n\tsum = [0 for k in range(n)] \r\n\tif n >= 1: \r\n\t\tsum[0] = arr[0] \r\n\tif n >= 2: \r\n\t\tsum[1] = arr[0] + arr[1] \r\n\tif n > 2: \r\n\t\tsum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) \r\n\tfor i in range(3, n): \r\n\t\tsum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3]) \r\n\treturn sum[n-1]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort a list in a dictionary.\n\n Your code should pass these tests:\n\n[\"assert sorted_dict({'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]})=={'n1': [1, 2, 3], 'n2': [1, 2, 5], 'n3': [2, 3, 4]}\", \"assert sorted_dict({'n1': [25,37,41], 'n2': [41,54,63], 'n3': [29,38,93]})=={'n1': [25, 37, 41], 'n2': [41, 54, 63], 'n3': [29, 38, 93]}\", \"assert sorted_dict({'n1': [58,44,56], 'n2': [91,34,58], 'n3': [100,200,300]})=={'n1': [44, 56, 58], 'n2': [34, 58, 91], 'n3': [100, 200, 300]}\"]\n[BEGIN]\n", "completion": "def sorted_dict(dict1):\r\n sorted_dict = {x: sorted(y) for x, y in dict1.items()}\r\n return sorted_dict\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the largest possible value of k such that k modulo x is y.\n\n Your code should pass these tests:\n\n['assert find_max_val(15, 10, 5) == 15', 'assert find_max_val(187, 10, 5) == 185', 'assert find_max_val(16, 11, 1) == 12']\n[BEGIN]\n", "completion": "import sys \r\ndef find_max_val(n, x, y): \r\n\tans = -sys.maxsize \r\n\tfor k in range(n + 1): \r\n\t\tif (k % x == y): \r\n\t\t\tans = max(ans, k) \r\n\treturn (ans if (ans >= 0 and\r\n\t\t\t\t\tans <= n) else -1) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the average of even numbers till a given even number.\n\n Your code should pass these tests:\n\n['assert average_Even(2) == 2', 'assert average_Even(4) == 3', 'assert average_Even(100) == 51']\n[BEGIN]\n", "completion": "def average_Even(n) : \r\n if (n% 2!= 0) : \r\n return (\"Invalid Input\") \r\n return -1 \r\n sm = 0\r\n count = 0\r\n while (n>= 2) : \r\n count = count+1\r\n sm = sm+n \r\n n = n-2\r\n return sm // count \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to shift first element to the end of given list.\n\n Your code should pass these tests:\n\n['assert move_last([1,2,3,4]) == [2,3,4,1]', 'assert move_last([2,3,4,1,5,0]) == [3,4,1,5,0,2]', 'assert move_last([5,4,3,2,1]) == [4,3,2,1,5]']\n[BEGIN]\n", "completion": "def move_last(num_list):\r\n a = [num_list[0] for i in range(num_list.count(num_list[0]))]\r\n x = [ i for i in num_list if i != num_list[0]]\r\n x.extend(a)\r\n return (x)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count occurrence of a character in a string.\n\n Your code should pass these tests:\n\n['assert count_char(\"Python\",\\'o\\')==1', 'assert count_char(\"little\",\\'t\\')==2', 'assert count_char(\"assert\",\\'s\\')==2']\n[BEGIN]\n", "completion": "def count_char(string,char):\r\n count = 0\r\n for i in range(len(string)):\r\n if(string[i] == char):\r\n count = count + 1\r\n return count\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count number of vowels in the string.\n\n Your code should pass these tests:\n\n[\"assert Check_Vow('corner','AaEeIiOoUu') == 2\", \"assert Check_Vow('valid','AaEeIiOoUu') == 2\", \"assert Check_Vow('true','AaEeIiOoUu') ==2\"]\n[BEGIN]\n", "completion": "def Check_Vow(string, vowels): \r\n final = [each for each in string if each in vowels] \r\n return(len(final)) \r\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to replace multiple occurence of character by single.\n\n Your code should pass these tests:\n\n[\"assert replace('peep','e') == 'pep'\", \"assert replace('Greek','e') == 'Grek'\", \"assert replace('Moon','o') == 'Mon'\"]\n[BEGIN]\n", "completion": "import re \r\ndef replace(string, char): \r\n pattern = char + '{2,}'\r\n string = re.sub(pattern, char, string) \r\n return string \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given ip address is valid or not using regex.\n\n Your code should pass these tests:\n\n['assert check_IP(\"192.168.0.1\") == \\'Valid IP address\\'', 'assert check_IP(\"110.234.52.124\") == \\'Valid IP address\\'', 'assert check_IP(\"366.1.2.2\") == \\'Invalid IP address\\'']\n[BEGIN]\n", "completion": "import re \r\nregex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'''\r\ndef check_IP(Ip): \r\n\tif(re.search(regex, Ip)): \r\n\t\treturn (\"Valid IP address\") \r\n\telse: \r\n\t\treturn (\"Invalid IP address\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether a sequence of numbers has a decreasing trend or not.\n\n Your code should pass these tests:\n\n['assert decreasing_trend([-4,-3,-2,-1]) == True', 'assert decreasing_trend([1,2,3]) == True', 'assert decreasing_trend([3,2,1]) == False']\n[BEGIN]\n", "completion": "def decreasing_trend(nums):\r\n if (sorted(nums)== nums):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to set the right most unset bit.\n\n Your code should pass these tests:\n\n['assert set_Right_most_Unset_Bit(21) == 23', 'assert set_Right_most_Unset_Bit(11) == 15', 'assert set_Right_most_Unset_Bit(15) == 15']\n[BEGIN]\n", "completion": "import math \r\ndef get_Pos_Of_Right_most_Set_Bit(n): \r\n return int(math.log2(n&-n)+1) \r\ndef set_Right_most_Unset_Bit(n): \r\n if (n == 0): \r\n return 1\r\n if ((n & (n + 1)) == 0): \r\n return n \r\n pos = get_Pos_Of_Right_most_Set_Bit(~n) \r\n return ((1 << (pos - 1)) | n) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find maximum of three numbers.\n\n Your code should pass these tests:\n\n['assert max_of_three(10,20,30)==30', 'assert max_of_three(55,47,39)==55', 'assert max_of_three(10,49,30)==49']\n[BEGIN]\n", "completion": "def max_of_three(num1,num2,num3): \r\n if (num1 >= num2) and (num1 >= num3):\r\n lnum = num1\r\n elif (num2 >= num1) and (num2 >= num3):\r\n lnum = num2\r\n else:\r\n lnum = num3\r\n return lnum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to convert a list of multiple integers into a single integer.\n\n Your code should pass these tests:\n\n['assert convert([1,2,3]) == 123', 'assert convert([4,5,6]) == 456', 'assert convert([7,8,9]) == 789']\n[BEGIN]\n", "completion": "def convert(list): \r\n s = [str(i) for i in list] \r\n res = int(\"\".join(s)) \r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove duplicate words from a given string using collections module.\n\n Your code should pass these tests:\n\n['assert remove_duplicate(\"Python Exercises Practice Solution Exercises\")==(\"Python Exercises Practice Solution\")', 'assert remove_duplicate(\"Python Exercises Practice Solution Python\")==(\"Python Exercises Practice Solution\")', 'assert remove_duplicate(\"Python Exercises Practice Solution Practice\")==(\"Python Exercises Practice Solution\")']\n[BEGIN]\n", "completion": "from collections import OrderedDict\r\ndef remove_duplicate(string):\r\n result = ' '.join(OrderedDict((w,w) for w in string.split()).keys())\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to add two integers. however, if the sum is between the given range it will return 20.\n\n Your code should pass these tests:\n\n['assert sum_nums(2,10,11,20)==20', 'assert sum_nums(15,17,1,10)==32', 'assert sum_nums(10,15,5,30)==20']\n[BEGIN]\n", "completion": "def sum_nums(x, y,m,n):\r\n sum_nums= x + y\r\n if sum_nums in range(m, n):\r\n return 20\r\n else:\r\n return sum_nums\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove everything except alphanumeric characters from the given string by using regex.\n\n Your code should pass these tests:\n\n[\"assert remove_extra_char('**//Google Android// - 12. ') == 'GoogleAndroid12'\", \"assert remove_extra_char('****//Google Flutter//*** - 36. ') == 'GoogleFlutter36'\", \"assert remove_extra_char('**//Google Firebase// - 478. ') == 'GoogleFirebase478'\"]\n[BEGIN]\n", "completion": "import re\r\ndef remove_extra_char(text1):\r\n pattern = re.compile('[\\W_]+')\r\n return (pattern.sub('', text1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the triangle is valid or not.\n\n Your code should pass these tests:\n\n['assert validity_triangle(60,50,90)==False', 'assert validity_triangle(45,75,60)==True', 'assert validity_triangle(30,50,100)==True']\n[BEGIN]\n", "completion": "def validity_triangle(a,b,c):\r\n total = a + b + c\r\n if total == 180:\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to remove spaces from a given string.\n\n Your code should pass these tests:\n\n['assert remove_spaces(\"a b c\") == \"abc\"', 'assert remove_spaces(\"1 2 3\") == \"123\"', 'assert remove_spaces(\" b c\") == \"bc\"']\n[BEGIN]\n", "completion": "def remove_spaces(str1):\r\n str1 = str1.replace(' ','')\r\n return str1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to access dictionary key\u2019s element by index.\n\n Your code should pass these tests:\n\n[\"assert access_key({'physics': 80, 'math': 90, 'chemistry': 86},0)== 'physics'\", \"assert access_key({'python':10, 'java': 20, 'C++':30},2)== 'C++'\", \"assert access_key({'program':15,'computer':45},1)== 'computer'\"]\n[BEGIN]\n", "completion": "def access_key(ditionary,key):\r\n return list(ditionary)[key]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether a sequence of numbers has an increasing trend or not.\n\n Your code should pass these tests:\n\n['assert increasing_trend([1,2,3,4]) == True', 'assert increasing_trend([4,3,2,1]) == False', 'assert increasing_trend([0,1,4,9]) == True']\n[BEGIN]\n", "completion": "def increasing_trend(nums):\r\n if (sorted(nums)== nums):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the smallest prime divisor of a number.\n\n Your code should pass these tests:\n\n['assert smallest_Divisor(10) == 2', 'assert smallest_Divisor(25) == 5', 'assert smallest_Divisor(31) == 31']\n[BEGIN]\n", "completion": "def smallest_Divisor(n): \r\n if (n % 2 == 0): \r\n return 2; \r\n i = 3; \r\n while (i*i <= n): \r\n if (n % i == 0): \r\n return i; \r\n i += 2; \r\n return n; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to multiply two lists using map and lambda function.\n\n Your code should pass these tests:\n\n['assert mul_list([1, 2, 3],[4,5,6])==[4,10,18]', 'assert mul_list([1,2],[3,4])==[3,8]', 'assert mul_list([90,120],[50,70])==[4500,8400]']\n[BEGIN]\n", "completion": "def mul_list(nums1,nums2):\r\n result = map(lambda x, y: x * y, nums1, nums2)\r\n return list(result)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given number can be represented by sum of two squares or not.\n\n Your code should pass these tests:\n\n['assert sum_Square(25) == True', 'assert sum_Square(24) == False', 'assert sum_Square(17) == True']\n[BEGIN]\n", "completion": "def sum_Square(n) : \r\n i = 1 \r\n while i*i <= n : \r\n j = 1\r\n while (j*j <= n) : \r\n if (i*i+j*j == n) : \r\n return True\r\n j = j+1\r\n i = i+1 \r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count occurences of a character in a repeated string.\n\n Your code should pass these tests:\n\n['assert count_Char(\"abcac\",\\'a\\') == 4', 'assert count_Char(\"abca\",\\'c\\') == 2', 'assert count_Char(\"aba\",\\'a\\') == 7']\n[BEGIN]\n", "completion": "def count_Char(str,x): \r\n count = 0\r\n for i in range(len(str)): \r\n if (str[i] == x) : \r\n count += 1\r\n n = 10\r\n repititions = n // len(str) \r\n count = count * repititions \r\n l = n % len(str) \r\n for i in range(l): \r\n if (str[i] == x): \r\n count += 1\r\n return count \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find sum of prime numbers between 1 to n.\n\n Your code should pass these tests:\n\n['assert sum_Of_Primes(10) == 17', 'assert sum_Of_Primes(20) == 77', 'assert sum_Of_Primes(5) == 10']\n[BEGIN]\n", "completion": "def sum_Of_Primes(n): \r\n prime = [True] * (n + 1) \r\n p = 2\r\n while p * p <= n: \r\n if prime[p] == True: \r\n i = p * 2\r\n while i <= n: \r\n prime[i] = False\r\n i += p \r\n p += 1 \r\n sum = 0\r\n for i in range (2,n + 1): \r\n if(prime[i]): \r\n sum += i \r\n return sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the frequency of each element in the given list.\n\n Your code should pass these tests:\n\n[\"assert freq_element((4, 5, 4, 5, 6, 6, 5, 5, 4) ) == '{4: 3, 5: 4, 6: 2}'\", \"assert freq_element((7, 8, 8, 9, 4, 7, 6, 5, 4) ) == '{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}'\", \"assert freq_element((1, 4, 3, 1, 4, 5, 2, 6, 2, 7) ) == '{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}'\"]\n[BEGIN]\n", "completion": "from collections import defaultdict \r\ndef freq_element(test_tup):\r\n res = defaultdict(int)\r\n for ele in test_tup:\r\n res[ele] += 1\r\n return (str(dict(res))) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the greatest common divisor (gcd) of two integers by using recursion.\n\n Your code should pass these tests:\n\n['assert recur_gcd(12,14) == 2', 'assert recur_gcd(13,17) == 1', 'assert recur_gcd(9, 3) == 3']\n[BEGIN]\n", "completion": "def recur_gcd(a, b):\r\n\tlow = min(a, b)\r\n\thigh = max(a, b)\r\n\tif low == 0:\r\n\t\treturn high\r\n\telif low == 1:\r\n\t\treturn 1\r\n\telse:\r\n\t\treturn recur_gcd(low, high%low)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to get the length of a complex number.\n\n Your code should pass these tests:\n\n['assert len_complex(3,4)==5.0', 'assert len_complex(9,10)==13.45362404707371', 'assert len_complex(7,9)==11.40175425099138']\n[BEGIN]\n", "completion": "import cmath\r\ndef len_complex(a,b):\r\n cn=complex(a,b)\r\n length=abs(cn)\r\n return length\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\n## write a function to find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block\n\n Your code should pass these tests:\n\n['assert min_jumps([1, 3, 6, 1, 0, 9], 6) == 3', 'assert min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11) == 3', 'assert min_jumps([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11) == 10']\n[BEGIN]\n", "completion": "def min_jumps(arr, n):\r\n\tjumps = [0 for i in range(n)]\r\n\tif (n == 0) or (arr[0] == 0):\r\n\t\treturn float('inf')\r\n\tjumps[0] = 0\r\n\tfor i in range(1, n):\r\n\t\tjumps[i] = float('inf')\r\n\t\tfor j in range(i):\r\n\t\t\tif (i <= j + arr[j]) and (jumps[j] != float('inf')):\r\n\t\t\t\tjumps[i] = min(jumps[i], jumps[j] + 1)\r\n\t\t\t\tbreak\r\n\treturn jumps[n-1]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to multiply consecutive numbers of a given list.\n\n Your code should pass these tests:\n\n['assert mul_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])==[1, 3, 12, 16, 20, 30, 42]', 'assert mul_consecutive_nums([4, 5, 8, 9, 6, 10])==[20, 40, 72, 54, 60]', 'assert mul_consecutive_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 6, 12, 20, 30, 42, 56, 72, 90]']\n[BEGIN]\n", "completion": "def mul_consecutive_nums(nums):\r\n result = [b*a for a, b in zip(nums[:-1], nums[1:])]\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to group the 1st elements on the basis of 2nd elements in the given tuple list.\n\n Your code should pass these tests:\n\n['assert group_element([(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)]) == {5: [6, 2], 7: [2, 8, 3], 8: [9]}', 'assert group_element([(7, 6), (3, 8), (3, 6), (9, 8), (10, 9), (4, 8)]) == {6: [7, 3], 8: [3, 9, 4], 9: [10]}', 'assert group_element([(8, 7), (4, 9), (4, 7), (10, 9), (11, 10), (5, 9)]) == {7: [8, 4], 9: [4, 10, 5], 10: [11]}']\n[BEGIN]\n", "completion": "from itertools import groupby \r\ndef group_element(test_list):\r\n res = dict()\r\n for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]):\r\n res[key] = [ele[0] for ele in val] \r\n return (res)\r\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the last two digits in factorial of a given number.\n\n Your code should pass these tests:\n\n['assert last_Two_Digits(7) == 40', 'assert last_Two_Digits(5) == 20', 'assert last_Two_Digits(2) == 2']\n[BEGIN]\n", "completion": "def last_Two_Digits(N): \r\n if (N >= 10): \r\n return\r\n fac = 1\r\n for i in range(1,N + 1): \r\n fac = (fac * i) % 100\r\n return (fac) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove multiple spaces in a string by using regex.\n\n Your code should pass these tests:\n\n[\"assert remove_multiple_spaces('Google Assistant') == 'Google Assistant'\", \"assert remove_multiple_spaces('Quad Core') == 'Quad Core'\", \"assert remove_multiple_spaces('ChromeCast Built-in') == 'ChromeCast Built-in'\"]\n[BEGIN]\n", "completion": "import re\r\ndef remove_multiple_spaces(text1):\r\n return (re.sub(' +',' ',text1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract unique values from the given dictionary values.\n\n Your code should pass these tests:\n\n[\"assert extract_unique({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]} ) == [1, 2, 5, 6, 7, 8, 10, 11, 12]\", \"assert extract_unique({'Built' : [7, 1, 9, 4],'for' : [11, 21, 36, 14, 9],'ISP' : [4, 1, 21, 39, 47],'TV' : [1, 32, 38]} ) == [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47]\", \"assert extract_unique({'F' : [11, 13, 14, 17],'A' : [12, 11, 15, 18],'N' : [19, 21, 15, 36],'G' : [37, 36, 35]}) == [11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37]\"]\n[BEGIN]\n", "completion": "def extract_unique(test_dict):\r\n res = list(sorted({ele for val in test_dict.values() for ele in val}))\r\n return res\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.\n\n Your code should pass these tests:\n\n['assert check_greater((10, 4, 5), (13, 5, 18)) == True', 'assert check_greater((1, 2, 3), (2, 1, 4)) == False', 'assert check_greater((4, 5, 6), (5, 6, 7)) == True']\n[BEGIN]\n", "completion": "def check_greater(test_tup1, test_tup2):\r\n res = all(x < y for x, y in zip(test_tup1, test_tup2))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to zip two given lists of lists.\n\n Your code should pass these tests:\n\n['assert zip_list([[1, 3], [5, 7], [9, 11]] ,[[2, 4], [6, 8], [10, 12, 14]] )==[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]', 'assert zip_list([[1, 2], [3, 4], [5, 6]] ,[[7, 8], [9, 10], [11, 12]] )==[[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]', \"assert zip_list([['a','b'],['c','d']] , [['e','f'],['g','h']] )==[['a','b','e','f'],['c','d','g','h']]\"]\n[BEGIN]\n", "completion": "def zip_list(list1,list2): \r\n result = list(map(list.__add__, list1, list2)) \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find number of even elements in the given list using lambda function.\n\n Your code should pass these tests:\n\n['assert count_even([1, 2, 3, 5, 7, 8, 9, 10])==3', 'assert count_even([10,15,14,13,-18,12,-20])==5', 'assert count_even([1, 2, 4, 8, 9])==3']\n[BEGIN]\n", "completion": "def count_even(array_nums):\r\n count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))\r\n return count_even\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys.\n\n Your code should pass these tests:\n\n['assert sort_dict_item({(5, 6) : 3, (2, 3) : 9, (8, 4): 10, (6, 4): 12} ) == {(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}', 'assert sort_dict_item({(6, 7) : 4, (3, 4) : 10, (9, 5): 11, (7, 5): 13} ) == {(3, 4): 10, (7, 5): 13, (6, 7): 4, (9, 5): 11}', 'assert sort_dict_item({(7, 8) : 5, (4, 5) : 11, (10, 6): 12, (8, 6): 14} ) == {(4, 5): 11, (8, 6): 14, (7, 8): 5, (10, 6): 12}']\n[BEGIN]\n", "completion": "def sort_dict_item(test_dict):\r\n res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])}\r\n return (res) \r\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the minimum number of swaps required to convert one binary string to another.\n\n Your code should pass these tests:\n\n['assert min_Swaps(\"1101\",\"1110\") == 1', 'assert min_Swaps(\"1111\",\"0100\") == \"Not Possible\"', 'assert min_Swaps(\"1110000\",\"0001101\") == 3']\n[BEGIN]\n", "completion": "def min_Swaps(str1,str2) : \r\n count = 0\r\n for i in range(len(str1)) : \r\n if str1[i] != str2[i] : \r\n count += 1\r\n if count % 2 == 0 : \r\n return (count // 2) \r\n else : \r\n return (\"Not Possible\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the number of elements in a list which are within a specific range.\n\n Your code should pass these tests:\n\n['assert count_range_in_list([10,20,30,40,40,40,70,80,99],40,100)==6', \"assert count_range_in_list(['a','b','c','d','e','f'],'a','e')==5\", 'assert count_range_in_list([7,8,9,15,17,19,45],15,20)==3']\n[BEGIN]\n", "completion": "def count_range_in_list(li, min, max):\r\n\tctr = 0\r\n\tfor x in li:\r\n\t\tif min <= x <= max:\r\n\t\t\tctr += 1\r\n\treturn ctr\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the equilibrium index of the given array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def equilibrium_index(arr):\r\n total_sum = sum(arr)\r\n left_sum=0\r\n for i, num in enumerate(arr):\r\n total_sum -= num\r\n if left_sum == total_sum:\r\n return i\r\n left_sum += num\r\n return -1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the minimum number of elements that should be removed such that amax-amin<=k.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def find_ind(key, i, n, \r\n\t\t\tk, arr):\r\n\tind = -1\r\n\tstart = i + 1\r\n\tend = n - 1;\r\n\twhile (start < end):\r\n\t\tmid = int(start +\r\n\t\t\t\t(end - start) / 2)\r\n\t\tif (arr[mid] - key <= k):\r\n\t\t\tind = mid\r\n\t\t\tstart = mid + 1\r\n\t\telse:\r\n\t\t\tend = mid\r\n\treturn ind\r\ndef removals(arr, n, k):\r\n\tans = n - 1\r\n\tarr.sort()\r\n\tfor i in range(0, n):\r\n\t\tj = find_ind(arr[i], i, \r\n\t\t\t\t\tn, k, arr)\r\n\t\tif (j != -1):\r\n\t\t\tans = min(ans, n -\r\n\t\t\t\t\t\t(j - i + 1))\r\n\treturn ans\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given key is present in the dictionary or not.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def is_key_present(d,x):\r\n if x in d:\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the harmonic sum of n-1.\n\n Your code should pass these tests:\n\n['assert harmonic_sum(10)==2.9289682539682538', 'assert harmonic_sum(4)==2.083333333333333', 'assert harmonic_sum(7)==2.5928571428571425 ']\n[BEGIN]\n", "completion": "def harmonic_sum(n):\r\n if n < 2:\r\n return 1\r\n else:\r\n return 1 / n + (harmonic_sum(n - 1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort a list of lists by length and value.\n\n Your code should pass these tests:\n\n['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\",\"HTML\"]])==[[\\'DBMS\\'], [\\'python\\'], [\\'SQL\\', \\'HTML\\'], [\\'java\\', \\'C\\', \\'C++\\']]']\n[BEGIN]\n", "completion": "def sort_sublists(list1):\r\n list1.sort() \r\n list1.sort(key=len)\r\n return list1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find whether an array is subset of another array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def is_subset(arr1, m, arr2, n): \r\n\thashset = set() \r\n\tfor i in range(0, m): \r\n\t\thashset.add(arr1[i]) \r\n\tfor i in range(0, n): \r\n\t\tif arr2[i] in hashset: \r\n\t\t\tcontinue\r\n\t\telse: \r\n\t\t\treturn False\r\n\treturn True\t\t\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the total set bits from 1 to n.\n\n Your code should pass these tests:\n\n['assert count_Set_Bits(16) == 33', 'assert count_Set_Bits(2) == 2', 'assert count_Set_Bits(14) == 28']\n[BEGIN]\n", "completion": "def count_Set_Bits(n) : \r\n n += 1; \r\n powerOf2 = 2; \r\n cnt = n // 2; \r\n while (powerOf2 <= n) : \r\n totalPairs = n // powerOf2; \r\n cnt += (totalPairs // 2) * powerOf2; \r\n if (totalPairs & 1) : \r\n cnt += (n % powerOf2) \r\n else : \r\n cnt += 0\r\n powerOf2 <<= 1; \r\n return cnt; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to convert a string to a list.\n\n Your code should pass these tests:\n\n[\"assert Convert('python program') == ['python','program']\", \"assert Convert('Data Analysis') ==['Data','Analysis']\", \"assert Convert('Hadoop Training') == ['Hadoop','Training']\"]\n[BEGIN]\n", "completion": "def Convert(string): \r\n li = list(string.split(\" \")) \r\n return li \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count unique keys for each value present in the tuple.\n\n Your code should pass these tests:\n\n[\"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), (4, 3), (14, 3), (11, 6)] ) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'\"]\n[BEGIN]\n", "completion": "from collections import defaultdict \r\ndef get_unique(test_list):\r\n res = defaultdict(list)\r\n for sub in test_list:\r\n res[sub[1]].append(sub[0])\r\n res = dict(res)\r\n res_dict = dict()\r\n for key in res:\r\n res_dict[key] = len(list(set(res[key])))\r\n return (str(res_dict)) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to access the initial and last data of the given tuple record.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def front_and_rear(test_tup):\r\n res = (test_tup[0], test_tup[-1])\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the product of digits of a number at even and odd places is equal or not.\n\n Your code should pass these tests:\n\n['assert product_Equal(2841) == True', 'assert product_Equal(1234) == False', 'assert product_Equal(1212) == False']\n[BEGIN]\n", "completion": "def product_Equal(n): \r\n if n < 10: \r\n return False\r\n prodOdd = 1; prodEven = 1\r\n while n > 0: \r\n digit = n % 10\r\n prodOdd *= digit \r\n n = n//10\r\n if n == 0: \r\n break; \r\n digit = n % 10\r\n prodEven *= digit \r\n n = n//10\r\n if prodOdd == prodEven: \r\n return True\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove duplicates from a list of lists.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "import itertools\r\ndef remove_duplicate(list1):\r\n list.sort(list1)\r\n remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1))\r\n return remove_duplicate\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given tuple contains all valid values or not.\n\n Your code should pass these tests:\n\n['assert check_valid((True, True, True, True) ) == True', 'assert check_valid((True, False, True, True) ) == False', 'assert check_valid((True, True, True, True) ) == True']\n[BEGIN]\n", "completion": "def check_valid(test_tup):\r\n res = not any(map(lambda ele: not ele, test_tup))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of distinct power of prime factor of given number.\n\n Your code should pass these tests:\n\n['assert count_Fac(24) == 3', 'assert count_Fac(12) == 2', 'assert count_Fac(4) == 1']\n[BEGIN]\n", "completion": "def count_Fac(n): \r\n m = n \r\n count = 0\r\n i = 2\r\n while((i * i) <= m): \r\n total = 0\r\n while (n % i == 0): \r\n n /= i \r\n total += 1 \r\n temp = 0\r\n j = 1\r\n while((temp + j) <= total): \r\n temp += j \r\n count += 1\r\n j += 1 \r\n i += 1\r\n if (n != 1): \r\n count += 1 \r\n return count \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert the given string of integers into a tuple.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def str_to_tuple(test_str):\r\n res = tuple(map(int, test_str.split(', ')))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the perimeter of a rombus.\n\n Your code should pass these tests:\n\n['assert rombus_perimeter(10)==40', 'assert rombus_perimeter(5)==20', 'assert rombus_perimeter(4)==16']\n[BEGIN]\n", "completion": "def rombus_perimeter(a):\r\n perimeter=4*a\r\n return perimeter\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the standard deviation.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "import math\r\nimport sys\r\ndef sd_calc(data):\r\n n = len(data)\r\n if n <= 1:\r\n return 0.0\r\n mean, sd = avg_calc(data), 0.0\r\n for el in data:\r\n sd += (float(el) - mean)**2\r\n sd = math.sqrt(sd / float(n-1))\r\n return sd\r\ndef avg_calc(ls):\r\n n, mean = len(ls), 0.0\r\n if n <= 1:\r\n return ls[0]\r\n for el in ls:\r\n mean = mean + float(el)\r\n mean = mean / float(n)\r\n return mean\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to create a list taking alternate elements from another given list.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def alternate_elements(list1):\r\n result=[]\r\n for item in list1[::2]:\r\n result.append(item)\r\n return result \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an a followed by zero or more b's.\n\n Your code should pass these tests:\n\n['assert text_match(\"ac\")==(\\'Found a match!\\')', 'assert text_match(\"dc\")==(\\'Not matched!\\')', 'assert text_match(\"abba\")==(\\'Found a match!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_match(text):\r\n patterns = 'ab*?'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to add a dictionary to the tuple.\n\n Your code should pass these tests:\n\n['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\" : 4, \"Okay\" : 5} ) == (8, 9, 10, {\\'POS\\': 3, \\'is\\': 4, \\'Okay\\': 5})']\n[BEGIN]\n", "completion": "def add_dict_to_tuple(test_tup, test_dict):\r\n test_tup = list(test_tup)\r\n test_tup.append(test_dict)\r\n test_tup = tuple(test_tup)\r\n return (test_tup) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.\n\n Your code should pass these tests:\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 ']\n[BEGIN]\n", "completion": "M = 100\r\ndef maxAverageOfPath(cost, N): \r\n\tdp = [[0 for i in range(N + 1)] for j in range(N + 1)] \r\n\tdp[0][0] = cost[0][0] \r\n\tfor i in range(1, N): \r\n\t\tdp[i][0] = dp[i - 1][0] + cost[i][0] \r\n\tfor j in range(1, N): \r\n\t\tdp[0][j] = dp[0][j - 1] + cost[0][j] \r\n\tfor i in range(1, N): \r\n\t\tfor j in range(1, N): \r\n\t\t\tdp[i][j] = max(dp[i - 1][j], \r\n\t\t\t\t\t\tdp[i][j - 1]) + cost[i][j] \r\n\treturn dp[N - 1][N - 1] / (2 * N - 1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to filter the height and width of students which are stored in a dictionary.\n\n Your code should pass these tests:\n\n[\"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 Vega': (6.2, 70),'Kierra Gentry': (6.0, 68)}\", \"assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.7,64)=={'Cierra Vega': (6.2, 70),'Alden Cantrell': (5.9, 65),'Kierra Gentry': (6.0, 68),'Pierre Cox': (5.8, 66)}\"]\n[BEGIN]\n", "completion": "def filter_data(students,h,w):\r\n result = {k: s for k, s in students.items() if s[0] >=h and s[1] >=w}\r\n return result \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the same pair in two given lists using map function.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "from operator import eq\r\ndef count_same_pair(nums1, nums2):\r\n result = sum(map(eq, nums1, nums2))\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the sum of all digits of the base to the specified power.\n\n Your code should pass these tests:\n\n['assert power_base_sum(2,100)==115', 'assert power_base_sum(8,10)==37', 'assert power_base_sum(8,15)==62']\n[BEGIN]\n", "completion": "def power_base_sum(base, power):\r\n return sum([int(i) for i in str(pow(base, power))])\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract values between quotation marks of the given string by using regex.\n\n Your code should pass these tests:\n\n['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\\') == [\\'4k Ultra HD\\', \\'HDR 10\\']']\n[BEGIN]\n", "completion": "import re\r\ndef extract_quotation(text1):\r\n return (re.findall(r'\"(.*?)\"', text1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to multiply the adjacent elements of the given tuple.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def multiply_elements(test_tup):\r\n res = tuple(i * j for i, j in zip(test_tup, test_tup[1:]))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove all characters except letters and numbers using regex\n\n Your code should pass these tests:\n\n['assert remove_char(\"123abcjw:, .@! eiw\") == \\'123abcjweiw\\'', 'assert remove_char(\"Hello1234:, ! Howare33u\") == \\'Hello1234Howare33u\\'', 'assert remove_char(\"Cool543Triks@:, Make@987Trips\") == \\'Cool543TriksMake987Trips\\' ']\n[BEGIN]\n", "completion": "import re \r\ndef remove_char(S):\r\n result = re.sub('[\\W_]+', '', S) \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sum elements in two lists.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def sum_list(lst1,lst2):\r\n res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] \r\n return res_list\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to add two lists using map and lambda function.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def add_list(nums1,nums2):\r\n result = map(lambda x, y: x + y, nums1, nums2)\r\n return list(result)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove consecutive duplicates of a given list.\n\n Your code should pass these tests:\n\n['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', 'c', 'd']\"]\n[BEGIN]\n", "completion": "from itertools import groupby\r\ndef consecutive_duplicates(nums):\r\n return [key for key, group in groupby(nums)] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the lateral surface area of a cone.\n\n Your code should pass these tests:\n\n['assert lateralsurface_cone(5,12)==204.20352248333654', 'assert lateralsurface_cone(10,15)==566.3586699569488', 'assert lateralsurface_cone(19,17)==1521.8090132193388']\n[BEGIN]\n", "completion": "import math\r\ndef lateralsurface_cone(r,h):\r\n l = math.sqrt(r * r + h * h)\r\n LSA = math.pi * r * l\r\n return LSA\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to replace all occurrences of spaces, commas, or dots with a colon.\n\n Your code should pass these tests:\n\n[\"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')\"]\n[BEGIN]\n", "completion": "import re\r\ndef replace_specialchar(text):\r\n return (re.sub(\"[ ,.]\", \":\", text))\r\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the index of the first occurrence of a given number in a sorted array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def find_first_occurrence(A, x):\r\n (left, right) = (0, len(A) - 1)\r\n result = -1\r\n while left <= right:\r\n mid = (left + right) // 2\r\n if x == A[mid]:\r\n result = mid\r\n right = mid - 1\r\n elif x < A[mid]:\r\n right = mid - 1\r\n else:\r\n left = mid + 1\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find sum of products of all possible subarrays.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def sum_Of_Subarray_Prod(arr,n):\r\n ans = 0\r\n res = 0\r\n i = n - 1\r\n while (i >= 0):\r\n incr = arr[i]*(1 + res)\r\n ans += incr\r\n res = incr\r\n i -= 1\r\n return (ans)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to toggle bits of the number except the first and the last bit.\n\n Your code should pass these tests:\n\n['assert toggle_middle_bits(9) == 15', 'assert toggle_middle_bits(10) == 12', 'assert toggle_middle_bits(11) == 13']\n[BEGIN]\n", "completion": "def set_middle_bits(n): \r\n n |= n >> 1; \r\n n |= n >> 2; \r\n n |= n >> 4; \r\n n |= n >> 8; \r\n n |= n >> 16; \r\n return (n >> 1) ^ 1\r\ndef toggle_middle_bits(n): \r\n if (n == 1): \r\n return 1\r\n return n ^ set_middle_bits(n) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to locate the left insertion point for a specified value in sorted order.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "import bisect\r\ndef left_insertion(a, x):\r\n i = bisect.bisect_left(a, x)\r\n return i\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given string is starting with a vowel or not using regex.\n\n Your code should pass these tests:\n\n['assert check_str(\"annie\") == \\'Valid\\'', 'assert check_str(\"dawood\") == \\'Invalid\\'', 'assert check_str(\"Else\") == \\'Valid\\'']\n[BEGIN]\n", "completion": "import re \r\nregex = '^[aeiouAEIOU][A-Za-z0-9_]*'\r\ndef check_str(string): \r\n\tif(re.search(regex, string)): \r\n\t\treturn (\"Valid\") \r\n\telse: \r\n\t\treturn (\"Invalid\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the geometric sum of n-1.\n\n Your code should pass these tests:\n\n['assert geometric_sum(7) == 1.9921875', 'assert geometric_sum(4) == 1.9375', 'assert geometric_sum(8) == 1.99609375']\n[BEGIN]\n", "completion": "def geometric_sum(n):\r\n if n < 0:\r\n return 0\r\n else:\r\n return 1 / (pow(2, n)) + geometric_sum(n - 1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the index of smallest triangular number with n digits.\n\n Your code should pass these tests:\n\n['assert find_Index(2) == 4', 'assert find_Index(3) == 14', 'assert find_Index(4) == 45']\n[BEGIN]\n", "completion": "import math \r\ndef find_Index(n): \r\n x = math.sqrt(2 * math.pow(10,(n - 1))); \r\n return round(x); \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert the given tuple to a key-value dictionary using adjacent elements.\n\n Your code should pass these tests:\n\n['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}']\n[BEGIN]\n", "completion": "def tuple_to_dict(test_tup):\r\n res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether all the characters are same or not.\n\n Your code should pass these tests:\n\n['assert all_Characters_Same(\"python\") == False', 'assert all_Characters_Same(\"aaa\") == True', 'assert all_Characters_Same(\"data\") == False']\n[BEGIN]\n", "completion": "def all_Characters_Same(s) :\r\n n = len(s)\r\n for i in range(1,n) :\r\n if s[i] != s[0] :\r\n return False\r\n return True\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to caluclate the area of a tetrahedron.\n\n Your code should pass these tests:\n\n['assert area_tetrahedron(3)==15.588457268119894', 'assert area_tetrahedron(20)==692.8203230275509', 'assert area_tetrahedron(10)==173.20508075688772']\n[BEGIN]\n", "completion": "import math\r\ndef area_tetrahedron(side):\r\n area = math.sqrt(3)*(side*side)\r\n return area\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to rotate a given list by specified number of items to the right direction.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def rotate_right(list1,m,n):\r\n result = list1[-(m):]+list1[:-(n)]\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given tuple has any none value or not.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def check_none(test_tup):\r\n res = any(map(lambda ele: ele is None, test_tup))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find numbers within a given range where every number is divisible by every digit it contains.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def divisible_by_digits(startnum, endnum):\r\n return [n for n in range(startnum, endnum+1) \\\r\n if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find area of a sector.\n\n Your code should pass these tests:\n\n['assert sector_area(4,45)==6.285714285714286', 'assert sector_area(9,45)==31.82142857142857', 'assert sector_area(9,360)==None']\n[BEGIN]\n", "completion": "def sector_area(r,a):\r\n pi=22/7\r\n if a >= 360:\r\n return None\r\n sectorarea = (pi*r**2) * (a/360)\r\n return sectorarea\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the longest common subsequence for the given three string sequence.\n\n Your code should pass these tests:\n\n[\"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\"]\n[BEGIN]\n", "completion": "def lcs_of_three(X, Y, Z, m, n, o): \r\n\tL = [[[0 for i in range(o+1)] for j in range(n+1)] \r\n\t\tfor k in range(m+1)] \r\n\tfor i in range(m+1): \r\n\t\tfor j in range(n+1): \r\n\t\t\tfor k in range(o+1): \r\n\t\t\t\tif (i == 0 or j == 0 or k == 0): \r\n\t\t\t\t\tL[i][j][k] = 0\r\n\t\t\t\telif (X[i-1] == Y[j-1] and\r\n\t\t\t\t\tX[i-1] == Z[k-1]): \r\n\t\t\t\t\tL[i][j][k] = L[i-1][j-1][k-1] + 1\r\n\t\t\t\telse: \r\n\t\t\t\t\tL[i][j][k] = max(max(L[i-1][j][k], \r\n\t\t\t\t\tL[i][j-1][k]), \r\n\t\t\t\t\t\t\t\t\tL[i][j][k-1]) \r\n\treturn L[m][n][o]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to put spaces between words starting with capital letters in a given string by using regex.\n\n Your code should pass these tests:\n\n['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\\'']\n[BEGIN]\n", "completion": "import re\r\ndef capital_words_spaces(str1):\r\n return re.sub(r\"(\\w)([A-Z])\", r\"\\1 \\2\", str1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort a given list of strings of numbers numerically.\n\n Your code should pass these tests:\n\n[\"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_numeric_strings(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11'])==[1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17]\"]\n[BEGIN]\n", "completion": "def sort_numeric_strings(nums_str):\r\n result = [int(x) for x in nums_str]\r\n result.sort()\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to add the given tuple to the given list.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def add_tuple(test_list, test_tup):\r\n test_list += test_tup\r\n return (test_list) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given array represents min heap or not.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def check_min_heap(arr, i):\r\n if 2 * i + 2 > len(arr):\r\n return True\r\n left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1)\r\n right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] \r\n and check_min_heap(arr, 2 * i + 2))\r\n return left_child and right_child\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the nth jacobsthal number.\n\n Your code should pass these tests:\n\n['assert jacobsthal_num(5) == 11', 'assert jacobsthal_num(2) == 1', 'assert jacobsthal_num(4) == 5']\n[BEGIN]\n", "completion": "def jacobsthal_num(n): \r\n\tdp = [0] * (n + 1) \r\n\tdp[0] = 0\r\n\tdp[1] = 1\r\n\tfor i in range(2, n+1): \r\n\t\tdp[i] = dp[i - 1] + 2 * dp[i - 2] \r\n\treturn dp[n]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find minimum k records from tuple list.\n\n Your code should pass these tests:\n\n[\"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)], 1) == [('Ayesha', 9)]\"]\n[BEGIN]\n", "completion": "def min_k(test_list, K):\r\n res = sorted(test_list, key = lambda x: x[1])[:K]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find common index elements from three lists.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def extract_index_list(l1, l2, l3):\r\n result = []\r\n for m, n, o in zip(l1, l2, l3):\r\n if (m == n == o):\r\n result.append(m)\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the second smallest number in a list.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def second_smallest(numbers):\r\n if (len(numbers)<2):\r\n return\r\n if ((len(numbers)==2) and (numbers[0] == numbers[1]) ):\r\n return\r\n dup_items = set()\r\n uniq_items = []\r\n for x in numbers:\r\n if x not in dup_items:\r\n uniq_items.append(x)\r\n dup_items.add(x)\r\n uniq_items.sort() \r\n return uniq_items[1] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an a followed by zero or one 'b'.\n\n Your code should pass these tests:\n\n['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!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_match_zero_one(text):\r\n patterns = 'ab?'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the pairs of reverse strings in the given string list.\n\n Your code should pass these tests:\n\n['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\\' ']\n[BEGIN]\n", "completion": "def count_reverse_pairs(test_list):\r\n res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len( \r\n\ttest_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))]) \r\n return str(res)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count number of unique lists within a list.\n\n Your code should pass these tests:\n\n['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([[10, 20, 30, 40], [60, 70, 50, 50], [90, 100, 200]])=={(10, 20, 30, 40): 1, (60, 70, 50, 50): 1, (90, 100, 200): 1}']\n[BEGIN]\n", "completion": "def unique_sublists(list1):\r\n result ={}\r\n for l in list1: \r\n result.setdefault(tuple(l), list()).append(1) \r\n for a, b in result.items(): \r\n result[a] = sum(b)\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check a decimal with a precision of 2.\n\n Your code should pass these tests:\n\n[\"assert is_decimal('123.11')==True\", \"assert is_decimal('e666.86')==False\", \"assert is_decimal('3.124587')==False\"]\n[BEGIN]\n", "completion": "def is_decimal(num):\r\n import re\r\n dnumre = re.compile(r\"\"\"^[0-9]+(\\.[0-9]{1,2})?$\"\"\")\r\n result = dnumre.search(num)\r\n return bool(result)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether an array contains only one distinct element or not.\n\n Your code should pass these tests:\n\n[\"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'\"]\n[BEGIN]\n", "completion": "def unique_Element(arr,n):\r\n s = set(arr)\r\n if (len(s) == 1):\r\n return ('YES')\r\n else:\r\n return ('NO')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to caluclate arc length of an angle.\n\n Your code should pass these tests:\n\n['assert arc_length(9,45)==3.5357142857142856', 'assert arc_length(9,480)==None', 'assert arc_length(5,270)==11.785714285714285']\n[BEGIN]\n", "completion": "def arc_length(d,a):\r\n pi=22/7\r\n if a >= 360:\r\n return None\r\n arclength = (pi*d) * (a/360)\r\n return arclength\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given month number contains 30 days or not.\n\n Your code should pass these tests:\n\n['assert check_monthnumber_number(6)==True', 'assert check_monthnumber_number(2)==False', 'assert check_monthnumber_number(12)==False']\n[BEGIN]\n", "completion": "def check_monthnumber_number(monthnum3):\r\n if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the minimum difference between any two elements in a given array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def find_Min_Diff(arr,n): \r\n arr = sorted(arr) \r\n diff = 10**20 \r\n for i in range(n-1): \r\n if arr[i+1] - arr[i] < diff: \r\n diff = arr[i+1] - arr[i] \r\n return diff \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count numeric values in a given string.\n\n Your code should pass these tests:\n\n[\"assert number_ctr('program2bedone') == 1\", \"assert number_ctr('3wonders') ==1\", \"assert number_ctr('123') == 3\"]\n[BEGIN]\n", "completion": "def number_ctr(str):\r\n number_ctr= 0\r\n for i in range(len(str)):\r\n if str[i] >= '0' and str[i] <= '9': number_ctr += 1 \r\n return number_ctr\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find nth polite number.\n\n Your code should pass these tests:\n\n['assert is_polite(7) == 11', 'assert is_polite(4) == 7', 'assert is_polite(9) == 13']\n[BEGIN]\n", "completion": "import math \r\ndef is_polite(n): \r\n\tn = n + 1\r\n\treturn (int)(n+(math.log((n + math.log(n, 2)), 2))) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to iterate over all pairs of consecutive items in a given list.\n\n Your code should pass these tests:\n\n['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)]']\n[BEGIN]\n", "completion": "def pair_wise(l1):\r\n temp = []\r\n for i in range(len(l1) - 1):\r\n current_element, next_element = l1[i], l1[i + 1]\r\n x = (current_element, next_element)\r\n temp.append(x)\r\n return temp\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of pairs whose sum is equal to \u2018sum\u2019.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def get_Pairs_Count(arr,n,sum):\r\n count = 0 \r\n for i in range(0,n):\r\n for j in range(i + 1,n):\r\n if arr[i] + arr[j] == sum:\r\n count += 1\r\n return count\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check for odd parity of a given number.\n\n Your code should pass these tests:\n\n['assert check_Odd_Parity(13) == True', 'assert check_Odd_Parity(21) == True', 'assert check_Odd_Parity(18) == False']\n[BEGIN]\n", "completion": "def check_Odd_Parity(x): \r\n parity = 0\r\n while (x != 0): \r\n x = x & (x - 1) \r\n parity += 1\r\n if (parity % 2 == 1): \r\n return True\r\n else: \r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to get the difference between two lists.\n\n Your code should pass these tests:\n\n['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]']\n[BEGIN]\n", "completion": "def Diff(li1,li2):\r\n return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1))))\r\n \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of fourth power of first n odd natural numbers.\n\n Your code should pass these tests:\n\n['assert odd_Num_Sum(2) == 82', 'assert odd_Num_Sum(3) == 707', 'assert odd_Num_Sum(4) == 3108']\n[BEGIN]\n", "completion": "def odd_Num_Sum(n) : \r\n j = 0\r\n sm = 0\r\n for i in range(1,n + 1) : \r\n j = (2*i-1) \r\n sm = sm + (j*j*j*j) \r\n return sm \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given expression is balanced or not.\n\n Your code should pass these tests:\n\n['assert check_expression(\"{()}[{}]\") == True', 'assert check_expression(\"{()}[{]\") == False', 'assert check_expression(\"{()}[{}][]({})\") == True']\n[BEGIN]\n", "completion": "from collections import deque\r\ndef check_expression(exp):\r\n if len(exp) & 1:\r\n return False\r\n stack = deque()\r\n for ch in exp:\r\n if ch == '(' or ch == '{' or ch == '[':\r\n stack.append(ch)\r\n if ch == ')' or ch == '}' or ch == ']':\r\n if not stack:\r\n return False\r\n top = stack.pop()\r\n if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')):\r\n return False\r\n return not stack\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove all the words with k length in the given string.\n\n Your code should pass these tests:\n\n[\"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'\"]\n[BEGIN]\n", "completion": "def remove_length(test_str, K):\r\n temp = test_str.split()\r\n res = [ele for ele in temp if len(ele) != K]\r\n res = ' '.join(res)\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the occurrence and position of the substrings within a string.\n\n Your code should pass these tests:\n\n[\"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)\"]\n[BEGIN]\n", "completion": "import re\r\ndef occurance_substring(text,pattern):\r\n for match in re.finditer(pattern, text):\r\n s = match.start()\r\n e = match.end()\r\n return (text[s:e], s, e)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the string is a valid email address or not using regex.\n\n Your code should pass these tests:\n\n['assert check_email(\"ankitrai326@gmail.com\") == \\'Valid Email\\'', 'assert check_email(\"my.ownsite@ourearth.org\") == \\'Valid Email\\'', 'assert check_email(\"ankitaoie326.com\") == \\'Invalid Email\\'']\n[BEGIN]\n", "completion": "import re \r\nregex = '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'\r\ndef check_email(email): \r\n\tif(re.search(regex,email)): \r\n\t\treturn (\"Valid Email\") \r\n\telse: \r\n\t\treturn (\"Invalid Email\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether every odd index contains odd numbers of a given list.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def odd_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count those characters which have vowels as their neighbors in the given string.\n\n Your code should pass these tests:\n\n[\"assert count_vowels('bestinstareels') == 7\", \"assert count_vowels('partofthejourneyistheend') == 12\", \"assert count_vowels('amazonprime') == 5\"]\n[BEGIN]\n", "completion": "def count_vowels(test_str):\r\n res = 0\r\n vow_list = ['a', 'e', 'i', 'o', 'u']\r\n for idx in range(1, len(test_str) - 1):\r\n if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list):\r\n res += 1\r\n if test_str[0] not in vow_list and test_str[1] in vow_list:\r\n res += 1\r\n if test_str[-1] not in vow_list and test_str[-2] in vow_list:\r\n res += 1\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of non-repeated elements in a given array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def find_Sum(arr,n): \r\n arr.sort() \r\n sum = arr[0] \r\n for i in range(0,n-1): \r\n if (arr[i] != arr[i+1]): \r\n sum = sum + arr[i+1] \r\n return sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to pack consecutive duplicates of a given list elements into sublists.\n\n Your code should pass these tests:\n\n['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]]', \"assert pack_consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==[['a', 'a'], ['b'], ['c'], ['d', 'd']]\"]\n[BEGIN]\n", "completion": "from itertools import groupby\r\ndef pack_consecutive_duplicates(list1):\r\n return [list(group) for key, group in groupby(list1)]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the number of unique lists within a list.\n\n Your code should pass these tests:\n\n['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, 2], [3, 4], [4, 5], [6, 7]])=={(1, 2): 1, (3, 4): 1, (4, 5): 1, (6, 7): 1}']\n[BEGIN]\n", "completion": "def unique_sublists(list1):\r\n result ={}\r\n for l in list1: \r\n result.setdefault(tuple(l), list()).append(1) \r\n for a, b in result.items(): \r\n result[a] = sum(b)\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the combinations of sums with tuples in the given tuple list.\n\n Your code should pass these tests:\n\n['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)]) == [(12, 15), (11, 9), (12, 18), (15, 12), (16, 21), (15, 15)]']\n[BEGIN]\n", "completion": "from itertools import combinations \r\ndef find_combinations(test_list):\r\n res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the count of divisors is even or odd.\n\n Your code should pass these tests:\n\n['assert count_Divisors(10) == \"Even\"', 'assert count_Divisors(100) == \"Odd\"', 'assert count_Divisors(125) == \"Even\"']\n[BEGIN]\n", "completion": "import math \r\ndef count_Divisors(n) : \r\n count = 0\r\n for i in range(1, (int)(math.sqrt(n)) + 2) : \r\n if (n % i == 0) : \r\n if( n // i == i) : \r\n count = count + 1\r\n else : \r\n count = count + 2\r\n if (count % 2 == 0) : \r\n return (\"Even\") \r\n else : \r\n return (\"Odd\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of all odd length subarrays.\n\n Your code should pass these tests:\n\n['assert Odd_Length_Sum([1,2,4]) == 14', 'assert Odd_Length_Sum([1,2,1,2]) == 15', 'assert Odd_Length_Sum([1,7]) == 8']\n[BEGIN]\n", "completion": "def Odd_Length_Sum(arr):\r\n Sum = 0\r\n l = len(arr)\r\n for i in range(l):\r\n Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i])\r\n return Sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert rgb color to hsv color.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def rgb_to_hsv(r, g, b):\r\n r, g, b = r/255.0, g/255.0, b/255.0\r\n mx = max(r, g, b)\r\n mn = min(r, g, b)\r\n df = mx-mn\r\n if mx == mn:\r\n h = 0\r\n elif mx == r:\r\n h = (60 * ((g-b)/df) + 360) % 360\r\n elif mx == g:\r\n h = (60 * ((b-r)/df) + 120) % 360\r\n elif mx == b:\r\n h = (60 * ((r-g)/df) + 240) % 360\r\n if mx == 0:\r\n s = 0\r\n else:\r\n s = (df/mx)*100\r\n v = mx*100\r\n return h, s, v\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the product of first even and odd number of a given list.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def mul_even_odd(list1):\r\n first_even = next((el for el in list1 if el%2==0),-1)\r\n first_odd = next((el for el in list1 if el%2!=0),-1)\r\n return (first_even*first_odd)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert tuple string to integer tuple.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def tuple_str_int(test_str):\r\n res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', '))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to locate the right insertion point for a specified value in sorted order.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "import bisect\r\ndef right_insertion(a, x):\r\n i = bisect.bisect_right(a, x)\r\n return i\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an a followed by three 'b'.\n\n Your code should pass these tests:\n\n['assert text_match_three(\"ac\")==(\\'Not matched!\\')', 'assert text_match_three(\"dc\")==(\\'Not matched!\\')', 'assert text_match_three(\"abbbba\")==(\\'Found a match!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_match_three(text):\r\n patterns = 'ab{3}?'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to create a new tuple from the given string and list.\n\n Your code should pass these tests:\n\n['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\\')']\n[BEGIN]\n", "completion": "def new_tuple(test_list, test_str):\r\n res = tuple(test_list + [test_str])\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the perimeter of a regular polygon.\n\n Your code should pass these tests:\n\n['assert perimeter_polygon(4,20)==80', 'assert perimeter_polygon(10,15)==150', 'assert perimeter_polygon(9,7)==63']\n[BEGIN]\n", "completion": "from math import tan, pi\r\ndef perimeter_polygon(s,l):\r\n perimeter = s*l\r\n return perimeter\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether every even index contains even numbers of a given list.\n\n Your code should pass these tests:\n\n['assert even_position([3,2,1]) == False', 'assert even_position([1,2,3]) == False', 'assert even_position([2,1,4]) == True']\n[BEGIN]\n", "completion": "def even_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove the nested record from the given tuple.\n\n Your code should pass these tests:\n\n['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)']\n[BEGIN]\n", "completion": "def remove_nested(test_tup):\r\n res = tuple()\r\n for count, ele in enumerate(test_tup):\r\n if not isinstance(ele, tuple):\r\n res = res + (ele, )\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of lists in a given number of lists.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def count_list(input_list): \r\n return len(input_list)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the last position of an element in a sorted array.\n\n Your code should pass these tests:\n\n['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']\n[BEGIN]\n", "completion": "def last(arr,x,n):\r\n low = 0\r\n high = n - 1\r\n res = -1 \r\n while (low <= high):\r\n mid = (low + high) // 2 \r\n if arr[mid] > x:\r\n high = mid - 1\r\n elif arr[mid] < x:\r\n low = mid + 1\r\n else:\r\n res = mid\r\n low = mid + 1\r\n return res\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an 'a' followed by anything, ending in 'b'.\n\n Your code should pass these tests:\n\n['assert text_starta_endb(\"aabbbb\")==(\\'Found a match!\\')', 'assert text_starta_endb(\"aabAbbbc\")==(\\'Not matched!\\')', 'assert text_starta_endb(\"accddbbjjj\")==(\\'Not matched!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_starta_endb(text):\r\n patterns = 'a.*?b$'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the n - cheap price items from a given dataset using heap queue algorithm.\n\n Your code should pass these tests:\n\n[\"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}]\", \"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1)==[{'name': 'Item-4', 'price': 22.75}]\"]\n[BEGIN]\n", "completion": "import heapq\r\ndef cheap_items(items,n):\r\n cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price'])\r\n return cheap_items\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite function to find the sum of all items in the given dictionary.\n\n Your code should pass these tests:\n\n[\"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\"]\n[BEGIN]\n", "completion": "def return_sum(dict):\r\n sum = 0\r\n for i in dict.values():\r\n sum = sum + i\r\n return sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of all odd natural numbers within the range l and r.\n\n Your code should pass these tests:\n\n['assert sum_in_Range(2,5) == 8', 'assert sum_in_Range(5,7) == 12', 'assert sum_in_Range(7,13) == 40']\n[BEGIN]\n", "completion": "def sum_Odd(n): \r\n terms = (n + 1)//2\r\n sum1 = terms * terms \r\n return sum1 \r\ndef sum_in_Range(l,r): \r\n return sum_Odd(r) - sum_Odd(l - 1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of an array.\n\n Your code should pass these tests:\n\n['assert _sum([1, 2, 3]) == 6', 'assert _sum([15, 12, 13, 10]) == 50', 'assert _sum([0, 1, 2]) == 3']\n[BEGIN]\n", "completion": "def _sum(arr): \r\n sum=0\r\n for i in arr: \r\n sum = sum + i \r\n return(sum) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to left rotate the bits of a given number.\n\n Your code should pass these tests:\n\n['assert left_Rotate(16,2) == 64', 'assert left_Rotate(10,2) == 40', 'assert left_Rotate(99,3) == 792']\n[BEGIN]\n", "completion": "INT_BITS = 32\r\ndef left_Rotate(n,d): \r\n return (n << d)|(n >> (INT_BITS - d)) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove all whitespaces from a string.\n\n Your code should pass these tests:\n\n[\"assert remove_all_spaces('python program')==('pythonprogram')\", \"assert remove_all_spaces('python programming language')==('pythonprogramminglanguage')\", \"assert remove_all_spaces('python program')==('pythonprogram')\"]\n[BEGIN]\n", "completion": "import re\r\ndef remove_all_spaces(text):\r\n return (re.sub(r'\\s+', '',text))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of equal numbers from three given integers.\n\n Your code should pass these tests:\n\n['assert test_three_equal(1,1,1) == 3', 'assert test_three_equal(-1,-2,-3) == 0', 'assert test_three_equal(1,2,2) == 2']\n[BEGIN]\n", "completion": "def test_three_equal(x,y,z):\r\n result= set([x,y,z])\r\n if len(result)==3:\r\n return 0\r\n else:\r\n return (4-len(result))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of rotations required to generate a sorted array.\n\n Your code should pass these tests:\n\n['assert count_Rotation([3,2,1],3) == 1', 'assert count_Rotation([4,5,1,2,3],5) == 2', 'assert count_Rotation([7,8,9,1,2,3],6) == 3']\n[BEGIN]\n", "completion": "def count_Rotation(arr,n): \r\n for i in range (1,n): \r\n if (arr[i] < arr[i - 1]): \r\n return i \r\n return 0\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given number is a perfect square or not.\n\n Your code should pass these tests:\n\n['assert is_Perfect_Square(10) == False', 'assert is_Perfect_Square(36) == True', 'assert is_Perfect_Square(14) == False']\n[BEGIN]\n", "completion": "def is_Perfect_Square(n) :\r\n i = 1\r\n while (i * i<= n):\r\n if ((n % i == 0) and (n / i == i)):\r\n return True \r\n i = i + 1\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the product of numbers is even or not.\n\n Your code should pass these tests:\n\n['assert is_Product_Even([1,2,3],3) == True', 'assert is_Product_Even([1,2,1,4],4) == True', 'assert is_Product_Even([1,1],2) == False']\n[BEGIN]\n", "completion": "def is_Product_Even(arr,n): \r\n for i in range(0,n): \r\n if ((arr[i] & 1) == 0): \r\n return True\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the list in a list of lists whose sum of elements is the highest.\n\n Your code should pass these tests:\n\n['assert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12] ', 'assert max_sum_list([[3,2,1], [6,5,4], [12,11,10]])==[12,11,10] ', 'assert max_sum_list([[2,3,1]])==[2,3,1] ']\n[BEGIN]\n", "completion": "def max_sum_list(lists):\r\n return max(lists, key=sum)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find maximum run of uppercase characters in the given string.\n\n Your code should pass these tests:\n\n[\"assert max_run_uppercase('GeMKSForGERksISBESt') == 5\", \"assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6\", \"assert max_run_uppercase('GooGLEFluTTER') == 4\"]\n[BEGIN]\n", "completion": "def max_run_uppercase(test_str):\r\n cnt = 0\r\n res = 0\r\n for idx in range(0, len(test_str)):\r\n if test_str[idx].isupper():\r\n cnt += 1\r\n else:\r\n res = cnt\r\n cnt = 0\r\n if test_str[len(test_str) - 1].isupper():\r\n res = cnt\r\n return (res)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the first odd number in a given list of numbers.\n\n Your code should pass these tests:\n\n['assert first_odd([1,3,5]) == 1', 'assert first_odd([2,4,1,3]) == 1', 'assert first_odd ([8,9,1]) == 9']\n[BEGIN]\n", "completion": "def first_odd(nums):\r\n first_odd = next((el for el in nums if el%2!=0),-1)\r\n return first_odd\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given tuples contain the k or not.\n\n Your code should pass these tests:\n\n['assert check_K((10, 4, 5, 6, 8), 6) == True', 'assert check_K((1, 2, 3, 4, 5, 6), 7) == False', 'assert check_K((7, 8, 9, 44, 11, 12), 11) == True']\n[BEGIN]\n", "completion": "def check_K(test_tup, K):\r\n res = False\r\n for ele in test_tup:\r\n if ele == K:\r\n res = True\r\n break\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if each element of second tuple is smaller than its corresponding index in first tuple.\n\n Your code should pass these tests:\n\n['assert check_smaller((1, 2, 3), (2, 3, 4)) == False', 'assert check_smaller((4, 5, 6), (3, 4, 5)) == True', 'assert check_smaller((11, 12, 13), (10, 11, 12)) == True']\n[BEGIN]\n", "completion": "def check_smaller(test_tup1, test_tup2):\r\n res = all(x > y for x, y in zip(test_tup1, test_tup2))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to iterate over elements repeating each as many times as its count.\n\n Your code should pass these tests:\n\n[\"assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q'] \", \"assert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's'] \", \"assert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']\"]\n[BEGIN]\n", "completion": "from collections import Counter\r\ndef count_variable(a,b,c,d):\r\n c = Counter(p=a, q=b, r=c, s=d)\r\n return list(c.elements())\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if two lists of tuples are identical or not.\n\n Your code should pass these tests:\n\n['assert check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True', 'assert check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False', 'assert check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True']\n[BEGIN]\n", "completion": "def check_identical(test_list1, test_list2):\r\n res = test_list1 == test_list2\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to abbreviate 'road' as 'rd.' in a given string.\n\n Your code should pass these tests:\n\n['assert road_rd(\"ravipadu Road\")==(\\'ravipadu Rd.\\')', 'assert road_rd(\"palnadu Road\")==(\\'palnadu Rd.\\')', 'assert road_rd(\"eshwar enclave Road\")==(\\'eshwar enclave Rd.\\')']\n[BEGIN]\n", "completion": "import re\r\ndef road_rd(street):\r\n return (re.sub('Road$', 'Rd.', street))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find length of the string.\n\n Your code should pass these tests:\n\n[\"assert string_length('python')==6\", \"assert string_length('program')==7\", \"assert string_length('language')==8\"]\n[BEGIN]\n", "completion": "def string_length(str1):\r\n count = 0\r\n for char in str1:\r\n count += 1\r\n return count\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the area of a rombus.\n\n Your code should pass these tests:\n\n['assert rombus_area(10,20)==100', 'assert rombus_area(10,5)==25', 'assert rombus_area(4,2)==4']\n[BEGIN]\n", "completion": "def rombus_area(p,q):\r\n area=(p*q)/2\r\n return area\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.\n\n Your code should pass these tests:\n\n['assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]', 'assert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]', 'assert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]']\n[BEGIN]\n", "completion": "def sort_by_dnf(arr, n):\r\n low=0\r\n mid=0\r\n high=n-1\r\n while mid <= high:\r\n if arr[mid] == 0:\r\n arr[low], arr[mid] = arr[mid], arr[low]\r\n low = low + 1\r\n mid = mid + 1\r\n elif arr[mid] == 1:\r\n mid = mid + 1\r\n else:\r\n arr[mid], arr[high] = arr[high], arr[mid]\r\n high = high - 1\r\n return arr\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to clear the values of the given tuples.\n\n Your code should pass these tests:\n\n['assert clear_tuple((1, 5, 3, 6, 8)) == ()', 'assert clear_tuple((2, 1, 4 ,5 ,6)) == ()', 'assert clear_tuple((3, 2, 5, 6, 8)) == ()']\n[BEGIN]\n", "completion": "def clear_tuple(test_tup):\r\n temp = list(test_tup)\r\n temp.clear()\r\n test_tup = tuple(temp)\r\n return (test_tup) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find numbers divisible by m or n from a list of numbers using lambda function.\n\n Your code should pass these tests:\n\n['assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],19,13)==[19, 65, 57, 39, 152, 190]', 'assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[2, 5, 8, 10]', 'assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10, 15, 20]']\n[BEGIN]\n", "completion": "def div_of_nums(nums,m,n):\r\n result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums)) \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count lower case letters in a given string.\n\n Your code should pass these tests:\n\n[\"assert lower_ctr('abc') == 3\", \"assert lower_ctr('string') == 6\", \"assert lower_ctr('Python') == 5\"]\n[BEGIN]\n", "completion": "def lower_ctr(str):\r\n lower_ctr= 0\r\n for i in range(len(str)):\r\n if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1 \r\n return lower_ctr\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the frequency of consecutive duplicate elements in a given list of numbers.\n\n Your code should pass these tests:\n\n['assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4])', 'assert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])', 'assert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])']\n[BEGIN]\n", "completion": "def count_duplic(lists):\r\n element = []\r\n frequency = []\r\n if not lists:\r\n return element\r\n running_count = 1\r\n for i in range(len(lists)-1):\r\n if lists[i] == lists[i+1]:\r\n running_count += 1\r\n else:\r\n frequency.append(running_count)\r\n element.append(lists[i])\r\n running_count = 1\r\n frequency.append(running_count)\r\n element.append(lists[i+1])\r\n return element,frequency\r\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given month number contains 28 days or not.\n\n Your code should pass these tests:\n\n['assert check_monthnum_number(2)==True', 'assert check_monthnum_number(1)==False', 'assert check_monthnum_number(3)==False']\n[BEGIN]\n", "completion": "def check_monthnum_number(monthnum1):\r\n if monthnum1 == 2:\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to merge two dictionaries into a single expression.\n\n Your code should pass these tests:\n\n['assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" })=={\\'B\\': \\'Black\\', \\'R\\': \\'Red\\', \\'P\\': \\'Pink\\', \\'G\\': \\'Green\\', \\'W\\': \\'White\\'}', 'assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={\\'O\\': \\'Orange\\', \\'P\\': \\'Pink\\', \\'B\\': \\'Black\\', \\'W\\': \\'White\\', \\'R\\': \\'Red\\'}', 'assert merge_dictionaries({ \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={\\'W\\': \\'White\\', \\'O\\': \\'Orange\\', \\'G\\': \\'Green\\', \\'B\\': \\'Black\\'}']\n[BEGIN]\n", "completion": "import collections as ct\r\ndef merge_dictionaries(dict1,dict2):\r\n merged_dict = dict(ct.ChainMap({}, dict1, dict2))\r\n return merged_dict\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to return true if the password is valid.\n\n Your code should pass these tests:\n\n['assert pass_validity(\"password\")==False', 'assert pass_validity(\"Password@10\")==True', 'assert pass_validity(\"password@10\")==False']\n[BEGIN]\n", "completion": "import re\r\ndef pass_validity(p):\r\n x = True\r\n while x: \r\n if (len(p)<6 or len(p)>12):\r\n break\r\n elif not re.search(\"[a-z]\",p):\r\n break\r\n elif not re.search(\"[0-9]\",p):\r\n break\r\n elif not re.search(\"[A-Z]\",p):\r\n break\r\n elif not re.search(\"[$#@]\",p):\r\n break\r\n elif re.search(\"\\s\",p):\r\n break\r\n else:\r\n return True\r\n x=False\r\n break\r\n\r\n if x:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given string starts with a substring using regex.\n\n Your code should pass these tests:\n\n['assert check_substring(\"dreams for dreams makes life fun\", \"makes\") == \\'string doesnt start with the given substring\\'', 'assert check_substring(\"Hi there how are you Hi alex\", \"Hi\") == \\'string starts with the given substring\\'', 'assert check_substring(\"Its been a long day\", \"been\") == \\'string doesnt start with the given substring\\'']\n[BEGIN]\n", "completion": "import re \r\ndef check_substring(string, sample) : \r\n if (sample in string): \r\n y = \"\\A\" + sample \r\n x = re.search(y, string) \r\n if x : \r\n return (\"string starts with the given substring\") \r\n else : \r\n return (\"string doesnt start with the given substring\") \r\n else : \r\n return (\"entered string isnt a substring\")\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to remove even numbers from a given list.\n\n Your code should pass these tests:\n\n['assert remove_even([1,3,5,2]) == [1,3,5]', 'assert remove_even([5,6,7]) == [5,7]', 'assert remove_even([1,2,3,4]) == [1,3]']\n[BEGIN]\n", "completion": "def remove_even(l):\r\n for i in l:\r\n if i % 2 == 0:\r\n l.remove(i)\r\n return l\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to access multiple elements of specified index from a given list.\n\n Your code should pass these tests:\n\n['assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]', 'assert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3]', 'assert access_elements([1,0,2,3],[0,1]) == [1,0]']\n[BEGIN]\n", "completion": "def access_elements(nums, list_index):\r\n result = [nums[i] for i in list_index]\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the type of triangle from the given sides.\n\n Your code should pass these tests:\n\n['assert check_Type_Of_Triangle(1,2,3) == \"Obtuse-angled Triangle\"', 'assert check_Type_Of_Triangle(2,2,2) == \"Acute-angled Triangle\"', 'assert check_Type_Of_Triangle(1,0,1) == \"Right-angled Triangle\"']\n[BEGIN]\n", "completion": "def check_Type_Of_Triangle(a,b,c): \r\n sqa = pow(a,2) \r\n sqb = pow(b,2) \r\n sqc = pow(c,2) \r\n if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb): \r\n return (\"Right-angled Triangle\") \r\n elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb): \r\n return (\"Obtuse-angled Triangle\") \r\n else: \r\n return (\"Acute-angled Triangle\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sum a specific column of a list in a given list of lists.\n\n Your code should pass these tests:\n\n['assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12', 'assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15', 'assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9']\n[BEGIN]\n", "completion": "def sum_column(list1, C):\r\n result = sum(row[C] for row in list1)\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count alphabets,digits and special charactes in a given string.\n\n Your code should pass these tests:\n\n['assert count_alpha_dig_spl(\"abc!@#123\")==(3,3,3)', 'assert count_alpha_dig_spl(\"dgsuy@#$%&1255\")==(5,4,5)', 'assert count_alpha_dig_spl(\"fjdsif627348#%$^&\")==(6,6,5)']\n[BEGIN]\n", "completion": "def count_alpha_dig_spl(string):\r\n alphabets=digits = special = 0\r\n for i in range(len(string)):\r\n if(string[i].isalpha()):\r\n alphabets = alphabets + 1\r\n elif(string[i].isdigit()):\r\n digits = digits + 1\r\n else:\r\n special = special + 1\r\n return (alphabets,digits,special) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find out the second most repeated (or frequent) string in the given sequence.\n\n Your code should pass these tests:\n\n[\"assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'\", \"assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'\", \"assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'\"]\n[BEGIN]\n", "completion": "from collections import Counter \r\n\t\r\ndef second_frequent(input): \r\n\tdict = Counter(input) \r\n\tvalue = sorted(dict.values(), reverse=True) \r\n\tsecond_large = value[1] \r\n\tfor (key, val) in dict.items(): \r\n\t\tif val == second_large: \r\n\t\t\treturn (key) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to round up a number to specific digits.\n\n Your code should pass these tests:\n\n['assert round_up(123.01247,0)==124', 'assert round_up(123.01247,1)==123.1', 'assert round_up(123.01247,2)==123.02']\n[BEGIN]\n", "completion": "import math\r\ndef round_up(a, digits):\r\n n = 10**-digits\r\n return round(math.ceil(a / n) * n, digits)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count equal element pairs from the given array.\n\n Your code should pass these tests:\n\n['assert count_Pairs([1,1,1,1],4) == 6', 'assert count_Pairs([1,5,1],3) == 1', 'assert count_Pairs([3,2,1,7,8,9],6) == 0']\n[BEGIN]\n", "completion": "def count_Pairs(arr,n): \r\n cnt = 0; \r\n for i in range(n): \r\n for j in range(i + 1,n): \r\n if (arr[i] == arr[j]): \r\n cnt += 1; \r\n return cnt; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract the maximum numeric value from a string by using regex.\n\n Your code should pass these tests:\n\n[\"assert extract_max('100klh564abc365bg') == 564\", \"assert extract_max('hello300how546mer231') == 546\", \"assert extract_max('its233beenalong343journey234') == 343\"]\n[BEGIN]\n", "completion": "import re \r\ndef extract_max(input): \r\n\tnumbers = re.findall('\\d+',input) \r\n\tnumbers = map(int,numbers) \r\n\treturn max(numbers)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to get dictionary keys as a list.\n\n Your code should pass these tests:\n\n[\"assert get_key({1:'python',2:'java'})==[1,2]\", \"assert get_key({10:'red',20:'blue',30:'black'})==[10,20,30]\", \"assert get_key({27:'language',39:'java',44:'little'})==[27,39,44]\"]\n[BEGIN]\n", "completion": "def get_key(dict): \r\n list = [] \r\n for key in dict.keys(): \r\n list.append(key) \r\n return list\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.\n\n Your code should pass these tests:\n\n['assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]] ', 'assert generate_matrix(2)==[[1,2],[4,3]]', 'assert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]]']\n[BEGIN]\n", "completion": "def generate_matrix(n):\r\n if n<=0:\r\n return [] \r\n matrix=[row[:] for row in [[0]*n]*n] \r\n row_st=0\r\n row_ed=n-1 \r\n col_st=0\r\n col_ed=n-1\r\n current=1 \r\n while (True):\r\n if current>n*n:\r\n break\r\n for c in range (col_st, col_ed+1):\r\n matrix[row_st][c]=current\r\n current+=1\r\n row_st+=1\r\n for r in range (row_st, row_ed+1):\r\n matrix[r][col_ed]=current\r\n current+=1\r\n col_ed-=1\r\n for c in range (col_ed, col_st-1, -1):\r\n matrix[row_ed][c]=current\r\n current+=1\r\n row_ed-=1\r\n for r in range (row_ed, row_st-1, -1):\r\n matrix[r][col_st]=current\r\n current+=1\r\n col_st+=1\r\n return matrix\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the slope of a line.\n\n Your code should pass these tests:\n\n['assert slope(4,2,2,5) == -1.5', 'assert slope(2,4,4,6) == 1', 'assert slope(1,2,4,2) == 0']\n[BEGIN]\n", "completion": "def slope(x1,y1,x2,y2): \r\n return (float)(y2-y1)/(x2-x1) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find length of the subarray having maximum sum.\n\n Your code should pass these tests:\n\n['assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5', 'assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2', 'assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3']\n[BEGIN]\n", "completion": "from sys import maxsize \r\ndef max_sub_array_sum(a,size): \r\n\tmax_so_far = -maxsize - 1\r\n\tmax_ending_here = 0\r\n\tstart = 0\r\n\tend = 0\r\n\ts = 0\r\n\tfor i in range(0,size): \r\n\t\tmax_ending_here += a[i] \r\n\t\tif max_so_far < max_ending_here: \r\n\t\t\tmax_so_far = max_ending_here \r\n\t\t\tstart = s \r\n\t\t\tend = i \r\n\t\tif max_ending_here < 0: \r\n\t\t\tmax_ending_here = 0\r\n\t\t\ts = i+1\r\n\treturn (end - start + 1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the cube sum of first n odd natural numbers.\n\n Your code should pass these tests:\n\n['assert cube_Sum(2) == 28', 'assert cube_Sum(3) == 153', 'assert cube_Sum(4) == 496']\n[BEGIN]\n", "completion": "def cube_Sum(n): \r\n sum = 0 \r\n for i in range(0,n) : \r\n sum += (2*i+1)*(2*i+1)*(2*i+1) \r\n return sum\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find minimum number swaps required to make two binary strings equal.\n\n Your code should pass these tests:\n\n['assert min_Swaps(\"0011\",\"1111\") == 1', 'assert min_Swaps(\"00011\",\"01001\") == 2', 'assert min_Swaps(\"111\",\"111\") == 0']\n[BEGIN]\n", "completion": "def min_Swaps(s1,s2) : \r\n c0 = 0; c1 = 0; \r\n for i in range(len(s1)) : \r\n if (s1[i] == '0' and s2[i] == '1') : \r\n c0 += 1; \r\n elif (s1[i] == '1' and s2[i] == '0') : \r\n c1 += 1; \r\n result = c0 // 2 + c1 // 2; \r\n if (c0 % 2 == 0 and c1 % 2 == 0) : \r\n return result; \r\n elif ((c0 + c1) % 2 == 0) : \r\n return result + 2; \r\n else : \r\n return -1; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort the tuples alphabetically by the first item of each tuple.\n\n Your code should pass these tests:\n\n['assert sort_tuple([(\"Amana\", 28), (\"Zenat\", 30), (\"Abhishek\", 29),(\"Nikhil\", 21), (\"B\", \"C\")]) == [(\\'Abhishek\\', 29), (\\'Amana\\', 28), (\\'B\\', \\'C\\'), (\\'Nikhil\\', 21), (\\'Zenat\\', 30)]', 'assert sort_tuple([(\"aaaa\", 28), (\"aa\", 30), (\"bab\", 29), (\"bb\", 21), (\"csa\", \"C\")]) == [(\\'aa\\', 30), (\\'aaaa\\', 28), (\\'bab\\', 29), (\\'bb\\', 21), (\\'csa\\', \\'C\\')]', 'assert sort_tuple([(\"Sarala\", 28), (\"Ayesha\", 30), (\"Suman\", 29),(\"Sai\", 21), (\"G\", \"H\")]) == [(\\'Ayesha\\', 30), (\\'G\\', \\'H\\'), (\\'Sai\\', 21), (\\'Sarala\\', 28), (\\'Suman\\', 29)]']\n[BEGIN]\n", "completion": "def sort_tuple(tup): \r\n\tn = len(tup) \r\n\tfor i in range(n): \r\n\t\tfor j in range(n-i-1): \r\n\t\t\tif tup[j][0] > tup[j + 1][0]: \r\n\t\t\t\ttup[j], tup[j + 1] = tup[j + 1], tup[j] \r\n\treturn tup\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.\n\n Your code should pass these tests:\n\n['assert Check_Solution(2,0,-1) == \"Yes\"', 'assert Check_Solution(1,-5,6) == \"No\"', 'assert Check_Solution(2,0,2) == \"Yes\"']\n[BEGIN]\n", "completion": "def Check_Solution(a,b,c): \r\n if b == 0: \r\n return (\"Yes\") \r\n else: \r\n return (\"No\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the number of inversions in the given array.\n\n Your code should pass these tests:\n\n['assert get_inv_count([1, 20, 6, 4, 5], 5) == 5', 'assert get_inv_count([8, 4, 2, 1], 4) == 6', 'assert get_inv_count([3, 1, 2], 3) == 2']\n[BEGIN]\n", "completion": "def get_inv_count(arr, n): \r\n\tinv_count = 0\r\n\tfor i in range(n): \r\n\t\tfor j in range(i + 1, n): \r\n\t\t\tif (arr[i] > arr[j]): \r\n\t\t\t\tinv_count += 1\r\n\treturn inv_count \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the number which occurs for odd number of times in the given array.\n\n Your code should pass these tests:\n\n['assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5', 'assert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3', 'assert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5']\n[BEGIN]\n", "completion": "def get_odd_occurence(arr, arr_size):\r\n for i in range(0, arr_size):\r\n count = 0\r\n for j in range(0, arr_size):\r\n if arr[i] == arr[j]:\r\n count += 1\r\n if (count % 2 != 0):\r\n return arr[i]\r\n return -1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.\n\n Your code should pass these tests:\n\n['assert nth_super_ugly_number(12,[2,7,13,19])==32', 'assert nth_super_ugly_number(10,[2,7,13,19])==26', 'assert nth_super_ugly_number(100,[2,7,13,19])==5408']\n[BEGIN]\n", "completion": "import heapq\r\ndef nth_super_ugly_number(n, primes):\r\n uglies = [1]\r\n def gen(prime):\r\n for ugly in uglies:\r\n yield ugly * prime\r\n merged = heapq.merge(*map(gen, primes))\r\n while len(uglies) < n:\r\n ugly = next(merged)\r\n if ugly != uglies[-1]:\r\n uglies.append(ugly)\r\n return uglies[-1]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the kth element in an array containing odd elements first and then even elements.\n\n Your code should pass these tests:\n\n['assert get_Number(8,5) == 2', 'assert get_Number(7,2) == 3', 'assert get_Number(5,2) == 3']\n[BEGIN]\n", "completion": "def get_Number(n, k): \r\n arr = [0] * n; \r\n i = 0; \r\n odd = 1; \r\n while (odd <= n): \r\n arr[i] = odd; \r\n i += 1; \r\n odd += 2;\r\n even = 2; \r\n while (even <= n): \r\n arr[i] = even; \r\n i += 1;\r\n even += 2; \r\n return arr[k - 1]; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the number of digits in factorial of a given number.\n\n Your code should pass these tests:\n\n['assert find_Digits(7) == 4', 'assert find_Digits(5) == 3', 'assert find_Digits(4) == 2']\n[BEGIN]\n", "completion": "import math \r\ndef find_Digits(n): \r\n if (n < 0): \r\n return 0;\r\n if (n <= 1): \r\n return 1; \r\n x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0)); \r\n return math.floor(x) + 1; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the minimum number of platforms required for a railway/bus station.\n\n Your code should pass these tests:\n\n['assert find_platform([900, 940, 950, 1100, 1500, 1800],[910, 1200, 1120, 1130, 1900, 2000],6)==3', 'assert find_platform([100,200,300,400],[700,800,900,1000],4)==4', 'assert find_platform([5,6,7,8],[4,3,2,1],4)==1']\n[BEGIN]\n", "completion": "def find_platform(arr, dep, n): \r\n arr.sort() \r\n dep.sort() \r\n plat_needed = 1\r\n result = 1\r\n i = 1\r\n j = 0\r\n while (i < n and j < n): \r\n if (arr[i] <= dep[j]): \r\n plat_needed+= 1\r\n i+= 1\r\n elif (arr[i] > dep[j]): \r\n plat_needed-= 1\r\n j+= 1\r\n if (plat_needed > result): \r\n result = plat_needed \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to copy a list from a singleton tuple.\n\n Your code should pass these tests:\n\n['assert lcopy([1, 2, 3]) == [1, 2, 3]', 'assert lcopy([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18]', 'assert lcopy([4, 5, 6]) == [4, 5, 6]\\n']\n[BEGIN]\n", "completion": "def lcopy(xs):\n return xs[:]\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the area of a trapezium.\n\n Your code should pass these tests:\n\n['assert area_trapezium(6,9,4)==30', 'assert area_trapezium(10,20,30)==450', 'assert area_trapezium(15,25,35)==700']\n[BEGIN]\n", "completion": "def area_trapezium(base1,base2,height):\r\n area = 0.5 * (base1 + base2) * height\r\n return area\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find sum of all prime divisors of a given number.\n\n Your code should pass these tests:\n\n['assert Sum(60) == 10', 'assert Sum(39) == 16', 'assert Sum(40) == 7']\n[BEGIN]\n", "completion": "def Sum(N): \r\n SumOfPrimeDivisors = [0]*(N + 1) \r\n for i in range(2,N + 1) : \r\n if (SumOfPrimeDivisors[i] == 0) : \r\n for j in range(i,N + 1,i) : \r\n SumOfPrimeDivisors[j] += i \r\n return SumOfPrimeDivisors[N] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if a triangle of positive area is possible with the given angles.\n\n Your code should pass these tests:\n\n['assert is_triangleexists(50,60,70)==True', 'assert is_triangleexists(90,45,45)==True', 'assert is_triangleexists(150,30,70)==False']\n[BEGIN]\n", "completion": "def is_triangleexists(a,b,c): \r\n if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180): \r\n if((a + b)>= c or (b + c)>= a or (a + c)>= b): \r\n return True \r\n else:\r\n return False\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find sum of inverse of divisors.\n\n Your code should pass these tests:\n\n['assert Sum_of_Inverse_Divisors(6,12) == 2', 'assert Sum_of_Inverse_Divisors(9,13) == 1.44', 'assert Sum_of_Inverse_Divisors(1,4) == 4']\n[BEGIN]\n", "completion": "def Sum_of_Inverse_Divisors(N,Sum): \r\n ans = float(Sum)*1.0 /float(N); \r\n return round(ans,2); \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to remove negative numbers from a list.\n\n Your code should pass these tests:\n\n['assert remove_negs([1,-2,3,-4]) == [1,3]', 'assert remove_negs([1,2,3,-4]) == [1,2,3]', 'assert remove_negs([4,5,-6,7,-8]) == [4,5,7]']\n[BEGIN]\n", "completion": "def remove_negs(num_list): \r\n for item in num_list: \r\n if item < 0: \r\n num_list.remove(item) \r\n return num_list\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find sum of odd factors of a number.\n\n Your code should pass these tests:\n\n['assert sum_of_odd_Factors(30) == 24', 'assert sum_of_odd_Factors(18) == 13', 'assert sum_of_odd_Factors(2) == 1']\n[BEGIN]\n", "completion": "import math\r\ndef sum_of_odd_Factors(n): \r\n res = 1\r\n while n % 2 == 0: \r\n n = n // 2 \r\n for i in range(3,int(math.sqrt(n) + 1)): \r\n count = 0\r\n curr_sum = 1\r\n curr_term = 1\r\n while n % i == 0: \r\n count+=1 \r\n n = n // i \r\n curr_term *= i \r\n curr_sum += curr_term \r\n res *= curr_sum \r\n if n >= 2: \r\n res *= (1 + n) \r\n return res \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.\n\n Your code should pass these tests:\n\n['assert raw_heap([25, 44, 68, 21, 39, 23, 89])==[21, 25, 23, 44, 39, 68, 89]', 'assert raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])== [14, 25, 22, 25, 35, 65, 75, 85, 58]', 'assert raw_heap([4, 5, 6, 2])==[2, 4, 6, 5]']\n[BEGIN]\n", "completion": "import heapq as hq\r\ndef raw_heap(rawheap):\r\n hq.heapify(rawheap)\r\n return rawheap\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check for even parity of a given number.\n\n Your code should pass these tests:\n\n['assert check_Even_Parity(10) == True', 'assert check_Even_Parity(11) == False', 'assert check_Even_Parity(18) == True']\n[BEGIN]\n", "completion": "def check_Even_Parity(x): \r\n parity = 0\r\n while (x != 0): \r\n x = x & (x - 1) \r\n parity += 1\r\n if (parity % 2 == 0): \r\n return True\r\n else: \r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find minimum adjacent swaps required to sort binary array.\n\n Your code should pass these tests:\n\n['assert find_Min_Swaps([1,0,1,0],4) == 3', 'assert find_Min_Swaps([0,1,0],3) == 1', 'assert find_Min_Swaps([0,0,1,1,0],5) == 2']\n[BEGIN]\n", "completion": "def find_Min_Swaps(arr,n) : \r\n noOfZeroes = [0] * n \r\n count = 0 \r\n noOfZeroes[n - 1] = 1 - arr[n - 1] \r\n for i in range(n-2,-1,-1) : \r\n noOfZeroes[i] = noOfZeroes[i + 1] \r\n if (arr[i] == 0) : \r\n noOfZeroes[i] = noOfZeroes[i] + 1\r\n for i in range(0,n) : \r\n if (arr[i] == 1) : \r\n count = count + noOfZeroes[i] \r\n return count \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to list out the list of given strings individually using map function.\n\n Your code should pass these tests:\n\n[\"assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]\", \"assert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]\", \"assert listify_list([' red ', 'green',' black', 'blue ',' orange', 'brown'])==[[' ', 'r', 'e', 'd', ' '], ['g', 'r', 'e', 'e', 'n'], [' ', 'b', 'l', 'a', 'c', 'k'], ['b', 'l', 'u', 'e', ' '], [' ', 'o', 'r', 'a', 'n', 'g', 'e'], ['b', 'r', 'o', 'w', 'n']]\"]\n[BEGIN]\n", "completion": "def listify_list(list1):\r\n result = list(map(list,list1)) \r\n return result \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count number of lists in a given list of lists and square the count.\n\n Your code should pass these tests:\n\n['assert count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==25', 'assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]] )==16', 'assert count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])==9']\n[BEGIN]\n", "completion": "def count_list(input_list): \r\n return (len(input_list))**2\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to generate all sublists of a given list.\n\n Your code should pass these tests:\n\n['assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]', \"assert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]\", 'assert sub_lists([1,2,3])==[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]']\n[BEGIN]\n", "completion": "from itertools import combinations\r\ndef sub_lists(my_list):\r\n\tsubs = []\r\n\tfor i in range(0, len(my_list)+1):\r\n\t temp = [list(x) for x in combinations(my_list, i)]\r\n\t if len(temp)>0:\r\n\t subs.extend(temp)\r\n\treturn subs\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given string is ending with only alphanumeric characters or not using regex.\n\n Your code should pass these tests:\n\n['assert check_alphanumeric(\"dawood@\") == \\'Discard\\'', 'assert check_alphanumeric(\"skdmsam326\") == \\'Accept\\'', 'assert check_alphanumeric(\"cooltricks@\") == \\'Discard\\'']\n[BEGIN]\n", "completion": "import re \r\nregex = '[a-zA-z0-9]$'\r\ndef check_alphanumeric(string): \r\n\tif(re.search(regex, string)): \r\n\t\treturn (\"Accept\") \r\n\telse: \r\n\t\treturn (\"Discard\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find all anagrams of a string in a given list of strings using lambda function.\n\n Your code should pass these tests:\n\n['assert anagram_lambda([\"bcda\", \"abce\", \"cbda\", \"cbea\", \"adcb\"],\"abcd\")==[\\'bcda\\', \\'cbda\\', \\'adcb\\']', 'assert anagram_lambda([\"recitals\",\" python\"], \"articles\" )==[\"recitals\"]', 'assert anagram_lambda([\" keep\",\" abcdef\",\" xyz\"],\" peek\")==[\" keep\"]']\n[BEGIN]\n", "completion": "from collections import Counter \r\ndef anagram_lambda(texts,str):\r\n result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the occurrences of n most common words in a given text.\n\n Your code should pass these tests:\n\n['assert n_common_words(\"python is a programming language\",1)==[(\\'python\\', 1)]', 'assert n_common_words(\"python is a programming language\",1)==[(\\'python\\', 1)]', 'assert n_common_words(\"python is a programming language\",5)==[(\\'python\\', 1),(\\'is\\', 1), (\\'a\\', 1), (\\'programming\\', 1), (\\'language\\', 1)]']\n[BEGIN]\n", "completion": "from collections import Counter\r\nimport re\r\ndef n_common_words(text,n):\r\n words = re.findall('\\w+',text)\r\n n_common_words= Counter(words).most_common(n)\r\n return list(n_common_words)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.\n\n Your code should pass these tests:\n\n['assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3', 'assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4', 'assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5']\n[BEGIN]\n", "completion": "def find_longest_conseq_subseq(arr, n): \r\n\tans = 0\r\n\tcount = 0\r\n\tarr.sort() \r\n\tv = [] \r\n\tv.append(arr[0]) \r\n\tfor i in range(1, n): \r\n\t\tif (arr[i] != arr[i - 1]): \r\n\t\t\tv.append(arr[i]) \r\n\tfor i in range(len(v)): \r\n\t\tif (i > 0 and v[i] == v[i - 1] + 1): \r\n\t\t\tcount += 1\r\n\t\telse: \r\n\t\t\tcount = 1\r\n\t\tans = max(ans, count) \r\n\treturn ans \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find palindromes in a given list of strings using lambda function.\n\n Your code should pass these tests:\n\n['assert palindrome_lambda([\"php\", \"res\", \"Python\", \"abcd\", \"Java\", \"aaa\"])==[\\'php\\', \\'aaa\\']', 'assert palindrome_lambda([\"abcd\", \"Python\", \"abba\", \"aba\"])==[\\'abba\\', \\'aba\\']', 'assert palindrome_lambda([\"abcd\", \"abbccbba\", \"abba\", \"aba\"])==[\\'abbccbba\\', \\'abba\\', \\'aba\\']']\n[BEGIN]\n", "completion": "def palindrome_lambda(texts):\r\n result = list(filter(lambda x: (x == \"\".join(reversed(x))), texts))\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to print n-times a list using map function.\n\n Your code should pass these tests:\n\n['assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21]', 'assert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28]', 'assert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70]']\n[BEGIN]\n", "completion": "def ntimes_list(nums,n):\r\n result = map(lambda x:n*x, nums) \r\n return list(result)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check whether the given month name contains 31 days or not.\n\n Your code should pass these tests:\n\n['assert check_monthnumb(\"February\")==False', 'assert check_monthnumb(\"January\")==True', 'assert check_monthnumb(\"March\")==True']\n[BEGIN]\n", "completion": "def check_monthnumb(monthname2):\r\n if(monthname2==\"January\" or monthname2==\"March\"or monthname2==\"May\" or monthname2==\"July\" or monthname2==\"Augest\" or monthname2==\"October\" or monthname2==\"December\"):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to add a minimum number such that the sum of array becomes even.\n\n Your code should pass these tests:\n\n['assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1', 'assert min_Num([1,2,3,4,5,6,7,8],8) == 2', 'assert min_Num([1,2,3],3) == 2']\n[BEGIN]\n", "completion": "def min_Num(arr,n): \r\n odd = 0\r\n for i in range(n): \r\n if (arr[i] % 2): \r\n odd += 1 \r\n if (odd % 2): \r\n return 1\r\n return 2\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the length of the last word in a given string.\n\n Your code should pass these tests:\n\n['assert length_Of_Last_Word(\"python language\") == 8', 'assert length_Of_Last_Word(\"PHP\") == 3', 'assert length_Of_Last_Word(\"\") == 0']\n[BEGIN]\n", "completion": "def length_Of_Last_Word(a): \r\n l = 0\r\n x = a.strip() \r\n for i in range(len(x)): \r\n if x[i] == \" \": \r\n l = 0\r\n else: \r\n l += 1\r\n return l \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove sublists from a given list of lists, which are outside a given range.\n\n Your code should pass these tests:\n\n['assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]]', 'assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[2], [1, 2, 3]]', 'assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],0,7)==[[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]']\n[BEGIN]\n", "completion": "def remove_list_range(list1, leftrange, rigthrange):\r\n result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)]\r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.\n\n Your code should pass these tests:\n\n['assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48', 'assert sum_positivenum([10,15,-14,13,-18,12,-20])==50', 'assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522']\n[BEGIN]\n", "completion": "def sum_positivenum(nums):\r\n sum_positivenum = list(filter(lambda nums:nums>0,nums))\r\n return sum(sum_positivenum)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given strings are rotations of each other or not.\n\n Your code should pass these tests:\n\n['assert are_Rotations(\"abc\",\"cba\") == False', 'assert are_Rotations(\"abcd\",\"cdba\") == False', 'assert are_Rotations(\"abacd\",\"cdaba\") == True']\n[BEGIN]\n", "completion": "def are_Rotations(string1,string2): \r\n size1 = len(string1) \r\n size2 = len(string2) \r\n temp = '' \r\n if size1 != size2: \r\n return False\r\n temp = string1 + string1 \r\n if (temp.count(string2)> 0): \r\n return True\r\n else: \r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if a nested list is a subset of another nested list.\n\n Your code should pass these tests:\n\n['assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True', 'assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True', 'assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False']\n[BEGIN]\n", "completion": "def check_subset(list1,list2): \r\n return all(map(list1.__contains__,list2)) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to solve the fibonacci sequence using recursion.\n\n Your code should pass these tests:\n\n['assert fibonacci(7) == 13', 'assert fibonacci(8) == 21', 'assert fibonacci(9) == 34']\n[BEGIN]\n", "completion": "def fibonacci(n):\r\n if n == 1 or n == 2:\r\n return 1\r\n else:\r\n return (fibonacci(n - 1) + (fibonacci(n - 2)))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check if the string is a concatenation of another string.\n\n Your code should pass these tests:\n\n['assert check_Concat(\"abcabcabc\",\"abc\") == True', 'assert check_Concat(\"abcab\",\"abc\") == False', 'assert check_Concat(\"aba\",\"ab\") == False']\n[BEGIN]\n", "completion": "def check_Concat(str1,str2):\r\n N = len(str1)\r\n M = len(str2)\r\n if (N % M != 0):\r\n return False\r\n for i in range(N):\r\n if (str1[i] != str2[i % M]):\r\n return False \r\n return True\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the minimum difference in the tuple pairs of given tuples.\n\n Your code should pass these tests:\n\n['assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1', 'assert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2', 'assert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6']\n[BEGIN]\n", "completion": "def min_difference(test_list):\r\n temp = [abs(b - a) for a, b in test_list]\r\n res = min(temp)\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find lcm of two positive integers.\n\n Your code should pass these tests:\n\n['assert lcm(4,6) == 12', 'assert lcm(15,17) == 255', 'assert lcm(2,6) == 6']\n[BEGIN]\n", "completion": "def lcm(x, y):\r\n if x > y:\r\n z = x\r\n else:\r\n z = y\r\n while(True):\r\n if((z % x == 0) and (z % y == 0)):\r\n lcm = z\r\n break\r\n z += 1\r\n return lcm\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to sort the given string.\n\n Your code should pass these tests:\n\n['assert sort_String(\"cba\") == \"abc\"', 'assert sort_String(\"data\") == \"aadt\"', 'assert sort_String(\"zxy\") == \"xyz\"']\n[BEGIN]\n", "completion": "def sort_String(str) : \r\n str = ''.join(sorted(str)) \r\n return (str) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if the given tuple contains only k elements.\n\n Your code should pass these tests:\n\n['assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True', 'assert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True', 'assert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False']\n[BEGIN]\n", "completion": "def check_tuples(test_tuple, K):\r\n res = all(ele in K for ele in test_tuple)\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.\n\n Your code should pass these tests:\n\n['assert text_match(\"aabbbbd\") == \\'Not matched!\\'', 'assert text_match(\"aabAbbbc\") == \\'Not matched!\\'', 'assert text_match(\"accddbbjjjb\") == \\'Found a match!\\'']\n[BEGIN]\n", "completion": "import re\r\ndef text_match(text):\r\n patterns = 'a.*?b$'\r\n if re.search(patterns, text):\r\n return ('Found a match!')\r\n else:\r\n return ('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find number of solutions in quadratic equation.\n\n Your code should pass these tests:\n\n['assert Check_Solution(2,5,2) == \"2 solutions\"', 'assert Check_Solution(1,1,1) == \"No solutions\"', 'assert Check_Solution(1,2,1) == \"1 solution\"']\n[BEGIN]\n", "completion": "def Check_Solution(a,b,c) : \r\n if ((b*b) - (4*a*c)) > 0 : \r\n return (\"2 solutions\") \r\n elif ((b*b) - (4*a*c)) == 0 : \r\n return (\"1 solution\") \r\n else : \r\n return (\"No solutions\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the sum of first even and odd number of a given list.\n\n Your code should pass these tests:\n\n['assert sum_even_odd([1,3,5,7,4,1,6,8])==5', 'assert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3', 'assert sum_even_odd([1,5,7,9,10])==11']\n[BEGIN]\n", "completion": "def sum_even_odd(list1):\r\n first_even = next((el for el in list1 if el%2==0),-1)\r\n first_odd = next((el for el in list1 if el%2!=0),-1)\r\n return (first_even+first_odd)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to caluclate perimeter of a parallelogram.\n\n Your code should pass these tests:\n\n['assert parallelogram_perimeter(10,20)==400', 'assert parallelogram_perimeter(15,20)==600', 'assert parallelogram_perimeter(8,9)==144']\n[BEGIN]\n", "completion": "def parallelogram_perimeter(b,h):\r\n perimeter=2*(b*h)\r\n return perimeter\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find numbers divisible by m and n from a list of numbers using lambda function.\n\n Your code should pass these tests:\n\n['assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44]', 'assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10]', 'assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20]']\n[BEGIN]\n", "completion": "def div_of_nums(nums,m,n):\r\n result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums)) \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether all the bits are within a given range or not.\n\n Your code should pass these tests:\n\n['assert all_Bits_Set_In_The_Given_Range(10,2,1) == True ', 'assert all_Bits_Set_In_The_Given_Range(5,2,4) == False', 'assert all_Bits_Set_In_The_Given_Range(22,2,3) == True ']\n[BEGIN]\n", "completion": "def all_Bits_Set_In_The_Given_Range(n,l,r): \r\n num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) \r\n new_num = n & num \r\n if (num == new_num): \r\n return True\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the two given strings are isomorphic to each other or not.\n\n Your code should pass these tests:\n\n['assert is_Isomorphic(\"paper\",\"title\") == True', 'assert is_Isomorphic(\"ab\",\"ba\") == True', 'assert is_Isomorphic(\"ab\",\"aa\") == False']\n[BEGIN]\n", "completion": "def is_Isomorphic(str1,str2): \r\n dict_str1 = {}\r\n dict_str2 = {}\r\n for i, value in enumerate(str1):\r\n dict_str1[value] = dict_str1.get(value,[]) + [i] \r\n for j, value in enumerate(str2):\r\n dict_str2[value] = dict_str2.get(value,[]) + [j]\r\n if sorted(dict_str1.values()) == sorted(dict_str2.values()):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to add all the numbers in a list and divide it with the length of the list.\n\n Your code should pass these tests:\n\n['assert sum_num((8, 2, 3, 0, 7))==4.0', 'assert sum_num((-10,-20,-30))==-20.0', 'assert sum_num((19,15,18))==17.333333333333332']\n[BEGIN]\n", "completion": "def sum_num(numbers):\r\n total = 0\r\n for x in numbers:\r\n total += x\r\n return total/len(numbers) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given number is odd or not using bitwise operator.\n\n Your code should pass these tests:\n\n['assert is_odd(5) == True', 'assert is_odd(6) == False', 'assert is_odd(7) == True']\n[BEGIN]\n", "completion": "def is_odd(n) : \r\n if (n^1 == n-1) :\r\n return True; \r\n else :\r\n return False; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to substract the elements of the given nested tuples.\n\n Your code should pass these tests:\n\n['assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))', 'assert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))', 'assert substract_elements(((19, 5), (18, 7), (19, 11), (17, 12)), ((12, 9), (17, 11), (13, 3), (19, 5))) == ((7, -4), (1, -4), (6, 8), (-2, 7))']\n[BEGIN]\n", "completion": "def substract_elements(test_tup1, test_tup2):\r\n res = tuple(tuple(a - b for a, b in zip(tup1, tup2))\r\n for tup1, tup2 in zip(test_tup1, test_tup2))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to reverse each list in a given list of lists.\n\n Your code should pass these tests:\n\n['assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]', 'assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]', 'assert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]']\n[BEGIN]\n", "completion": "def reverse_list_lists(lists):\r\n for l in lists:\r\n l.sort(reverse = True)\r\n return lists \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the index of an extra element present in one sorted array.\n\n Your code should pass these tests:\n\n['assert find_Extra([1,2,3,4],[1,2,3],3) == 3', 'assert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4', 'assert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5']\n[BEGIN]\n", "completion": "def find_Extra(arr1,arr2,n) : \r\n for i in range(0, n) : \r\n if (arr1[i] != arr2[i]) : \r\n return i \r\n return n \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given two numbers have same number of digits or not.\n\n Your code should pass these tests:\n\n['assert same_Length(12,1) == False', 'assert same_Length(2,2) == True', 'assert same_Length(10,20) == True']\n[BEGIN]\n", "completion": "def same_Length(A,B): \r\n while (A > 0 and B > 0): \r\n A = A / 10; \r\n B = B / 10; \r\n if (A == 0 and B == 0): \r\n return True; \r\n return False; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove multiple spaces in a string.\n\n Your code should pass these tests:\n\n[\"assert remove_spaces('python program')==('python program')\", \"assert remove_spaces('python programming language')==('python programming language')\", \"assert remove_spaces('python program')==('python program')\"]\n[BEGIN]\n", "completion": "import re\r\ndef remove_spaces(text):\r\n return (re.sub(' +',' ',text))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to get the last element of each sublist.\n\n Your code should pass these tests:\n\n['assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]', \"assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']\", 'assert Extract([[1, 2, 3], [4, 5]]) == [3, 5]']\n[BEGIN]\n", "completion": "def Extract(lst): \r\n return [item[-1] for item in lst] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert the given string of float type into tuple.\n\n Your code should pass these tests:\n\n['assert float_to_tuple(\"1.2, 1.3, 2.3, 2.4, 6.5\") == (1.2, 1.3, 2.3, 2.4, 6.5)', 'assert float_to_tuple(\"2.3, 2.4, 5.6, 5.4, 8.9\") == (2.3, 2.4, 5.6, 5.4, 8.9)', 'assert float_to_tuple(\"0.3, 0.5, 7.8, 9.4\") == (0.3, 0.5, 7.8, 9.4)']\n[BEGIN]\n", "completion": "def float_to_tuple(test_str):\r\n res = tuple(map(float, test_str.split(', ')))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum sum of subsequences of given array with no adjacent elements.\n\n Your code should pass these tests:\n\n['assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26', 'assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28', 'assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44']\n[BEGIN]\n", "completion": "def max_sum_subseq(A):\r\n n = len(A)\r\n if n == 1:\r\n return A[0]\r\n look_up = [None] * n\r\n look_up[0] = A[0]\r\n look_up[1] = max(A[0], A[1])\r\n for i in range(2, n):\r\n look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])\r\n look_up[i] = max(look_up[i], A[i])\r\n return look_up[n - 1]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.\n\n Your code should pass these tests:\n\n['assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] ', 'assert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8), (7,9)] ', 'assert sort_list_last([(20,50), (10,20), (40,40)])==[(10,20),(40,40),(20,50)] ']\n[BEGIN]\n", "completion": "def last(n):\r\n return n[-1]\r\ndef sort_list_last(tuples):\r\n return sorted(tuples, key=last)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the word is present in a given sentence or not.\n\n Your code should pass these tests:\n\n['assert is_Word_Present(\"machine learning\",\"machine\") == True', 'assert is_Word_Present(\"easy\",\"fun\") == False', 'assert is_Word_Present(\"python language\",\"code\") == False']\n[BEGIN]\n", "completion": "def is_Word_Present(sentence,word): \r\n s = sentence.split(\" \") \r\n for i in s: \r\n if (i == word): \r\n return True\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract specified number of elements from a given list, which follow each other continuously.\n\n Your code should pass these tests:\n\n['assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4]', 'assert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4]', 'assert extract_elements([0,0,0,0,0],5)==[0]']\n[BEGIN]\n", "completion": "from itertools import groupby \r\ndef extract_elements(numbers, n):\r\n result = [i for i, j in groupby(numbers) if len(list(j)) == n] \r\n return result\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether an array can be sorted or not by picking only the corner elements.\n\n Your code should pass these tests:\n\n['assert check([3,2,1,2,3,4],6) == True', 'assert check([2,1,4,5,1],5) == True', 'assert check([1,2,2,1,2,3],6) == True']\n[BEGIN]\n", "completion": "def check(arr,n): \r\n g = 0 \r\n for i in range(1,n): \r\n if (arr[i] - arr[i - 1] > 0 and g == 1): \r\n return False\r\n if (arr[i] - arr[i] < 0): \r\n g = 1\r\n return True\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function where a string will start with a specific number.\n\n Your code should pass these tests:\n\n[\"assert match_num('5-2345861')==True\", \"assert match_num('6-2345861')==False\", \"assert match_num('78910')==False\"]\n[BEGIN]\n", "completion": "import re\r\ndef match_num(string):\r\n text = re.compile(r\"^5\")\r\n if text.match(string):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the smallest multiple of the first n numbers.\n\n Your code should pass these tests:\n\n['assert smallest_multiple(13)==360360', 'assert smallest_multiple(2)==2', 'assert smallest_multiple(1)==1']\n[BEGIN]\n", "completion": "def smallest_multiple(n):\r\n if (n<=2):\r\n return n\r\n i = n * 2\r\n factors = [number for number in range(n, 1, -1) if number * 2 > n]\r\n while True:\r\n for a in factors:\r\n if i % a != 0:\r\n i += n\r\n break\r\n if (a == factors[-1] and i % a == 0):\r\n return i\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to combine two dictionaries by adding values for common keys.\n\n Your code should pass these tests:\n\n[\"assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300}) \", \"assert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900}) \", \"assert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})==({'b': 1800, 'd': 1800, 'a': 1800})\"]\n[BEGIN]\n", "completion": "from collections import Counter\r\ndef add_dict(d1,d2):\r\n add_dict = Counter(d1) + Counter(d2)\r\n return add_dict\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to count the total unset bits from 1 to n.\n\n Your code should pass these tests:\n\n['assert count_Unset_Bits(2) == 1', 'assert count_Unset_Bits(5) == 4', 'assert count_Unset_Bits(14) == 17']\n[BEGIN]\n", "completion": "def count_Unset_Bits(n) : \r\n cnt = 0; \r\n for i in range(1,n + 1) : \r\n temp = i; \r\n while (temp) : \r\n if (temp % 2 == 0) : \r\n cnt += 1; \r\n temp = temp // 2; \r\n return cnt; \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to return true if the given number is even else return false.\n\n Your code should pass these tests:\n\n['assert even_num(13.5)==False', 'assert even_num(0)==True', 'assert even_num(-9)==False']\n[BEGIN]\n", "completion": "def even_num(x):\r\n if x%2==0:\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of squares of binomial co-efficients.\n\n Your code should pass these tests:\n\n['assert sum_of_square(4) == 70', 'assert sum_of_square(5) == 252', 'assert sum_of_square(2) == 6']\n[BEGIN]\n", "completion": "def factorial(start,end): \r\n res = 1 \r\n for i in range(start,end + 1): \r\n res *= i \r\n return res \r\ndef sum_of_square(n): \r\n return int(factorial(n + 1, 2 * n) /factorial(1, n)) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to extract year, month and date from a url by using regex.\n\n Your code should pass these tests:\n\n['assert extract_date(\"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\") == [(\\'2016\\', \\'09\\', \\'02\\')]', 'assert extract_date(\"https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-s-death-his-brother-in-law-shares-advice-for-fans-1749646/\") == [(\\'2020\\', \\'11\\', \\'03\\')]', 'assert extract_date(\"https://economictimes.indiatimes.com/news/economy/2020/12/29/finance/pension-assets-under-pfrda-touch-rs-5-32-lakh-crore/articleshow/79736619.cms\") == [(\\'2020\\', \\'12\\', \\'29\\')]']\n[BEGIN]\n", "completion": "import re\r\ndef extract_date(url):\r\n return re.findall(r'/(\\d{4})/(\\d{1,2})/(\\d{1,2})/', url)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to print the first n lucky numbers.\n\n Your code should pass these tests:\n\n['assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33] ', 'assert lucky_num(5)==[1, 3, 7, 9, 13]', 'assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]']\n[BEGIN]\n", "completion": "def lucky_num(n):\r\n List=range(-1,n*n+9,2)\r\n i=2\r\n while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1\r\n return List[1:n+1]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the fixed point in the given array.\n\n Your code should pass these tests:\n\n['assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3', 'assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1', 'assert find_fixed_point([0, 2, 5, 8, 17],5) == 0']\n[BEGIN]\n", "completion": "def find_fixed_point(arr, n): \r\n\tfor i in range(n): \r\n\t\tif arr[i] is i: \r\n\t\t\treturn i \r\n\treturn -1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the previous palindrome of a specified number.\n\n Your code should pass these tests:\n\n['assert previous_palindrome(99)==88', 'assert previous_palindrome(1221)==1111', 'assert previous_palindrome(120)==111']\n[BEGIN]\n", "completion": "def previous_palindrome(num):\r\n for x in range(num-1,0,-1):\r\n if str(x) == str(x)[::-1]:\r\n return x\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to validate a gregorian date.\n\n Your code should pass these tests:\n\n['assert check_date(11,11,2002)==True', 'assert check_date(13,11,2002)==False', \"assert check_date('11','11','2002')==True\"]\n[BEGIN]\n", "completion": "import datetime\r\ndef check_date(m, d, y):\r\n try:\r\n m, d, y = map(int, (m, d, y))\r\n datetime.date(y, m, d)\r\n return True\r\n except ValueError:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.\n\n Your code should pass these tests:\n\n['assert maximum_product( [12, 74, 9, 50, 61, 41])==225700', 'assert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375', 'assert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520']\n[BEGIN]\n", "completion": "def maximum_product(nums):\r\n import heapq\r\n a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums)\r\n return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find ln, m lobb number.\n\n Your code should pass these tests:\n\n['assert int(lobb_num(5, 3)) == 35', 'assert int(lobb_num(3, 2)) == 5', 'assert int(lobb_num(4, 2)) == 20']\n[BEGIN]\n", "completion": "def binomial_coeff(n, k): \r\n\tC = [[0 for j in range(k + 1)] \r\n\t\t\tfor i in range(n + 1)] \r\n\tfor i in range(0, n + 1): \r\n\t\tfor j in range(0, min(i, k) + 1): \r\n\t\t\tif (j == 0 or j == i): \r\n\t\t\t\tC[i][j] = 1\r\n\t\t\telse: \r\n\t\t\t\tC[i][j] = (C[i - 1][j - 1] \r\n\t\t\t\t\t\t\t+ C[i - 1][j]) \r\n\treturn C[n][k] \r\ndef lobb_num(n, m): \r\n\treturn (((2 * m + 1) *\r\n\t\tbinomial_coeff(2 * n, m + n)) \r\n\t\t\t\t\t/ (m + n + 1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check for a number at the end of a string.\n\n Your code should pass these tests:\n\n[\"assert end_num('abcdef')==False\", \"assert end_num('abcdef7')==True\", \"assert end_num('abc')==False\"]\n[BEGIN]\n", "completion": "import re\r\ndef end_num(string):\r\n text = re.compile(r\".*[0-9]$\")\r\n if text.match(string):\r\n return True\r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the given string is made up of two alternating characters or not.\n\n Your code should pass these tests:\n\n['assert is_Two_Alter(\"abab\") == True', 'assert is_Two_Alter(\"aaaa\") == False', 'assert is_Two_Alter(\"xyz\") == False']\n[BEGIN]\n", "completion": "def is_Two_Alter(s): \r\n for i in range (len( s) - 2) : \r\n if (s[i] != s[i + 2]) : \r\n return False\r\n if (s[0] == s[1]): \r\n return False\r\n return True\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to rearrange positive and negative numbers in a given array using lambda function.\n\n Your code should pass these tests:\n\n['assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]', 'assert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]', 'assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]']\n[BEGIN]\n", "completion": "def rearrange_numbs(array_nums):\r\n result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i)\r\n return result \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find if there is a triplet in the array whose sum is equal to a given value.\n\n Your code should pass these tests:\n\n['assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)', 'assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)', 'assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)']\n[BEGIN]\n", "completion": "def find_triplet_array(A, arr_size, sum): \r\n\tfor i in range( 0, arr_size-2): \r\n\t\tfor j in range(i + 1, arr_size-1): \r\n\t\t\tfor k in range(j + 1, arr_size): \r\n\t\t\t\tif A[i] + A[j] + A[k] == sum: \r\n\t\t\t\t\treturn A[i],A[j],A[k] \r\n\t\t\t\t\treturn True\r\n\treturn False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the sequences of one upper case letter followed by lower case letters.\n\n Your code should pass these tests:\n\n['assert text_uppercase_lowercase(\"AaBbGg\")==(\\'Found a match!\\')', 'assert text_uppercase_lowercase(\"aA\")==(\\'Not matched!\\')', 'assert text_uppercase_lowercase(\"PYTHON\")==(\\'Not matched!\\')']\n[BEGIN]\n", "completion": "import re\r\ndef text_uppercase_lowercase(text):\r\n patterns = '[A-Z]+[a-z]+$'\r\n if re.search(patterns, text):\r\n return 'Found a match!'\r\n else:\r\n return ('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count coin change.\n\n Your code should pass these tests:\n\n['assert coin_change([1, 2, 3],3,4)==4', 'assert coin_change([4,5,6,7,8,9],6,9)==2', 'assert coin_change([4,5,6,7,8,9],6,4)==1']\n[BEGIN]\n", "completion": "def coin_change(S, m, n): \r\n table = [[0 for x in range(m)] for x in range(n+1)] \r\n for i in range(m): \r\n table[0][i] = 1\r\n for i in range(1, n+1): \r\n for j in range(m): \r\n x = table[i - S[j]][j] if i-S[j] >= 0 else 0\r\n y = table[i][j-1] if j >= 1 else 0 \r\n table[i][j] = x + y \r\n return table[n][m-1] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to multiply all items in the list.\n\n Your code should pass these tests:\n\n['assert multiply_list([1,-2,3]) == -6', 'assert multiply_list([1,2,3,4]) == 24', 'assert multiply_list([3,1,2,3]) == 18']\n[BEGIN]\n", "completion": "def multiply_list(items):\r\n tot = 1\r\n for x in items:\r\n tot *= x\r\n return tot\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove all tuples with all none values in the given tuple list.\n\n Your code should pass these tests:\n\n[\"assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'\", \"assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'\", \"assert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(1, 2), (2, None), (3, None), (24, 3)]'\"]\n[BEGIN]\n", "completion": "def remove_tuple(test_list):\r\n res = [sub for sub in test_list if not all(ele == None for ele in sub)]\r\n return (str(res)) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to perform chunking of tuples each of size n.\n\n Your code should pass these tests:\n\n['assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]', 'assert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]', 'assert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16, 17), (19, 21, 22, 25)]']\n[BEGIN]\n", "completion": "def chunk_tuples(test_tup, N):\r\n res = [test_tup[i : i + N] for i in range(0, len(test_tup), N)]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find a pair with the highest product from a given array of integers.\n\n Your code should pass these tests:\n\n['assert max_product([1, 2, 3, 4, 7, 0, 8, 4])==(7, 8)', 'assert max_product([0, -1, -2, -4, 5, 0, -6])==(-4, -6)', 'assert max_product([1, 3, 5, 6, 8, 9])==(8,9)']\n[BEGIN]\n", "completion": "def max_product(arr): \r\n arr_len = len(arr) \r\n if (arr_len < 2): \r\n return None \r\n x = arr[0]; y = arr[1] \r\n for i in range(0, arr_len): \r\n for j in range(i + 1, arr_len): \r\n if (arr[i] * arr[j] > x * y): \r\n x = arr[i]; y = arr[j] \r\n return x,y \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the length of the shortest string that has both str1 and str2 as subsequences.\n\n Your code should pass these tests:\n\n['assert super_seq(\"AGGTAB\", \"GXTXAYB\", 6, 7) == 9', 'assert super_seq(\"feek\", \"eke\", 4, 3) == 5', 'assert super_seq(\"PARRT\", \"RTA\", 5, 3) == 6']\n[BEGIN]\n", "completion": "def super_seq(X, Y, m, n):\r\n\tif (not m):\r\n\t\treturn n\r\n\tif (not n):\r\n\t\treturn m\r\n\tif (X[m - 1] == Y[n - 1]):\r\n\t\treturn 1 + super_seq(X, Y, m - 1, n - 1)\r\n\treturn 1 + min(super_seq(X, Y, m - 1, n),\tsuper_seq(X, Y, m, n - 1))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find maximum of two numbers.\n\n Your code should pass these tests:\n\n['assert max_of_two(10,20)==20', 'assert max_of_two(19,15)==19', 'assert max_of_two(-10,-20)==-10']\n[BEGIN]\n", "completion": "def max_of_two( x, y ):\r\n if x > y:\r\n return x\r\n return y\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to calculate the product of all the numbers of a given tuple.\n\n Your code should pass these tests:\n\n['assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864', 'assert mutiple_tuple((1,2,3)) == 6', 'assert mutiple_tuple((-2,-4,-6)) == -48']\n[BEGIN]\n", "completion": "def mutiple_tuple(nums):\r\n temp = list(nums)\r\n product = 1 \r\n for x in temp:\r\n product *= x\r\n return product\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find n-th rencontres number.\n\n Your code should pass these tests:\n\n['assert rencontres_number(7, 2) == 924', 'assert rencontres_number(3, 0) == 2', 'assert rencontres_number(3, 1) == 3']\n[BEGIN]\n", "completion": "def binomial_coeffi(n, k): \r\n\tif (k == 0 or k == n): \r\n\t\treturn 1\r\n\treturn (binomial_coeffi(n - 1, k - 1) \r\n\t\t+ binomial_coeffi(n - 1, k)) \r\ndef rencontres_number(n, m): \r\n\tif (n == 0 and m == 0): \r\n\t\treturn 1\r\n\tif (n == 1 and m == 0): \r\n\t\treturn 0\r\n\tif (m == 0): \r\n\t\treturn ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0))) \r\n\treturn (binomial_coeffi(n, m) * rencontres_number(n - m, 0))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the height of the given binary tree.\n\n Your test setup code:\nroot = Node(1) \r\nroot.left = Node(2) \r\nroot.right = Node(3) \r\nroot.left.left = Node(4) \r\nroot.left.right = Node(5) \r\nroot1 = Node(1); \r\nroot1.left = Node(2); \r\nroot1.right = Node(3); \r\nroot1.left.left = Node(4); \r\nroot1.right.left = Node(5); \r\nroot1.right.right = Node(6); \r\nroot1.right.right.right= Node(7); \r\nroot1.right.right.right.right = Node(8)\r\nroot2 = Node(1) \r\nroot2.left = Node(2) \r\nroot2.right = Node(3) \r\nroot2.left.left = Node(4) \r\nroot2.left.right = Node(5)\r\nroot2.left.left.left = Node(6)\r\nroot2.left.left.right = Node(7)\n\n Your code should pass these tests:\n\n['assert (max_height(root)) == 3', 'assert (max_height(root1)) == 5 ', 'assert (max_height(root2)) == 4']\n[BEGIN]\n", "completion": "class Node: \r\n\tdef __init__(self, data): \r\n\t\tself.data = data \r\n\t\tself.left = None\r\n\t\tself.right = None\r\ndef max_height(node): \r\n\tif node is None: \r\n\t\treturn 0 ; \r\n\telse : \r\n\t\tleft_height = max_height(node.left) \r\n\t\tright_height = max_height(node.right) \r\n\t\tif (left_height > right_height): \r\n\t\t\treturn left_height+1\r\n\t\telse: \r\n\t\t\treturn right_height+1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.\n\n Your code should pass these tests:\n\n[\"assert change_date_format('2026-01-02')=='02-01-2026'\", \"assert change_date_format('2021-01-04')=='04-01-2021'\", \"assert change_date_format('2030-06-06')=='06-06-2030'\"]\n[BEGIN]\n", "completion": "import re\r\ndef change_date_format(dt):\r\n return re.sub(r'(\\d{4})-(\\d{1,2})-(\\d{1,2})', '\\\\3-\\\\2-\\\\1', dt)\r\n return change_date_format(dt)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count repeated items of a tuple.\n\n Your code should pass these tests:\n\n['assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3', 'assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2', 'assert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4']\n[BEGIN]\n", "completion": "def count_tuplex(tuplex,value): \r\n count = tuplex.count(value)\r\n return count\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that matches a string that has an a followed by zero or more b's by using regex.\n\n Your code should pass these tests:\n\n['assert text_match(\"msb\") == \\'Not matched!\\'', 'assert text_match(\"a0c\") == \\'Found a match!\\'', 'assert text_match(\"abbc\") == \\'Found a match!\\'']\n[BEGIN]\n", "completion": "import re\r\ndef text_match(text):\r\n patterns = 'ab*?'\r\n if re.search(patterns, text):\r\n return ('Found a match!')\r\n else:\r\n return ('Not matched!')\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the sum of series 1\u00b3+2\u00b3+3\u00b3+\u2026.+n\u00b3.\n\n Your code should pass these tests:\n\n['assert sum_series(7)==784', 'assert sum_series(5)==225', 'assert sum_series(15)==14400']\n[BEGIN]\n", "completion": "import math \r\ndef sum_series(number):\r\n total = 0\r\n total = math.pow((number * (number + 1)) /2, 2)\r\n return total\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove duplicate words from a given list of strings.\n\n Your code should pass these tests:\n\n['assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\"])==[\\'Python\\', \\'Exercises\\', \\'Practice\\', \\'Solution\\']', 'assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"Java\"])==[\\'Python\\', \\'Exercises\\', \\'Practice\\', \\'Solution\\', \\'Java\\']', 'assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"C++\",\"C\",\"C++\"])==[\\'Python\\', \\'Exercises\\', \\'Practice\\', \\'Solution\\',\\'C++\\',\\'C\\']']\n[BEGIN]\n", "completion": "def remove_duplic_list(l):\r\n temp = []\r\n for x in l:\r\n if x not in temp:\r\n temp.append(x)\r\n return temp\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert camel case string to snake case string by using regex.\n\n Your code should pass these tests:\n\n[\"assert camel_to_snake('GoogleAssistant') == 'google_assistant'\", \"assert camel_to_snake('ChromeCast') == 'chrome_cast'\", \"assert camel_to_snake('QuadCore') == 'quad_core'\"]\n[BEGIN]\n", "completion": "import re\r\ndef camel_to_snake(text):\r\n str1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', text)\r\n return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', str1).lower()\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the nth delannoy number.\n\n Your code should pass these tests:\n\n['assert dealnnoy_num(3, 4) == 129', 'assert dealnnoy_num(3, 3) == 63', 'assert dealnnoy_num(4, 5) == 681']\n[BEGIN]\n", "completion": "def dealnnoy_num(n, m): \r\n\tif (m == 0 or n == 0) : \r\n\t\treturn 1\r\n\treturn dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the sum of series 1\u00b2+2\u00b2+3\u00b2+\u2026.+n\u00b2.\n\n Your code should pass these tests:\n\n['assert series_sum(6)==91', 'assert series_sum(7)==140', 'assert series_sum(12)==650']\n[BEGIN]\n", "completion": "def series_sum(number):\r\n total = 0\r\n total = (number * (number + 1) * (2 * number + 1)) / 6\r\n return total\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to re-arrange the given tuples based on the given ordered list.\n\n Your code should pass these tests:\n\n['assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]', 'assert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]', 'assert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)], [2, 5, 3, 6]) == [(2, 4), (5, 7), (3, 8), (6, 3)]']\n[BEGIN]\n", "completion": "def re_arrange_tuples(test_list, ord_list):\r\n temp = dict(test_list)\r\n res = [(key, temp[key]) for key in ord_list]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the most common character in a given string.\n\n Your code should pass these tests:\n\n['assert max_char(\"hello world\")==(\\'l\\')', 'assert max_char(\"hello \")==(\\'l\\')', 'assert max_char(\"python pr\")==(\\'p\\')']\n[BEGIN]\n", "completion": "from collections import Counter \r\ndef max_char(str1):\r\n temp = Counter(str1) \r\n max_char = max(temp, key = temp.get)\r\n return max_char\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find three closest elements from three sorted arrays.\n\n Your code should pass these tests:\n\n['assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)', 'assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)', 'assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)']\n[BEGIN]\n", "completion": "import sys \r\n\r\ndef find_closet(A, B, C, p, q, r): \r\n\tdiff = sys.maxsize \r\n\tres_i = 0\r\n\tres_j = 0\r\n\tres_k = 0\r\n\ti = 0\r\n\tj = 0\r\n\tk = 0\r\n\twhile(i < p and j < q and k < r): \r\n\t\tminimum = min(A[i], min(B[j], C[k])) \r\n\t\tmaximum = max(A[i], max(B[j], C[k])); \r\n\t\tif maximum-minimum < diff: \r\n\t\t\tres_i = i \r\n\t\t\tres_j = j \r\n\t\t\tres_k = k \r\n\t\t\tdiff = maximum - minimum; \r\n\t\tif diff == 0: \r\n\t\t\tbreak\r\n\t\tif A[i] == minimum: \r\n\t\t\ti = i+1\r\n\t\telif B[j] == minimum: \r\n\t\t\tj = j+1\r\n\t\telse: \r\n\t\t\tk = k+1\r\n\treturn A[res_i],B[res_j],C[res_k]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort a list of dictionaries using lambda function.\n\n Your code should pass these tests:\n\n[\"assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]\", \"assert sorted_models([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])==([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])\", \"assert sorted_models([{'make':'micromax','model':40,'color':'grey'},{'make':'poco','model':60,'color':'blue'}])==([{'make':'poco','model':60,'color':'blue'},{'make':'micromax','model':40,'color':'grey'}])\"]\n[BEGIN]\n", "completion": "def sorted_models(models):\r\n sorted_models = sorted(models, key = lambda x: x['color'])\r\n return sorted_models\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort the given array by using heap sort.\n\n Your code should pass these tests:\n\n['assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]', 'assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]', 'assert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]']\n[BEGIN]\n", "completion": "def heap_sort(arr):\r\n heapify(arr) \r\n end = len(arr) - 1\r\n while end > 0:\r\n arr[end], arr[0] = arr[0], arr[end]\r\n shift_down(arr, 0, end - 1)\r\n end -= 1\r\n return arr\r\n\r\ndef heapify(arr):\r\n start = len(arr) // 2\r\n while start >= 0:\r\n shift_down(arr, start, len(arr) - 1)\r\n start -= 1\r\ndef shift_down(arr, start, end):\r\n root = start\r\n while root * 2 + 1 <= end:\r\n child = root * 2 + 1\r\n if child + 1 <= end and arr[child] < arr[child + 1]:\r\n child += 1\r\n if child <= end and arr[root] < arr[child]:\r\n arr[root], arr[child] = arr[child], arr[root]\r\n root = child\r\n else:\r\n return\r\n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to count the elements in a list until an element is a tuple.\n\n Your code should pass these tests:\n\n['assert count_elim([10,20,30,(10,20),40])==3', 'assert count_elim([10,(20,30),(10,20),40])==1', 'assert count_elim([(10,(20,30,(10,20),40))])==0']\n[BEGIN]\n", "completion": "def count_elim(num):\r\n count_elim = 0\r\n for n in num:\r\n if isinstance(n, tuple):\r\n break\r\n count_elim += 1\r\n return count_elim\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to check if any list element is present in the given list.\n\n Your code should pass these tests:\n\n['assert check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) == True', 'assert check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) == True', 'assert check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) == False']\n[BEGIN]\n", "completion": "def check_element(test_tup, check_list):\r\n res = False\r\n for ele in check_list:\r\n if ele in test_tup:\r\n res = True\r\n break\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to combine two given sorted lists using heapq module.\n\n Your code should pass these tests:\n\n['assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]', 'assert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11])==[1,2,3,5,5,6,7,8,9,11]', 'assert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]']\n[BEGIN]\n", "completion": "from heapq import merge\r\ndef combine_lists(num1,num2):\r\n combine_lists=list(merge(num1, num2))\r\n return combine_lists\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to separate and print the numbers and their position of a given string.\n\n Your code should pass these tests:\n\n['assert num_position(\"there are 70 flats in this apartment\")==10', 'assert num_position(\"every adult have 32 teeth\")==17', 'assert num_position(\"isha has 79 chocolates in her bag\")==9']\n[BEGIN]\n", "completion": "import re\r\ndef num_position(text):\r\n for m in re.finditer(\"\\d+\", text):\r\n return m.start()\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert the given tuples into set.\n\n Your code should pass these tests:\n\n[\"assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}\", \"assert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}\", \"assert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'}\"]\n[BEGIN]\n", "completion": "def tuple_to_set(t):\r\n s = set(t)\r\n return (s) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the most common elements and their counts of a specified text.\n\n Your code should pass these tests:\n\n[\"assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)] \", \"assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]\", \"assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]\"]\n[BEGIN]\n", "completion": "from collections import Counter \r\ndef most_common_elem(s,a):\r\n most_common_elem=Counter(s).most_common(a)\r\n return most_common_elem\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the length of the shortest word.\n\n Your code should pass these tests:\n\n['assert len_log([\"win\",\"lose\",\"great\"]) == 3', 'assert len_log([\"a\",\"ab\",\"abc\"]) == 1', 'assert len_log([\"12\",\"12\",\"1234\"]) == 2']\n[BEGIN]\n", "completion": "def len_log(list1):\r\n min=len(list1[0])\r\n for i in list1:\r\n if len(i)<min:\r\n min=len(i)\r\n return min\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to get an item of a tuple.\n\n Your code should pass these tests:\n\n['assert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),3)==(\\'e\\')', 'assert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),-4)==(\\'u\\')', 'assert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),-3)==(\\'r\\')']\n[BEGIN]\n", "completion": "def get_item(tup1,index):\r\n item = tup1[index]\r\n return item\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to sort the given tuple list basis the total digits in tuple.\n\n Your code should pass these tests:\n\n[\"assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'\", \"assert sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234, 334)]'\", \"assert sort_list([(34, 4, 61, 723), (1, 2), (145,), (134, 23)] ) == '[(1, 2), (145,), (134, 23), (34, 4, 61, 723)]'\"]\n[BEGIN]\n", "completion": "def count_digs(tup):\r\n return sum([len(str(ele)) for ele in tup ]) \r\ndef sort_list(test_list):\r\n test_list.sort(key = count_digs)\r\n return (str(test_list))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to display sign of the chinese zodiac for given year.\n\n Your code should pass these tests:\n\n[\"assert chinese_zodiac(1997)==('Ox')\", \"assert chinese_zodiac(1998)==('Tiger')\", \"assert chinese_zodiac(1994)==('Dog')\"]\n[BEGIN]\n", "completion": "def chinese_zodiac(year):\r\n if (year - 2000) % 12 == 0:\r\n sign = 'Dragon'\r\n elif (year - 2000) % 12 == 1:\r\n sign = 'Snake'\r\n elif (year - 2000) % 12 == 2:\r\n sign = 'Horse'\r\n elif (year - 2000) % 12 == 3:\r\n sign = 'sheep'\r\n elif (year - 2000) % 12 == 4:\r\n sign = 'Monkey'\r\n elif (year - 2000) % 12 == 5:\r\n sign = 'Rooster'\r\n elif (year - 2000) % 12 == 6:\r\n sign = 'Dog'\r\n elif (year - 2000) % 12 == 7:\r\n sign = 'Pig'\r\n elif (year - 2000) % 12 == 8:\r\n sign = 'Rat'\r\n elif (year - 2000) % 12 == 9:\r\n sign = 'Ox'\r\n elif (year - 2000) % 12 == 10:\r\n sign = 'Tiger'\r\n else:\r\n sign = 'Hare'\r\n return sign\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum of similar indices in two lists of tuples.\n\n Your code should pass these tests:\n\n['assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]', 'assert max_similar_indices([(3, 5), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]', 'assert max_similar_indices([(4, 6), (8, 9), (7, 3)],[(7, 6), (10, 12), (10, 16)]) == [(7, 6), (10, 12), (10, 16)]']\n[BEGIN]\n", "completion": "def max_similar_indices(test_list1, test_list2):\r\n res = [(max(x[0], y[0]), max(x[1], y[1]))\r\n for x, y in zip(test_list1, test_list2)]\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to compute the value of ncr mod p.\n\n Your code should pass these tests:\n\n['assert nCr_mod_p(10, 2, 13) == 6', 'assert nCr_mod_p(11, 3, 14) == 11', 'assert nCr_mod_p(18, 14, 19) == 1']\n[BEGIN]\n", "completion": "def nCr_mod_p(n, r, p): \r\n\tif (r > n- r): \r\n\t\tr = n - r \r\n\tC = [0 for i in range(r + 1)] \r\n\tC[0] = 1 \r\n\tfor i in range(1, n + 1): \r\n\t\tfor j in range(min(i, r), 0, -1): \r\n\t\t\tC[j] = (C[j] + C[j-1]) % p \r\n\treturn C[r] \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the minimun number of subsets with distinct elements.\n\n Your code should pass these tests:\n\n['assert subset([1, 2, 3, 4],4) == 1', 'assert subset([5, 6, 9, 3, 4, 3, 4],7) == 2', 'assert subset([1, 2, 3 ],3) == 1']\n[BEGIN]\n", "completion": "def subset(ar, n): \r\n res = 0\r\n ar.sort() \r\n for i in range(0, n) : \r\n count = 1\r\n for i in range(n - 1): \r\n if ar[i] == ar[i + 1]: \r\n count+=1\r\n else: \r\n break \r\n res = max(res, count) \r\n return res \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function that gives profit amount if the given amount has profit else return none.\n\n Your code should pass these tests:\n\n['assert profit_amount(1500,1200)==300', 'assert profit_amount(100,200)==None', 'assert profit_amount(2000,5000)==None']\n[BEGIN]\n", "completion": "def profit_amount(actual_cost,sale_amount): \r\n if(actual_cost > sale_amount):\r\n amount = actual_cost - sale_amount\r\n return amount\r\n else:\r\n return None\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find out, if the given number is abundant.\n\n Your code should pass these tests:\n\n['assert is_abundant(12)==True', 'assert is_abundant(13)==False', 'assert is_abundant(9)==False']\n[BEGIN]\n", "completion": "def is_abundant(n):\r\n fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])\r\n return fctrsum > n\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to split the given string at uppercase letters by using regex.\n\n Your code should pass these tests:\n\n['assert split_list(\"LearnToBuildAnythingWithGoogle\") == [\\'Learn\\', \\'To\\', \\'Build\\', \\'Anything\\', \\'With\\', \\'Google\\']', 'assert split_list(\"ApmlifyingTheBlack+DeveloperCommunity\") == [\\'Apmlifying\\', \\'The\\', \\'Black+\\', \\'Developer\\', \\'Community\\']', 'assert split_list(\"UpdateInTheGoEcoSystem\") == [\\'Update\\', \\'In\\', \\'The\\', \\'Go\\', \\'Eco\\', \\'System\\']']\n[BEGIN]\n", "completion": "import re\r\ndef split_list(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to get the position of rightmost set bit.\n\n Your code should pass these tests:\n\n['assert get_First_Set_Bit_Pos(12) == 3', 'assert get_First_Set_Bit_Pos(18) == 2', 'assert get_First_Set_Bit_Pos(16) == 5']\n[BEGIN]\n", "completion": "import math\r\ndef get_First_Set_Bit_Pos(n):\r\n return math.log2(n&-n)+1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert an integer into a roman numeral.\n\n Your code should pass these tests:\n\n['assert int_to_roman(1)==(\"I\")', 'assert int_to_roman(50)==(\"L\")', 'assert int_to_roman(4)==(\"IV\")']\n[BEGIN]\n", "completion": "def int_to_roman( num):\r\n val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1]\r\n syb = [\"M\", \"CM\", \"D\", \"CD\",\"C\", \"XC\", \"L\", \"XL\",\"X\", \"IX\", \"V\", \"IV\",\"I\"]\r\n roman_num = ''\r\n i = 0\r\n while num > 0:\r\n for _ in range(num // val[i]):\r\n roman_num += syb[i]\r\n num -= val[i]\r\n i += 1\r\n return roman_num\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the average of a list.\n\n Your code should pass these tests:\n\n['assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75', 'assert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75', 'assert Average([1,2,3]) == 2']\n[BEGIN]\n", "completion": "def Average(lst): \r\n return sum(lst) / len(lst) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to solve tiling problem.\n\n Your code should pass these tests:\n\n['assert get_noOfways(4)==3', 'assert get_noOfways(3)==2', 'assert get_noOfways(5)==5']\n[BEGIN]\n", "completion": "def get_noOfways(n):\r\n if (n == 0):\r\n return 0;\r\n if (n == 1):\r\n return 1; \r\n return get_noOfways(n - 1) + get_noOfways(n - 2);\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert a roman numeral to an integer.\n\n Your code should pass these tests:\n\n[\"assert roman_to_int('MMMCMLXXXVI')==3986\", \"assert roman_to_int('MMMM')==4000\", \"assert roman_to_int('C')==100\"]\n[BEGIN]\n", "completion": "def roman_to_int(s):\r\n rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\r\n int_val = 0\r\n for i in range(len(s)):\r\n if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:\r\n int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]\r\n else:\r\n int_val += rom_val[s[i]]\r\n return int_val\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find the sum of all even natural numbers within the range l and r.\n\n Your code should pass these tests:\n\n['assert sum_Even(2,5) == 6', 'assert sum_Even(3,8) == 18', 'assert sum_Even(4,6) == 10']\n[BEGIN]\n", "completion": "def sum_Natural(n): \r\n sum = (n * (n + 1)) \r\n return int(sum) \r\ndef sum_Even(l,r): \r\n return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2))) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to calculate the discriminant value.\n\n Your code should pass these tests:\n\n['assert discriminant_value(4,8,2)==(\"Two solutions\",32)', 'assert discriminant_value(5,7,9)==(\"no real solution\",-131)', 'assert discriminant_value(0,0,9)==(\"one solution\",0)']\n[BEGIN]\n", "completion": "def discriminant_value(x,y,z):\r\n discriminant = (y**2) - (4*x*z)\r\n if discriminant > 0:\r\n return (\"Two solutions\",discriminant)\r\n elif discriminant == 0:\r\n return (\"one solution\",discriminant)\r\n elif discriminant < 0:\r\n return (\"no real solution\",discriminant)\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to check whether the length of the word is even or not.\n\n Your code should pass these tests:\n\n['assert word_len(\"program\") == False', 'assert word_len(\"solution\") == True', 'assert word_len(\"data\") == True']\n[BEGIN]\n", "completion": "def word_len(s): \r\n s = s.split(' ') \r\n for word in s: \r\n if len(word)%2==0: \r\n return True \r\n else:\r\n return False\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to convert camel case string to snake case string.\n\n Your code should pass these tests:\n\n[\"assert camel_to_snake('PythonProgram')==('python_program')\", \"assert camel_to_snake('pythonLanguage')==('python_language')\", \"assert camel_to_snake('ProgrammingLanguage')==('programming_language')\"]\n[BEGIN]\n", "completion": "def camel_to_snake(text):\r\n import re\r\n str1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', text)\r\n return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', str1).lower()\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to remove an empty tuple from a list of tuples.\n\n Your code should pass these tests:\n\n[\"assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd'] \", 'assert remove_empty([(), (), (\\'\\',), (\"python\"), (\"program\")])==[(\\'\\',), (\"python\"), (\"program\")] ', 'assert remove_empty([(), (), (\\'\\',), (\"java\")])==[(\\'\\',),(\"java\") ] ']\n[BEGIN]\n", "completion": "def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]\r\n tuple1 = [t for t in tuple1 if t]\r\n return tuple1\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to accept the strings which contains all vowels.\n\n Your code should pass these tests:\n\n['assert check(\"SEEquoiaL\") == \\'accepted\\'', 'assert check(\\'program\\') == \"not accepted\"', 'assert check(\\'fine\\') == \"not accepted\"']\n[BEGIN]\n", "completion": "def check(string): \r\n if len(set(string).intersection(\"AEIOUaeiou\"))>=5: \r\n return ('accepted') \r\n else: \r\n return (\"not accepted\") \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to find maximum possible value for the given periodic function.\n\n Your code should pass these tests:\n\n['assert floor_Max(11,10,9) == 9', 'assert floor_Max(5,7,4) == 2', 'assert floor_Max(2,2,1) == 1']\n[BEGIN]\n", "completion": "def floor_Max(A,B,N):\r\n x = min(B - 1,N)\r\n return (A*x) // B\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to join the tuples if they have similar initial elements.\n\n Your code should pass these tests:\n\n['assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]', 'assert join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]', 'assert join_tuples([(7, 8), (7, 9), (8, 10), (8, 12), (9, 15)] ) == [(7, 8, 9), (8, 10, 12), (9, 15)]']\n[BEGIN]\n", "completion": "def join_tuples(test_list):\r\n res = []\r\n for sub in test_list:\r\n if res and res[-1][0] == sub[0]:\r\n res[-1].extend(sub[1:])\r\n else:\r\n res.append([ele for ele in sub])\r\n res = list(map(tuple, res))\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find minimum of two numbers.\n\n Your code should pass these tests:\n\n['assert min_of_two(10,20)==10', 'assert min_of_two(19,15)==15', 'assert min_of_two(-10,-20)==-20']\n[BEGIN]\n", "completion": "def min_of_two( x, y ):\r\n if x < y:\r\n return x\r\n return y\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the maximum number of segments of lengths a, b and c that can be formed from n.\n\n Your code should pass these tests:\n\n['assert maximum_segments(7, 5, 2, 5) == 2', 'assert maximum_segments(17, 2, 1, 3) == 17', 'assert maximum_segments(18, 16, 3, 6) == 6']\n[BEGIN]\n", "completion": "def maximum_segments(n, a, b, c) : \r\n\tdp = [-1] * (n + 10) \r\n\tdp[0] = 0\r\n\tfor i in range(0, n) : \r\n\t\tif (dp[i] != -1) : \r\n\t\t\tif(i + a <= n ): \r\n\t\t\t\tdp[i + a] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + a]) \r\n\t\t\tif(i + b <= n ): \r\n\t\t\t\tdp[i + b] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + b]) \r\n\t\t\tif(i + c <= n ): \r\n\t\t\t\tdp[i + c] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + c]) \r\n\treturn dp[n]\n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to concatenate the given two tuples to a nested tuple.\n\n Your code should pass these tests:\n\n['assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)', 'assert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)', 'assert concatenate_nested((4, 5), (6, 8)) == (4, 5, 6, 8)']\n[BEGIN]\n", "completion": "def concatenate_nested(test_tup1, test_tup2):\r\n res = test_tup1 + test_tup2\r\n return (res) \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a python function to left rotate the string.\n\n Your code should pass these tests:\n\n['assert left_rotate(\"python\",2) == \"thonpy\" ', 'assert left_rotate(\"bigdata\",3 ) == \"databig\" ', 'assert left_rotate(\"hadoop\",1 ) == \"adooph\" ']\n[BEGIN]\n", "completion": "def left_rotate(s,d):\r\n tmp = s[d : ] + s[0 : d]\r\n return tmp \n[DONE]"} | |
| {"prompt": "You are an expert Python programmer, and here is your task:\nWrite a function to find the minimum total path sum in the given triangle.\n\n Your code should pass these tests:\n\n['assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6', 'assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10 ', 'assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9']\n[BEGIN]\n", "completion": "def min_sum_path(A): \r\n\tmemo = [None] * len(A) \r\n\tn = len(A) - 1\r\n\tfor i in range(len(A[n])): \r\n\t\tmemo[i] = A[n][i] \r\n\tfor i in range(len(A) - 2, -1,-1): \r\n\t\tfor j in range( len(A[i])): \r\n\t\t\tmemo[j] = A[i][j] + min(memo[j], \r\n\t\t\t\t\t\t\t\t\tmemo[j + 1]) \r\n\treturn memo[0]\n[DONE]"} | |