|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the longest chain which can be formed from the given set of pairs.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the first repeated character in a given string.\n\n### Response:","output":"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\""} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to get a lucid number smaller than or equal to n.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to reverse words in a given string.\n\n### Response:","output":"def reverse_words(s):\r\n return ' '.join(reversed(s.split()))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given integer is a prime number.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert degrees to radians.\n\n### Response:","output":"import math\r\ndef radian_degree(degree):\r\n radian = degree*(math.pi\/180)\r\n return radian"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find nth bell number.\n\n### Response:","output":"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] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find minimum possible value for the given periodic function.\n\n### Response:","output":"def floor_Min(A,B,N):\r\n x = max(B - 1,N)\r\n return (A*x) \/\/ B"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to remove the k'th element from a given list.\n\n### Response:","output":"def remove_kth_element(list1, L):\r\n return list1[:L-1] + list1[L:]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum of nth column from the given tuple list.\n\n### Response:","output":"def max_of_nth(test_list, N):\r\n res = max([sub[N] for sub in test_list])\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to merge the first and last elements separately in a list of lists.\n\n### Response:","output":"def merge(lst): \r\n return [list(ele) for ele in list(zip(*lst))] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum value in record list as tuple attribute in the given tuple list.\n\n### Response:","output":"def maximum_value(test_list):\r\n res = [(key, max(lst)) for key, lst in test_list]\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the cumulative sum of all the values that are present in the given tuple list.\n\n### Response:","output":"def cummulative_sum(test_list):\r\n res = sum(map(sum, test_list))\r\n return (res)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find average value of the numbers in a given tuple of tuples.\n\n### Response:","output":"def average_tuple(nums):\r\n result = [sum(x) \/ len(x) for x in zip(*nums)]\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to perfom the modulo of tuple elements in the given two tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to divide two lists using map and lambda function.\n\n### Response:","output":"def div_list(nums1,nums2):\r\n result = map(lambda x, y: x \/ y, nums1, nums2)\r\n return list(result)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to move all the numbers in it to the given string.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the largest subset where each pair is divisible.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to increment the numeric values in the given strings by k.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the median of two sorted arrays of same size.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the n-th power of individual elements in a list using lambda function.\n\n### Response:","output":"def nth_nums(nums,n):\r\n nth_nums = list(map(lambda x: x ** n, nums))\r\n return nth_nums"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to convert the given string to upper case.\n\n### Response:","output":"def is_upper(string):\r\n return (string.upper())"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to interchange first and last elements in a given list.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the largest triangle that can be inscribed in the semicircle.\n\n### Response:","output":"def triangle_area(r) : \r\n if r < 0 : \r\n return -1\r\n return r * r "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the smallest missing number from the given array.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find even numbers from a mixed list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract all the adjacent coordinates of the given coordinate tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to replace whitespaces with an underscore and vice versa in a given string by using regex.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to move all zeroes to the end of the given list.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of xor of all pairs of numbers in the given array.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of fourth power of first n even natural numbers.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to push all values into a heap and then pop off the smallest values one at a time.\n\n### Response:","output":"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))]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check if roots of a quadratic equation are reciprocal of each other or not.\n\n### Response:","output":"def Check_Solution(a,b,c): \r\n if (a == c): \r\n return (\"Yes\"); \r\n else: \r\n return (\"No\"); "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given amount has no profit and no loss\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate wind chill index.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove the parenthesis area in a string.\n\n### Response:","output":"import re\r\ndef remove_parenthesis(items):\r\n for item in items:\r\n return (re.sub(r\" ?\\([^)]+\\)\", \"\", item))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the nth nonagonal number.\n\n### Response:","output":"def is_nonagonal(n): \r\n\treturn int(n * (7 * n - 5) \/ 2) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove similar rows from the given tuple matrix.\n\n### Response:","output":"def remove_similar_row(test_list):\r\n res = set(sorted([tuple(sorted(set(sub))) for sub in test_list]))\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a word containing 'z', not at the start or end of the word.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to reverse an array upto a given position.\n\n### Response:","output":"def reverse_Array_Upto_K(input, k): \r\n return (input[k-1::-1] + input[k:]) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the product of it\u2019s kth index in the given tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count number of cubes of size k in a cube of size n.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to split a string at uppercase letters.\n\n### Response:","output":"import re\r\ndef split_upperstring(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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])))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to calculate the sum of the numbers in a list between the indices of a specified range.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given two arrays are equal or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if one tuple is a subset of another tuple.\n\n### Response:","output":"def check_subset(test_tup1, test_tup2):\r\n res = set(test_tup2).issubset(test_tup1)\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to group a sequence of key-value pairs into a dictionary of lists using collections module.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the perimeter of a rectangle.\n\n### Response:","output":"def rectangle_perimeter(l,b):\r\n perimeter=2*(l+b)\r\n return perimeter"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of fifth power of n natural numbers.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the minimum sum of absolute differences of two arrays.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the first digit in factorial of a given number.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the item with maximum occurrences in a given list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to print duplicants from a list of integers.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to choose points from two ranges such that no point lies in both the ranges.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum sum that can be formed which has no three consecutive elements present.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort a list in a dictionary.\n\n### Response:","output":"def sorted_dict(dict1):\r\n sorted_dict = {x: sorted(y) for x, y in dict1.items()}\r\n return sorted_dict"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the largest possible value of k such that k modulo x is y.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the average of even numbers till a given even number.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to shift first element to the end of given list.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count occurrence of a character in a string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count number of vowels in the string.\n\n### Response:","output":"def Check_Vow(string, vowels): \r\n final = [each for each in string if each in vowels] \r\n return(len(final)) \r\n"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to replace multiple occurence of character by single.\n\n### Response:","output":"import re \r\ndef replace(string, char): \r\n pattern = char + '{2,}'\r\n string = re.sub(pattern, char, string) \r\n return string "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given ip address is valid or not using regex.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether a sequence of numbers has a decreasing trend or not.\n\n### Response:","output":"def decreasing_trend(nums):\r\n if (sorted(nums)== nums):\r\n return True\r\n else:\r\n return False"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to set the right most unset bit.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find maximum of three numbers.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to convert a list of multiple integers into a single integer.\n\n### Response:","output":"def convert(list): \r\n s = [str(i) for i in list] \r\n res = int(\"\".join(s)) \r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove duplicate words from a given string using collections module.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to add two integers. however, if the sum is between the given range it will return 20.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove everything except alphanumeric characters from the given string by using regex.\n\n### Response:","output":"import re\r\ndef remove_extra_char(text1):\r\n pattern = re.compile('[\\W_]+')\r\n return (pattern.sub('', text1))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the triangle is valid or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to remove spaces from a given string.\n\n### Response:","output":"def remove_spaces(str1):\r\n str1 = str1.replace(' ','')\r\n return str1"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to access dictionary key\u2019s element by index.\n\n### Response:","output":"def access_key(ditionary,key):\r\n return list(ditionary)[key]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether a sequence of numbers has an increasing trend or not.\n\n### Response:","output":"def increasing_trend(nums):\r\n if (sorted(nums)== nums):\r\n return True\r\n else:\r\n return False"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the smallest prime divisor of a number.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to multiply two lists using map and lambda function.\n\n### Response:","output":"def mul_list(nums1,nums2):\r\n result = map(lambda x, y: x * y, nums1, nums2)\r\n return list(result)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given number can be represented by sum of two squares or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count occurences of a character in a repeated string.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find sum of prime numbers between 1 to n.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the frequency of each element in the given list.\n\n### Response:","output":"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))) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the greatest common divisor (gcd) of two integers by using recursion.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to get the length of a complex number.\n\n### Response:","output":"import cmath\r\ndef len_complex(a,b):\r\n cn=complex(a,b)\r\n length=abs(cn)\r\n return length"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to multiply consecutive numbers of a given list.\n\n### Response:","output":"def mul_consecutive_nums(nums):\r\n result = [b*a for a, b in zip(nums[:-1], nums[1:])]\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to group the 1st elements on the basis of 2nd elements in the given tuple list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the last two digits in factorial of a given number.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove multiple spaces in a string by using regex.\n\n### Response:","output":"import re\r\ndef remove_multiple_spaces(text1):\r\n return (re.sub(' +',' ',text1))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract unique values from the given dictionary values.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to zip two given lists of lists.\n\n### Response:","output":"def zip_list(list1,list2): \r\n result = list(map(list.__add__, list1, list2)) \r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find number of even elements in the given list using lambda function.\n\n### Response:","output":"def count_even(array_nums):\r\n count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))\r\n return count_even"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the minimum number of swaps required to convert one binary string to another.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the number of elements in a list which are within a specific range.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the equilibrium index of the given array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the minimum number of elements that should be removed such that amax-amin<=k.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given key is present in the dictionary or not.\n\n### Response:","output":"def is_key_present(d,x):\r\n if x in d:\r\n return True\r\n else:\r\n return False"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the harmonic sum of n-1.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort a list of lists by length and value.\n\n### Response:","output":"def sort_sublists(list1):\r\n list1.sort() \r\n list1.sort(key=len)\r\n return list1"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find whether an array is subset of another array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the total set bits from 1 to n.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to convert a string to a list.\n\n### Response:","output":"def Convert(string): \r\n li = list(string.split(\" \")) \r\n return li "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count unique keys for each value present in the tuple.\n\n### Response:","output":"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)) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to access the initial and last data of the given tuple record.\n\n### Response:","output":"def front_and_rear(test_tup):\r\n res = (test_tup[0], test_tup[-1])\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove duplicates from a list of lists.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given tuple contains all valid values or not.\n\n### Response:","output":"def check_valid(test_tup):\r\n res = not any(map(lambda ele: not ele, test_tup))\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of distinct power of prime factor of given number.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert the given string of integers into a tuple.\n\n### Response:","output":"def str_to_tuple(test_str):\r\n res = tuple(map(int, test_str.split(', ')))\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the perimeter of a rombus.\n\n### Response:","output":"def rombus_perimeter(a):\r\n perimeter=4*a\r\n return perimeter"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the standard deviation.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to create a list taking alternate elements from another given list.\n\n### Response:","output":"def alternate_elements(list1):\r\n result=[]\r\n for item in list1[::2]:\r\n result.append(item)\r\n return result "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an a followed by zero or more b's.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to add a dictionary to the tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to filter the height and width of students which are stored in a dictionary.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the same pair in two given lists using map function.\n\n### Response:","output":"from operator import eq\r\ndef count_same_pair(nums1, nums2):\r\n result = sum(map(eq, nums1, nums2))\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the sum of all digits of the base to the specified power.\n\n### Response:","output":"def power_base_sum(base, power):\r\n return sum([int(i) for i in str(pow(base, power))])"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract values between quotation marks of the given string by using regex.\n\n### Response:","output":"import re\r\ndef extract_quotation(text1):\r\n return (re.findall(r'\"(.*?)\"', text1))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to multiply the adjacent elements of the given tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove all characters except letters and numbers using regex\n\n### Response:","output":"import re \r\ndef remove_char(S):\r\n result = re.sub('[\\W_]+', '', S) \r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sum elements in two lists.\n\n### Response:","output":"def sum_list(lst1,lst2):\r\n res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] \r\n return res_list"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to add two lists using map and lambda function.\n\n### Response:","output":"def add_list(nums1,nums2):\r\n result = map(lambda x, y: x + y, nums1, nums2)\r\n return list(result)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove consecutive duplicates of a given list.\n\n### Response:","output":"from itertools import groupby\r\ndef consecutive_duplicates(nums):\r\n return [key for key, group in groupby(nums)] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the lateral surface area of a cone.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to replace all occurrences of spaces, commas, or dots with a colon.\n\n### Response:","output":"import re\r\ndef replace_specialchar(text):\r\n return (re.sub(\"[ ,.]\", \":\", text))\r"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the index of the first occurrence of a given number in a sorted array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find sum of products of all possible subarrays.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to toggle bits of the number except the first and the last bit.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to locate the left insertion point for a specified value in sorted order.\n\n### Response:","output":"import bisect\r\ndef left_insertion(a, x):\r\n i = bisect.bisect_left(a, x)\r\n return i"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given string is starting with a vowel or not using regex.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the geometric sum of n-1.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the index of smallest triangular number with n digits.\n\n### Response:","output":"import math \r\ndef find_Index(n): \r\n x = math.sqrt(2 * math.pow(10,(n - 1))); \r\n return round(x); "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert the given tuple to a key-value dictionary using adjacent elements.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether all the characters are same or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to caluclate the area of a tetrahedron.\n\n### Response:","output":"import math\r\ndef area_tetrahedron(side):\r\n area = math.sqrt(3)*(side*side)\r\n return area"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to rotate a given list by specified number of items to the right direction.\n\n### Response:","output":"def rotate_right(list1,m,n):\r\n result = list1[-(m):]+list1[:-(n)]\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given tuple has any none value or not.\n\n### Response:","output":"def check_none(test_tup):\r\n res = any(map(lambda ele: ele is None, test_tup))\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find numbers within a given range where every number is divisible by every digit it contains.\n\n### Response:","output":"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)))]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find area of a sector.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the longest common subsequence for the given three string sequence.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to put spaces between words starting with capital letters in a given string by using regex.\n\n### Response:","output":"import re\r\ndef capital_words_spaces(str1):\r\n return re.sub(r\"(\\w)([A-Z])\", r\"\\1 \\2\", str1)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort a given list of strings of numbers numerically.\n\n### Response:","output":"def sort_numeric_strings(nums_str):\r\n result = [int(x) for x in nums_str]\r\n result.sort()\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to add the given tuple to the given list.\n\n### Response:","output":"def add_tuple(test_list, test_tup):\r\n test_list += test_tup\r\n return (test_list) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given array represents min heap or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the nth jacobsthal number.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find minimum k records from tuple list.\n\n### Response:","output":"def min_k(test_list, K):\r\n res = sorted(test_list, key = lambda x: x[1])[:K]\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find common index elements from three lists.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the second smallest number in a list.\n\n### Response:","output":"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] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an a followed by zero or one 'b'.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the pairs of reverse strings in the given string list.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count number of unique lists within a list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check a decimal with a precision of 2.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether an array contains only one distinct element or not.\n\n### Response:","output":"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')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to caluclate arc length of an angle.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given month number contains 30 days or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the minimum difference between any two elements in a given array.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count numeric values in a given string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find nth polite number.\n\n### Response:","output":"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))) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to iterate over all pairs of consecutive items in a given list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of pairs whose sum is equal to \u2018sum\u2019.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check for odd parity of a given number.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to get the difference between two lists.\n\n### Response:","output":"def Diff(li1,li2):\r\n return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1))))\r\n "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of fourth power of first n odd natural numbers.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given expression is balanced or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove all the words with k length in the given string.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the occurrence and position of the substrings within a string.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the string is a valid email address or not using regex.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether every odd index contains odd numbers of a given list.\n\n### Response:","output":"def odd_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count those characters which have vowels as their neighbors in the given string.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of non-repeated elements in a given array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to pack consecutive duplicates of a given list elements into sublists.\n\n### Response:","output":"from itertools import groupby\r\ndef pack_consecutive_duplicates(list1):\r\n return [list(group) for key, group in groupby(list1)]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the number of unique lists within a list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the combinations of sums with tuples in the given tuple list.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the count of divisors is even or odd.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of all odd length subarrays.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert rgb color to hsv color.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the product of first even and odd number of a given list.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert tuple string to integer tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to locate the right insertion point for a specified value in sorted order.\n\n### Response:","output":"import bisect\r\ndef right_insertion(a, x):\r\n i = bisect.bisect_right(a, x)\r\n return i"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an a followed by three 'b'.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to create a new tuple from the given string and list.\n\n### Response:","output":"def new_tuple(test_list, test_str):\r\n res = tuple(test_list + [test_str])\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the perimeter of a regular polygon.\n\n### Response:","output":"from math import tan, pi\r\ndef perimeter_polygon(s,l):\r\n perimeter = s*l\r\n return perimeter"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether every even index contains even numbers of a given list.\n\n### Response:","output":"def even_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove the nested record from the given tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of lists in a given number of lists.\n\n### Response:","output":"def count_list(input_list): \r\n return len(input_list)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the last position of an element in a sorted array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an 'a' followed by anything, ending in 'b'.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the n - cheap price items from a given dataset using heap queue algorithm.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite function to find the sum of all items in the given dictionary.\n\n### Response:","output":"def return_sum(dict):\r\n sum = 0\r\n for i in dict.values():\r\n sum = sum + i\r\n return sum"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of all odd natural numbers within the range l and r.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of an array.\n\n### Response:","output":"def _sum(arr): \r\n sum=0\r\n for i in arr: \r\n sum = sum + i \r\n return(sum) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to left rotate the bits of a given number.\n\n### Response:","output":"INT_BITS = 32\r\ndef left_Rotate(n,d): \r\n return (n << d)|(n >> (INT_BITS - d)) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove all whitespaces from a string.\n\n### Response:","output":"import re\r\ndef remove_all_spaces(text):\r\n return (re.sub(r'\\s+', '',text))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of equal numbers from three given integers.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of rotations required to generate a sorted array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given number is a perfect square or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the product of numbers is even or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the list in a list of lists whose sum of elements is the highest.\n\n### Response:","output":"def max_sum_list(lists):\r\n return max(lists, key=sum)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find maximum run of uppercase characters in the given string.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the first odd number in a given list of numbers.\n\n### Response:","output":"def first_odd(nums):\r\n first_odd = next((el for el in nums if el%2!=0),-1)\r\n return first_odd"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given tuples contain the k or not.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if each element of second tuple is smaller than its corresponding index in first tuple.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to iterate over elements repeating each as many times as its count.\n\n### Response:","output":"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())"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if two lists of tuples are identical or not.\n\n### Response:","output":"def check_identical(test_list1, test_list2):\r\n res = test_list1 == test_list2\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to abbreviate 'road' as 'rd.' in a given string.\n\n### Response:","output":"import re\r\ndef road_rd(street):\r\n return (re.sub('Road$', 'Rd.', street))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find length of the string.\n\n### Response:","output":"def string_length(str1):\r\n count = 0\r\n for char in str1:\r\n count += 1\r\n return count"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the area of a rombus.\n\n### Response:","output":"def rombus_area(p,q):\r\n area=(p*q)\/2\r\n return area"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to clear the values of the given tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find numbers divisible by m or n from a list of numbers using lambda function.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count lower case letters in a given string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the frequency of consecutive duplicate elements in a given list of numbers.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given month number contains 28 days or not.\n\n### Response:","output":"def check_monthnum_number(monthnum1):\r\n if monthnum1 == 2:\r\n return True\r\n else:\r\n return False"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to merge two dictionaries into a single expression.\n\n### Response:","output":"import collections as ct\r\ndef merge_dictionaries(dict1,dict2):\r\n merged_dict = dict(ct.ChainMap({}, dict1, dict2))\r\n return merged_dict"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to return true if the password is valid.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given string starts with a substring using regex.\n\n### Response:","output":"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\")"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to remove even numbers from a given list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to access multiple elements of specified index from a given list.\n\n### Response:","output":"def access_elements(nums, list_index):\r\n result = [nums[i] for i in list_index]\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the type of triangle from the given sides.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sum a specific column of a list in a given list of lists.\n\n### Response:","output":"def sum_column(list1, C):\r\n result = sum(row[C] for row in list1)\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count alphabets,digits and special charactes in a given string.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find out the second most repeated (or frequent) string in the given sequence.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to round up a number to specific digits.\n\n### Response:","output":"import math\r\ndef round_up(a, digits):\r\n n = 10**-digits\r\n return round(math.ceil(a \/ n) * n, digits)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count equal element pairs from the given array.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract the maximum numeric value from a string by using regex.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to get dictionary keys as a list.\n\n### Response:","output":"def get_key(dict): \r\n list = [] \r\n for key in dict.keys(): \r\n list.append(key) \r\n return list"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the slope of a line.\n\n### Response:","output":"def slope(x1,y1,x2,y2): \r\n return (float)(y2-y1)\/(x2-x1) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find length of the subarray having maximum sum.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the cube sum of first n odd natural numbers.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find minimum number swaps required to make two binary strings equal.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort the tuples alphabetically by the first item of each tuple.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.\n\n### Response:","output":"def Check_Solution(a,b,c): \r\n if b == 0: \r\n return (\"Yes\") \r\n else: \r\n return (\"No\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the number of inversions in the given array.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the number which occurs for odd number of times in the given array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the kth element in an array containing odd elements first and then even elements.\n\n### Response:","output":"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]; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the number of digits in factorial of a given number.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the minimum number of platforms required for a railway\/bus station.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to copy a list from a singleton tuple.\n\n### Response:","output":"def lcopy(xs):\n return xs[:]\n"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the area of a trapezium.\n\n### Response:","output":"def area_trapezium(base1,base2,height):\r\n area = 0.5 * (base1 + base2) * height\r\n return area"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find sum of all prime divisors of a given number.\n\n### Response:","output":"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] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if a triangle of positive area is possible with the given angles.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find sum of inverse of divisors.\n\n### Response:","output":"def Sum_of_Inverse_Divisors(N,Sum): \r\n ans = float(Sum)*1.0 \/float(N); \r\n return round(ans,2); "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to remove negative numbers from a list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find sum of odd factors of a number.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.\n\n### Response:","output":"import heapq as hq\r\ndef raw_heap(rawheap):\r\n hq.heapify(rawheap)\r\n return rawheap"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check for even parity of a given number.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find minimum adjacent swaps required to sort binary array.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to list out the list of given strings individually using map function.\n\n### Response:","output":"def listify_list(list1):\r\n result = list(map(list,list1)) \r\n return result "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count number of lists in a given list of lists and square the count.\n\n### Response:","output":"def count_list(input_list): \r\n return (len(input_list))**2"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to generate all sublists of a given list.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given string is ending with only alphanumeric characters or not using regex.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find all anagrams of a string in a given list of strings using lambda function.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the occurrences of n most common words in a given text.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find palindromes in a given list of strings using lambda function.\n\n### Response:","output":"def palindrome_lambda(texts):\r\n result = list(filter(lambda x: (x == \"\".join(reversed(x))), texts))\r\n return result"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to print n-times a list using map function.\n\n### Response:","output":"def ntimes_list(nums,n):\r\n result = map(lambda x:n*x, nums) \r\n return list(result)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check whether the given month name contains 31 days or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to add a minimum number such that the sum of array becomes even.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the length of the last word in a given string.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove sublists from a given list of lists, which are outside a given range.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.\n\n### Response:","output":"def sum_positivenum(nums):\r\n sum_positivenum = list(filter(lambda nums:nums>0,nums))\r\n return sum(sum_positivenum)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given strings are rotations of each other or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if a nested list is a subset of another nested list.\n\n### Response:","output":"def check_subset(list1,list2): \r\n return all(map(list1.__contains__,list2)) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to solve the fibonacci sequence using recursion.\n\n### Response:","output":"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)))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check if the string is a concatenation of another string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the minimum difference in the tuple pairs of given tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find lcm of two positive integers.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to sort the given string.\n\n### Response:","output":"def sort_String(str) : \r\n str = ''.join(sorted(str)) \r\n return (str) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if the given tuple contains only k elements.\n\n### Response:","output":"def check_tuples(test_tuple, K):\r\n res = all(ele in K for ele in test_tuple)\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find number of solutions in quadratic equation.\n\n### Response:","output":"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\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the sum of first even and odd number of a given list.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to caluclate perimeter of a parallelogram.\n\n### Response:","output":"def parallelogram_perimeter(b,h):\r\n perimeter=2*(b*h)\r\n return perimeter"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find numbers divisible by m and n from a list of numbers using lambda function.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether all the bits are within a given range or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the two given strings are isomorphic to each other or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to add all the numbers in a list and divide it with the length of the list.\n\n### Response:","output":"def sum_num(numbers):\r\n total = 0\r\n for x in numbers:\r\n total += x\r\n return total\/len(numbers) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given number is odd or not using bitwise operator.\n\n### Response:","output":"def is_odd(n) : \r\n if (n^1 == n-1) :\r\n return True; \r\n else :\r\n return False; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to substract the elements of the given nested tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to reverse each list in a given list of lists.\n\n### Response:","output":"def reverse_list_lists(lists):\r\n for l in lists:\r\n l.sort(reverse = True)\r\n return lists "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the index of an extra element present in one sorted array.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given two numbers have same number of digits or not.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove multiple spaces in a string.\n\n### Response:","output":"import re\r\ndef remove_spaces(text):\r\n return (re.sub(' +',' ',text))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to get the last element of each sublist.\n\n### Response:","output":"def Extract(lst): \r\n return [item[-1] for item in lst] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert the given string of float type into tuple.\n\n### Response:","output":"def float_to_tuple(test_str):\r\n res = tuple(map(float, test_str.split(', ')))\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum sum of subsequences of given array with no adjacent elements.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\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### Response:","output":"def last(n):\r\n return n[-1]\r\ndef sort_list_last(tuples):\r\n return sorted(tuples, key=last)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the word is present in a given sentence or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract specified number of elements from a given list, which follow each other continuously.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether an array can be sorted or not by picking only the corner elements.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function where a string will start with a specific number.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the smallest multiple of the first n numbers.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to combine two dictionaries by adding values for common keys.\n\n### Response:","output":"from collections import Counter\r\ndef add_dict(d1,d2):\r\n add_dict = Counter(d1) + Counter(d2)\r\n return add_dict"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to count the total unset bits from 1 to n.\n\n### Response:","output":"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; "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to return true if the given number is even else return false.\n\n### Response:","output":"def even_num(x):\r\n if x%2==0:\r\n return True\r\n else:\r\n return False"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of squares of binomial co-efficients.\n\n### Response:","output":"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)) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to extract year, month and date from a url by using regex.\n\n### Response:","output":"import re\r\ndef extract_date(url):\r\n return re.findall(r'\/(\\d{4})\/(\\d{1,2})\/(\\d{1,2})\/', url)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to print the first n lucky numbers.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the fixed point in the given array.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the previous palindrome of a specified number.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to validate a gregorian date.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.\n\n### Response:","output":"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])"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find ln, m lobb number.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check for a number at the end of a string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the given string is made up of two alternating characters or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to rearrange positive and negative numbers in a given array using lambda function.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find if there is a triplet in the array whose sum is equal to a given value.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the sequences of one upper case letter followed by lower case letters.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count coin change.\n\n### Response:","output":"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] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to multiply all items in the list.\n\n### Response:","output":"def multiply_list(items):\r\n tot = 1\r\n for x in items:\r\n tot *= x\r\n return tot"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove all tuples with all none values in the given tuple list.\n\n### Response:","output":"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)) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to perform chunking of tuples each of size n.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find a pair with the highest product from a given array of integers.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the length of the shortest string that has both str1 and str2 as subsequences.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find maximum of two numbers.\n\n### Response:","output":"def max_of_two( x, y ):\r\n if x > y:\r\n return x\r\n return y"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to calculate the product of all the numbers of a given tuple.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find n-th rencontres number.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the height of the given binary tree.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count repeated items of a tuple.\n\n### Response:","output":"def count_tuplex(tuplex,value): \r\n count = tuplex.count(value)\r\n return count"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that matches a string that has an a followed by zero or more b's by using regex.\n\n### Response:","output":"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!')"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the sum of series 1\u00b3+2\u00b3+3\u00b3+\u2026.+n\u00b3.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove duplicate words from a given list of strings.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert camel case string to snake case string by using regex.\n\n### Response:","output":"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()"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the nth delannoy number.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the sum of series 1\u00b2+2\u00b2+3\u00b2+\u2026.+n\u00b2.\n\n### Response:","output":"def series_sum(number):\r\n total = 0\r\n total = (number * (number + 1) * (2 * number + 1)) \/ 6\r\n return total"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to re-arrange the given tuples based on the given ordered list.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the most common character in a given string.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find three closest elements from three sorted arrays.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort a list of dictionaries using lambda function.\n\n### Response:","output":"def sorted_models(models):\r\n sorted_models = sorted(models, key = lambda x: x['color'])\r\n return sorted_models"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort the given array by using heap sort.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to count the elements in a list until an element is a tuple.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to check if any list element is present in the given list.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to combine two given sorted lists using heapq module.\n\n### Response:","output":"from heapq import merge\r\ndef combine_lists(num1,num2):\r\n combine_lists=list(merge(num1, num2))\r\n return combine_lists"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to separate and print the numbers and their position of a given string.\n\n### Response:","output":"import re\r\ndef num_position(text):\r\n for m in re.finditer(\"\\d+\", text):\r\n return m.start()"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert the given tuples into set.\n\n### Response:","output":"def tuple_to_set(t):\r\n s = set(t)\r\n return (s) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the most common elements and their counts of a specified text.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the length of the shortest word.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to get an item of a tuple.\n\n### Response:","output":"def get_item(tup1,index):\r\n item = tup1[index]\r\n return item"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to sort the given tuple list basis the total digits in tuple.\n\n### Response:","output":"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))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to display sign of the chinese zodiac for given year.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum of similar indices in two lists of tuples.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to compute the value of ncr mod p.\n\n### Response:","output":"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] "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the minimun number of subsets with distinct elements.\n\n### Response:","output":"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 "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that gives profit amount if the given amount has profit else return none.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find out, if the given number is abundant.\n\n### Response:","output":"def is_abundant(n):\r\n fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])\r\n return fctrsum > n"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to split the given string at uppercase letters by using regex.\n\n### Response:","output":"import re\r\ndef split_list(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to get the position of rightmost set bit.\n\n### Response:","output":"import math\r\ndef get_First_Set_Bit_Pos(n):\r\n return math.log2(n&-n)+1"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert an integer into a roman numeral.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the average of a list.\n\n### Response:","output":"def Average(lst): \r\n return sum(lst) \/ len(lst) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to solve tiling problem.\n\n### Response:","output":"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);"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert a roman numeral to an integer.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find the sum of all even natural numbers within the range l and r.\n\n### Response:","output":"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))) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to calculate the discriminant value.\n\n### Response:","output":"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)"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to check whether the length of the word is even or not.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to convert camel case string to snake case string.\n\n### Response:","output":"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()"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to remove an empty tuple from a list of tuples.\n\n### Response:","output":"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"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to accept the strings which contains all vowels.\n\n### Response:","output":"def check(string): \r\n if len(set(string).intersection(\"AEIOUaeiou\"))>=5: \r\n return ('accepted') \r\n else: \r\n return (\"not accepted\") "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to find maximum possible value for the given periodic function.\n\n### Response:","output":"def floor_Max(A,B,N):\r\n x = min(B - 1,N)\r\n return (A*x) \/\/ B"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to join the tuples if they have similar initial elements.\n\n### Response:","output":"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) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find minimum of two numbers.\n\n### Response:","output":"def min_of_two( x, y ):\r\n if x < y:\r\n return x\r\n return y"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the maximum number of segments of lengths a, b and c that can be formed from n.\n\n### Response:","output":"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]"} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to concatenate the given two tuples to a nested tuple.\n\n### Response:","output":"def concatenate_nested(test_tup1, test_tup2):\r\n res = test_tup1 + test_tup2\r\n return (res) "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a python function to left rotate the string.\n\n### Response:","output":"def left_rotate(s,d):\r\n tmp = s[d : ] + s[0 : d]\r\n return tmp "} |
|
{"input":"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function to find the minimum total path sum in the given triangle.\n\n### Response:","output":"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]"} |
|
|