CoolFace
Apppublic

scm104/pychatbot

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
mbpp_train.json3118 linesDownload Raw Back to root
1[2    {3        "instruction": "Write a function to convert the given tuple to a floating-point number.",4        "response": "def tuple_to_float(test_tup):\r\n  res = float('.'.join(str(ele) for ele in test_tup))\r\n  return (res) "5    },6    {7        "instruction": "Write a python function to shift last element to first position in the given list.",8        "response": "def move_first(test_list):\r\n  test_list = test_list[-1:] + test_list[:-1]  \r\n  return test_list"9    },10    {11        "instruction": "Write a function to find the longest palindromic subsequence in the given string.",12        "response": "def lps(str): \r\n\tn = len(str) \r\n\tL = [[0 for x in range(n)] for x in range(n)] \r\n\tfor i in range(n): \r\n\t\tL[i][i] = 1\r\n\tfor cl in range(2, n+1): \r\n\t\tfor i in range(n-cl+1): \r\n\t\t\tj = i+cl-1\r\n\t\t\tif str[i] == str[j] and cl == 2: \r\n\t\t\t\tL[i][j] = 2\r\n\t\t\telif str[i] == str[j]: \r\n\t\t\t\tL[i][j] = L[i+1][j-1] + 2\r\n\t\t\telse: \r\n\t\t\t\tL[i][j] = max(L[i][j-1], L[i+1][j]); \r\n\treturn L[0][n-1]"13    },14    {15        "instruction": "Write a python function to find the slope of a line.",16        "response": "def slope(x1,y1,x2,y2): \r\n    return (float)(y2-y1)/(x2-x1)  "17    },18    {19        "instruction": "Write a function to calculate the perimeter of a regular polygon.",20        "response": "from math import tan, pi\r\ndef perimeter_polygon(s,l):\r\n  perimeter = s*l\r\n  return perimeter"21    },22    {23        "instruction": "Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.",24        "response": "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"25    },26    {27        "instruction": "Write a function to find the ration of negative numbers in an array of integers.",28        "response": "from array import array\r\ndef negative_count(nums):\r\n    n = len(nums)\r\n    n1 = 0\r\n    for x in nums:\r\n        if x < 0:\r\n            n1 += 1\r\n        else:\r\n          None\r\n    return round(n1/n,2)"29    },30    {31        "instruction": "Write a python function to count number of cubes of size k in a cube of size n.",32        "response": "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"33    },34    {35        "instruction": "Write a function to generate a 3d array having each element as '*'.",36        "response": "def array_3d(m,n,o):\r\n array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)]\r\n return array_3d"37    },38    {39        "instruction": "Write a python function to check whether every even index contains even numbers of a given list.",40        "response": "def even_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))"41    },42    {43        "instruction": "Write a function to find minimum number of coins that make a given value.",44        "response": "import sys \r\ndef min_coins(coins, m, V): \r\n    if (V == 0): \r\n        return 0\r\n    res = sys.maxsize \r\n    for i in range(0, m): \r\n        if (coins[i] <= V): \r\n            sub_res = min_coins(coins, m, V-coins[i]) \r\n            if (sub_res != sys.maxsize and sub_res + 1 < res): \r\n                res = sub_res + 1  \r\n    return res "45    },46    {47        "instruction": "Write a function to find the nth decagonal number.",48        "response": "def is_num_decagonal(n): \r\n\treturn 4 * n * n - 3 * n "49    },50    {51        "instruction": "Write a function to check if one tuple is a subset of another tuple.",52        "response": "def check_subset(test_tup1, test_tup2):\r\n  res = set(test_tup2).issubset(test_tup1)\r\n  return (res) "53    },54    {55        "instruction": "Write a function to find the smallest range that includes at-least one element from each of the given arrays.",56        "response": "from heapq import heappop, heappush\r\nclass Node:\r\n    def __init__(self, value, list_num, index):\r\n        self.value = value\r\n        self.list_num = list_num\r\n        self.index = index\r\n    def __lt__(self, other):\r\n        return self.value < other.value\r\ndef find_minimum_range(list):\r\n    high = float('-inf')\r\n    p = (0, float('inf'))\r\n    pq = []\r\n    for i in range(len(list)):\r\n        heappush(pq, Node(list[i][0], i, 0))\r\n        high = max(high, list[i][0])\r\n    while True:\r\n        top = heappop(pq)\r\n        low = top.value\r\n        i = top.list_num\r\n        j = top.index\r\n        if high - low < p[1] - p[0]:\r\n            p = (low, high)\r\n        if j == len(list[i]) - 1:\r\n            return p\r\n        heappush(pq, Node(list[i][j + 1], i, j + 1))\r\n        high = max(high, list[i][j + 1])"57    },58    {59        "instruction": "Write a python function to check whether every odd index contains odd numbers of a given list.",60        "response": "def odd_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))"61    },62    {63        "instruction": "Write a python function to count the number of digits in factorial of a given number.",64        "response": "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; "65    },66    {67        "instruction": "Write a python function to find the largest postive number from the given list.",68        "response": "def largest_pos(list1): \r\n    max = list1[0] \r\n    for x in list1: \r\n        if x > max : \r\n             max = x  \r\n    return max"69    },70    {71        "instruction": "Write a function to calculate the sum of perrin numbers.",72        "response": "def cal_sum(n): \r\n\ta = 3\r\n\tb = 0\r\n\tc = 2\r\n\tif (n == 0): \r\n\t\treturn 3\r\n\tif (n == 1): \r\n\t\treturn 3\r\n\tif (n == 2): \r\n\t\treturn 5\r\n\tsum = 5\r\n\twhile (n > 2): \r\n\t\td = a + b \r\n\t\tsum = sum + d \r\n\t\ta = b \r\n\t\tb = c \r\n\t\tc = d \r\n\t\tn = n-1\r\n\treturn sum"73    },74    {75        "instruction": "Write a function to combine two dictionaries by adding values for common keys.",76        "response": "from collections import Counter\r\ndef add_dict(d1,d2):\r\n   add_dict = Counter(d1) + Counter(d2)\r\n   return add_dict"77    },78    {79        "instruction": "Write a function to get the angle of a complex number.",80        "response": "import cmath\r\ndef angle_complex(a,b):\r\n  cn=complex(a,b)\r\n  angle=cmath.phase(a+b)\r\n  return angle"81    },82    {83        "instruction": "Write a python function to find the sum of all odd length subarrays.",84        "response": "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"85    },86    {87        "instruction": "Write a python function to check whether the first and last characters of a given string are equal or not.",88        "response": "def check_Equality(str):\r\n  if (str[0] == str[-1]):  \r\n    return (\"Equal\") \r\n  else:  \r\n    return (\"Not Equal\") "89    },90    {91        "instruction": "Write a function to find maximum of two numbers.",92        "response": "def max_of_two( x, y ):\r\n    if x > y:\r\n        return x\r\n    return y"93    },94    {95        "instruction": "Write a python function to find the average of a list.",96        "response": "def Average(lst): \r\n    return sum(lst) / len(lst) "97    },98    {99        "instruction": "Write a function to join the tuples if they have similar initial elements.",100        "response": "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) "101    },102    {103        "instruction": "Write a function to find entringer number e(n, k).",104        "response": "def zigzag(n, k): \r\n\tif (n == 0 and k == 0): \r\n\t\treturn 1\r\n\tif (k == 0): \r\n\t\treturn 0\r\n\treturn zigzag(n, k - 1) + zigzag(n - 1, n - k)"105    },106    {107        "instruction": "Write a python function to find sum of inverse of divisors.",108        "response": "def Sum_of_Inverse_Divisors(N,Sum): \r\n    ans = float(Sum)*1.0 /float(N);  \r\n    return round(ans,2); "109    },110    {111        "instruction": "Write a python function to find the sum of xor of all pairs of numbers in the given array.",112        "response": "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 "113    },114    {115        "instruction": "Write a python function to find the sum of common divisors of two given numbers.",116        "response": "def sum(a,b): \r\n    sum = 0\r\n    for i in range (1,min(a,b)): \r\n        if (a % i == 0 and b % i == 0): \r\n            sum += i \r\n    return sum"117    },118    {119        "instruction": "Write a python function to check whether all the characters are same or not.",120        "response": "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"121    },122    {123        "instruction": "Write a function to find the minimum number of platforms required for a railway/bus station.",124        "response": "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"125    },126    {127        "instruction": "Write a function to find kth element from the given two sorted arrays.",128        "response": "def find_kth(arr1, arr2, m, n, k):\r\n\tsorted1 = [0] * (m + n)\r\n\ti = 0\r\n\tj = 0\r\n\td = 0\r\n\twhile (i < m and j < n):\r\n\t\tif (arr1[i] < arr2[j]):\r\n\t\t\tsorted1[d] = arr1[i]\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tsorted1[d] = arr2[j]\r\n\t\t\tj += 1\r\n\t\td += 1\r\n\twhile (i < m):\r\n\t\tsorted1[d] = arr1[i]\r\n\t\td += 1\r\n\t\ti += 1\r\n\twhile (j < n):\r\n\t\tsorted1[d] = arr2[j]\r\n\t\td += 1\r\n\t\tj += 1\r\n\treturn sorted1[k - 1]"129    },130    {131        "instruction": "Write a function to find sequences of lowercase letters joined with an underscore.",132        "response": "import re\r\ndef text_lowercase_underscore(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!')"133    },134    {135        "instruction": "Write a function to move all zeroes to the end of the given array.",136        "response": "def re_order(A):\r\n    k = 0\r\n    for i in A:\r\n        if i:\r\n            A[k] = i\r\n            k = k + 1\r\n    for i in range(k, len(A)):\r\n        A[i] = 0\r\n    return A"137    },138    {139        "instruction": "Write a python function to find the element that appears only once in a sorted array.",140        "response": "def search(arr,n) :\r\n    XOR = 0\r\n    for i in range(n) :\r\n        XOR = XOR ^ arr[i]\r\n    return (XOR)"141    },142    {143        "instruction": "Write a function to find the second smallest number in a list.",144        "response": "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] "145    },146    {147        "instruction": "Write a python function to find the average of odd numbers till a given odd number.",148        "response": "def average_Odd(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>=1) : \r\n        count=count+1\r\n        sm = sm + n \r\n        n = n-2\r\n    return sm//count "149    },150    {151        "instruction": "Write a function to move all the numbers in it to the given string.",152        "response": "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) "153    },154    {155        "instruction": "Write a function to find eulerian number a(n, m).",156        "response": "def eulerian_num(n, m): \r\n\tif (m >= n or n == 0): \r\n\t\treturn 0 \r\n\tif (m == 0): \r\n\t\treturn 1 \r\n\treturn ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))"157    },158    {159        "instruction": "Write a python function to check whether a sequence of numbers has an increasing trend or not.",160        "response": "def increasing_trend(nums):\r\n    if (sorted(nums)== nums):\r\n        return True\r\n    else:\r\n        return False"161    },162    {163        "instruction": "Write a function to flatten the tuple list to a string.",164        "response": "def flatten_tuple(test_list):\r\n  res = ' '.join([idx for tup in test_list for idx in tup])\r\n  return (res) "165    },166    {167        "instruction": "Write a function to find the maximum difference between available pairs in the given tuple list.",168        "response": "def max_difference(test_list):\r\n  temp = [abs(b - a) for a, b in test_list]\r\n  res = max(temp)\r\n  return (res) "169    },170    {171        "instruction": "Write a function to convert degrees to radians.",172        "response": "import math\r\ndef radian_degree(degree):\r\n radian = degree*(math.pi/180)\r\n return radian"173    },174    {175        "instruction": "Write a function to sort a list of elements using pancake sort.",176        "response": "def pancake_sort(nums):\r\n    arr_len = len(nums)\r\n    while arr_len > 1:\r\n        mi = nums.index(max(nums[0:arr_len]))\r\n        nums = nums[mi::-1] + nums[mi+1:len(nums)]\r\n        nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]\r\n        arr_len -= 1\r\n    return nums"177    },178    {179        "instruction": "Write a function to find the lateral surface area of a cylinder.",180        "response": "def lateralsuface_cylinder(r,h):\r\n  lateralsurface= 2*3.1415*r*h\r\n  return lateralsurface"181    },182    {183        "instruction": "Write a function to find palindromes in a given list of strings using lambda function.",184        "response": "def palindrome_lambda(texts):\r\n  result = list(filter(lambda x: (x == \"\".join(reversed(x))), texts))\r\n  return result"185    },186    {187        "instruction": "Write a function to find the sum of first even and odd number of a given list.",188        "response": "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)"189    },190    {191        "instruction": "Write a function to shortlist words that are longer than n from a given list of words.",192        "response": "def long_words(n, str):\r\n    word_len = []\r\n    txt = str.split(\" \")\r\n    for x in txt:\r\n        if len(x) > n:\r\n            word_len.append(x)\r\n    return word_len\t"193    },194    {195        "instruction": "Write a python function to find quotient of two numbers.",196        "response": "def find(n,m):  \r\n    q = n//m \r\n    return (q)"197    },198    {199        "instruction": "Write a function to convert a list to a tuple.",200        "response": "def list_tuple(listx):\r\n  tuplex = tuple(listx)\r\n  return tuplex"201    },202    {203        "instruction": "Write a function to find common elements in given nested lists. * list item * list item * list item * list item",204        "response": "def common_in_nested_lists(nestedlist):\r\n    result = list(set.intersection(*map(set, nestedlist)))\r\n    return result"205    },206    {207        "instruction": "Write a function to find the similar elements from the given two tuple lists.",208        "response": "def similar_elements(test_tup1, test_tup2):\r\n  res = tuple(set(test_tup1) & set(test_tup2))\r\n  return (res) "209    },210    {211        "instruction": "Write a function to check if all values are same in a dictionary.",212        "response": "def check_value(dict, n):\r\n    result = all(x == n for x in dict.values()) \r\n    return result"213    },214    {215        "instruction": "Write a function to extract values between quotation marks of the given string by using regex.",216        "response": "import re\r\ndef extract_quotation(text1):\r\n  return (re.findall(r'\"(.*?)\"', text1))"217    },218    {219        "instruction": "Write a python function to find the sum of the largest and smallest value in a given array.",220        "response": "def big_sum(nums):\r\n      sum= max(nums)+min(nums)\r\n      return sum"221    },222    {223        "instruction": "Write a function to extract the nth element from a given list of tuples.",224        "response": "def extract_nth_element(list1, n):\r\n    result = [x[n] for x in list1]\r\n    return result"225    },226    {227        "instruction": "Write a python function to find minimum number swaps required to make two binary strings equal.",228        "response": "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;  "229    },230    {231        "instruction": "Write a function to find the sum of arithmetic progression.",232        "response": "def ap_sum(a,n,d):\r\n  total = (n * (2 * a + (n - 1) * d)) / 2\r\n  return total"233    },234    {235        "instruction": "Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value.",236        "response": "def remove_replica(test_tup):\r\n  temp = set()\r\n  res = tuple(ele if ele not in temp and not temp.add(ele) \r\n\t\t\t\telse 'MSP' for ele in test_tup)\r\n  return (res)"237    },238    {239        "instruction": "Write a function to sort a list of dictionaries using lambda function.",240        "response": "def sorted_models(models):\r\n sorted_models = sorted(models, key = lambda x: x['color'])\r\n return sorted_models"241    },242    {243        "instruction": "Write 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.",244        "response": "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])))"245    },246    {247        "instruction": "Write a function to find tuples which have all elements divisible by k from the given list of tuples.",248        "response": "def find_tuples(test_list, K):\r\n  res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]\r\n  return (str(res)) "249    },250    {251        "instruction": "Write a function to find squares of individual elements in a list using lambda function.",252        "response": "def square_nums(nums):\r\n square_nums = list(map(lambda x: x ** 2, nums))\r\n return square_nums"253    },254    {255        "instruction": "Write a function to find the length of the longest increasing subsequence of the given sequence.",256        "response": "def longest_increasing_subsequence(arr): \r\n\tn = len(arr) \r\n\tlongest_increasing_subsequence = [1]*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] > arr[j] and longest_increasing_subsequence[i]< longest_increasing_subsequence[j] + 1 : \r\n\t\t\t\tlongest_increasing_subsequence[i] = longest_increasing_subsequence[j]+1\r\n\tmaximum = 0\r\n\tfor i in range(n): \r\n\t\tmaximum = max(maximum , longest_increasing_subsequence[i]) \r\n\treturn maximum"257    },258    {259        "instruction": "Write a function to select the nth items of a list.",260        "response": "def nth_items(list,n):\r\n return list[::n]"261    },262    {263        "instruction": "Write a python function to count negative numbers in a list.",264        "response": "def neg_count(list):\r\n  neg_count= 0\r\n  for num in list: \r\n    if num <= 0: \r\n      neg_count += 1\r\n  return neg_count "265    },266    {267        "instruction": "Write a function to zip the two given tuples.",268        "response": "def zip_tuples(test_tup1, test_tup2):\r\n  res = []\r\n  for i, j in enumerate(test_tup1):\r\n    res.append((j, test_tup2[i % len(test_tup2)])) \r\n  return (res) "269    },270    {271        "instruction": "Write a function to create a list taking alternate elements from another given list.",272        "response": "def alternate_elements(list1):\r\n    result=[]\r\n    for item in list1[::2]:\r\n        result.append(item)\r\n    return result "273    },274    {275        "instruction": "Write a python function to access multiple elements of specified index from a given list.",276        "response": "def access_elements(nums, list_index):\r\n    result = [nums[i] for i in list_index]\r\n    return result"277    },278    {279        "instruction": "Write a function to convert radians to degrees.",280        "response": "import math\r\ndef degree_radian(radian):\r\n degree = radian*(180/math.pi)\r\n return degree"281    },282    {283        "instruction": "Write a function to toggle characters case in a string.",284        "response": "def toggle_string(string):\r\n string1 = string.swapcase()\r\n return string1"285    },286    {287        "instruction": "Write a python function to check whether the given number can be represented by sum of two squares or not.",288        "response": "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"289    },290    {291        "instruction": "Write a function to search an element in the given array by using binary search.",292        "response": "def binary_search(item_list,item):\r\n\tfirst = 0\r\n\tlast = len(item_list)-1\r\n\tfound = False\r\n\twhile( first<=last and not found):\r\n\t\tmid = (first + last)//2\r\n\t\tif item_list[mid] == item :\r\n\t\t\tfound = True\r\n\t\telse:\r\n\t\t\tif item < item_list[mid]:\r\n\t\t\t\tlast = mid - 1\r\n\t\t\telse:\r\n\t\t\t\tfirst = mid + 1\t\r\n\treturn found"293    },294    {295        "instruction": "Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.",296        "response": "def func(nums, k):\r\n    import collections\r\n    d = collections.defaultdict(int)\r\n    for row in nums:\r\n        for i in row:\r\n            d[i] += 1\r\n    temp = []\r\n    import heapq\r\n    for key, v in d.items():\r\n        if len(temp) < k:\r\n            temp.append((v, key))\r\n            if len(temp) == k:\r\n                heapq.heapify(temp)\r\n        else:\r\n            if v > temp[0][0]:\r\n                heapq.heappop(temp)\r\n                heapq.heappush(temp, (v, key))\r\n    result = []\r\n    while temp:\r\n        v, key = heapq.heappop(temp)\r\n        result.append(key)\r\n    return result"297    },298    {299        "instruction": "Write a function that gives loss amount if the given amount has loss else return none.",300        "response": "def loss_amount(actual_cost,sale_amount): \r\n  if(sale_amount > actual_cost):\r\n    amount = sale_amount - actual_cost\r\n    return amount\r\n  else:\r\n    return None"301    },302    {303        "instruction": "Write a function to extract every first or specified element from a given two-dimensional list.",304        "response": "def specified_element(nums, N):\r\n    result = [i[N] for i in nums]\r\n    return result\r\n    "305    },306    {307        "instruction": "Write a python function to find the next perfect square greater than a given number.",308        "response": "import math  \r\ndef next_Perfect_Square(N): \r\n    nextN = math.floor(math.sqrt(N)) + 1\r\n    return nextN * nextN "309    },310    {311        "instruction": "Write a function to check if a triangle of positive area is possible with the given angles.",312        "response": "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"313    },314    {315        "instruction": "Write a function to print check if the triangle is equilateral or not.",316        "response": "def check_equilateral(x,y,z):\r\n  if x == y == z:\r\n\t   return True\r\n  else:\r\n     return False"317    },318    {319        "instruction": "Write a function to extract specified size of strings from a give list of string values.",320        "response": "def extract_string(str, l):\r\n    result = [e for e in str if len(e) == l] \r\n    return result"321    },322    {323        "instruction": "Write a function to find all adverbs and their positions in a given sentence.",324        "response": "import re\r\ndef find_adverb_position(text):\r\n for m in re.finditer(r\"\\w+ly\", text):\r\n    return (m.start(), m.end(), m.group(0))"325    },326    {327        "instruction": "Write a function to find the depth of a dictionary.",328        "response": "def dict_depth(d):\r\n    if isinstance(d, dict):\r\n        return 1 + (max(map(dict_depth, d.values())) if d else 0)\r\n    return 0"329    },330    {331        "instruction": "Write a python function to check whether the given number can be represented as difference of two squares or not.",332        "response": "def dif_Square(n): \r\n    if (n % 4 != 2): \r\n        return True\r\n    return False"333    },334    {335        "instruction": "Write a function to convert a list of multiple integers into a single integer.",336        "response": "def multiple_to_single(L):\r\n  x = int(\"\".join(map(str, L)))\r\n  return x"337    },338    {339        "instruction": "Write a python function to find the last digit of a given number.",340        "response": "def last_Digit(n) :\r\n    return (n % 10) "341    },342    {343        "instruction": "Write a function to check whether the given month number contains 28 days or not.",344        "response": "def check_monthnum_number(monthnum1):\r\n  if monthnum1 == 2:\r\n    return True\r\n  else:\r\n    return False"345    },346    {347        "instruction": "Write a function to find number of odd elements in the given list using lambda function.",348        "response": "def count_odd(array_nums):\r\n   count_odd = len(list(filter(lambda x: (x%2 != 0) , array_nums)))\r\n   return count_odd"349    },350    {351        "instruction": "Write a python function to remove the characters which have odd index values of a given string.",352        "response": "def odd_values_string(str):\r\n  result = \"\" \r\n  for i in range(len(str)):\r\n    if i % 2 == 0:\r\n      result = result + str[i]\r\n  return result"353    },354    {355        "instruction": "Write a function to delete the smallest element from the given heap and then insert a new item.",356        "response": "import heapq as hq\r\ndef heap_replace(heap,a):\r\n  hq.heapify(heap)\r\n  hq.heapreplace(heap, a)\r\n  return heap"357    },358    {359        "instruction": "Write a python function to get the first element of each sublist.",360        "response": "def Extract(lst): \r\n    return [item[0] for item in lst] "361    },362    {363        "instruction": "Write a python function to find the last digit in factorial of a given number.",364        "response": "def last_Digit_Factorial(n): \r\n    if (n == 0): return 1\r\n    elif (n <= 2): return n  \r\n    elif (n == 3): return 6\r\n    elif (n == 4): return 4 \r\n    else: \r\n      return 0"365    },366    {367        "instruction": "Write a function to print n-times a list using map function.",368        "response": "def ntimes_list(nums,n):\r\n    result = map(lambda x:n*x, nums) \r\n    return list(result)"369    },370    {371        "instruction": "Write a function to find out, if the given number is abundant.",372        "response": "def is_abundant(n):\r\n    fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])\r\n    return fctrsum > n"373    },374    {375        "instruction": "Write a python function to remove even numbers from a given list.",376        "response": "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"377    },378    {379        "instruction": "Write a python function to count the number of squares in a rectangle.",380        "response": "def count_Squares(m,n):\r\n    if(n < m):\r\n        temp = m\r\n        m = n\r\n        n = temp\r\n    return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))"381    },382    {383        "instruction": "Write a function to remove characters from the first string which are present in the second string.",384        "response": "NO_OF_CHARS = 256\r\ndef str_to_list(string): \r\n\ttemp = [] \r\n\tfor x in string: \r\n\t\ttemp.append(x) \r\n\treturn temp \r\ndef lst_to_string(List): \r\n\treturn ''.join(List) \r\ndef get_char_count_array(string): \r\n\tcount = [0] * NO_OF_CHARS \r\n\tfor i in string: \r\n\t\tcount[ord(i)] += 1\r\n\treturn count \r\ndef remove_dirty_chars(string, second_string): \r\n\tcount = get_char_count_array(second_string) \r\n\tip_ind = 0\r\n\tres_ind = 0\r\n\ttemp = '' \r\n\tstr_list = str_to_list(string) \r\n\twhile ip_ind != len(str_list): \r\n\t\ttemp = str_list[ip_ind] \r\n\t\tif count[ord(temp)] == 0: \r\n\t\t\tstr_list[res_ind] = str_list[ip_ind] \r\n\t\t\tres_ind += 1\r\n\t\tip_ind+=1\r\n\treturn lst_to_string(str_list[0:res_ind]) "385    },386    {387        "instruction": "Write a function to remove sublists from a given list of lists, which are outside a given range.",388        "response": "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"389    },390    {391        "instruction": "Write a function to find common first element in given list of tuple.",392        "response": "def group_tuples(Input): \r\n\tout = {} \r\n\tfor elem in Input: \r\n\t\ttry: \r\n\t\t\tout[elem[0]].extend(elem[1:]) \r\n\t\texcept KeyError: \r\n\t\t\tout[elem[0]] = list(elem) \r\n\treturn [tuple(values) for values in out.values()] "393    },394    {395        "instruction": "Write a python function to get the last element of each sublist.",396        "response": "def Extract(lst): \r\n    return [item[-1] for item in lst] "397    },398    {399        "instruction": "Write a function to find the minimum value in a given heterogeneous list.",400        "response": "def min_val(listval):\r\n     min_val = min(i for i in listval if isinstance(i, int))\r\n     return min_val"401    },402    {403        "instruction": "Write a function that matches a string that has an a followed by zero or more b's by using regex.",404        "response": "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!')"405    },406    {407        "instruction": "Write a function to remove even characters in a string.",408        "response": "def remove_even(str1):\r\n str2 = ''\r\n for i in range(1, len(str1) + 1):\r\n    if(i % 2 != 0):\r\n        str2 = str2 + str1[i - 1]\r\n return str2"409    },410    {411        "instruction": "Write a python function to sort a list according to the second element in sublist.",412        "response": "def Sort(sub_li): \r\n    sub_li.sort(key = lambda x: x[1]) \r\n    return sub_li "413    },414    {415        "instruction": "Write a function to find the sum of geometric progression series.",416        "response": "import math\r\ndef sum_gp(a,n,r):\r\n total = (a * (1 - math.pow(r, n ))) / (1- r)\r\n return total"417    },418    {419        "instruction": "Write a function to sort a tuple by its float element.",420        "response": "def float_sort(price):\r\n  float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True)\r\n  return float_sort"421    },422    {423        "instruction": "Write a function to find nth polite number.",424        "response": "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))) "425    },426    {427        "instruction": "Write a function to remove words from a given list of strings containing a character or string.",428        "response": "def remove_words(list1, charlist):\r\n    new_list = []\r\n    for line in list1:\r\n        new_words = ' '.join([word for word in line.split() if not any([phrase in word for phrase in charlist])])\r\n        new_list.append(new_words)\r\n    return new_list"429    },430    {431        "instruction": "Write a function to remove uppercase substrings from a given string by using regex.",432        "response": "import re\r\ndef remove_uppercase(str1):\r\n  remove_upper = lambda text: re.sub('[A-Z]', '', text)\r\n  result =  remove_upper(str1)\r\n  return (result)"433    },434    {435        "instruction": "Write a python function to find the nth digit in the proper fraction of two given numbers.",436        "response": "def find_Nth_Digit(p,q,N) :  \r\n    while (N > 0) : \r\n        N -= 1;  \r\n        p *= 10;  \r\n        res = p // q;  \r\n        p %= q;  \r\n    return res;  "437    },438    {439        "instruction": "Write a function to find the n'th perrin number using recursion.",440        "response": "def get_perrin(n):\r\n  if (n == 0):\r\n    return 3\r\n  if (n == 1):\r\n    return 0\r\n  if (n == 2):\r\n    return 2 \r\n  return get_perrin(n - 2) + get_perrin(n - 3)"441    },442    {443        "instruction": "Write a function to filter a dictionary based on values.",444        "response": "def dict_filter(dict,n):\r\n result = {key:value for (key, value) in dict.items() if value >=n}\r\n return result"445    },446    {447        "instruction": "Write a function to find the maximum of nth column from the given tuple list.",448        "response": "def max_of_nth(test_list, N):\r\n  res = max([sub[N] for sub in test_list])\r\n  return (res) "449    },450    {451        "instruction": "Write a python function to check whether a sequence of numbers has a decreasing trend or not.",452        "response": "def decreasing_trend(nums):\r\n    if (sorted(nums)== nums):\r\n        return True\r\n    else:\r\n        return False"453    },454    {455        "instruction": "Write function to find the sum of all items in the given dictionary.",456        "response": "def return_sum(dict):\r\n  sum = 0\r\n  for i in dict.values():\r\n    sum = sum + i\r\n  return sum"457    },458    {459        "instruction": "Write a function to calculate wind chill index.",460        "response": "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))"461    },462    {463        "instruction": "Write a function to count number of unique lists within a list.",464        "response": "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"465    },466    {467        "instruction": "Write a function to merge two dictionaries into a single expression.",468        "response": "import collections as ct\r\ndef merge_dictionaries(dict1,dict2):\r\n    merged_dict = dict(ct.ChainMap({}, dict1, dict2))\r\n    return merged_dict"469    },470    {471        "instruction": "Write a function to find the division of first even and odd number of a given list.",472        "response": "def div_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)"473    },474    {475        "instruction": "Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.",476        "response": "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)"477    },478    {479        "instruction": "Write a python function to check whether two given lines are parallel or not.",480        "response": "def parallel_lines(line1, line2):\r\n  return line1[0]/line1[1] == line2[0]/line2[1]"481    },482    {483        "instruction": "Write a function to count the element frequency in the mixed nested tuple.",484        "response": "def flatten(test_tuple): \r\n\tfor tup in test_tuple: \r\n\t\tif isinstance(tup, tuple): \r\n\t\t\tyield from flatten(tup) \r\n\t\telse: \r\n\t\t\tyield tup \r\ndef count_element_freq(test_tuple):\r\n  res = {}\r\n  for ele in flatten(test_tuple):\r\n    if ele not in res:\r\n      res[ele] = 0\r\n    res[ele] += 1\r\n  return (res) "485    },486    {487        "instruction": "Write a function to get a colon of a tuple.",488        "response": "from copy import deepcopy\r\ndef colon_tuplex(tuplex,m,n):\r\n  tuplex_colon = deepcopy(tuplex)\r\n  tuplex_colon[m].append(n)\r\n  return tuplex_colon"489    },490    {491        "instruction": "Write a python function to check whether the last element of given array is even or odd after performing an operation p times.",492        "response": "def check_last (arr,n,p): \r\n    _sum = 0\r\n    for i in range(n): \r\n        _sum = _sum + arr[i] \r\n    if p == 1: \r\n        if _sum % 2 == 0: \r\n            return \"ODD\"\r\n        else: \r\n            return \"EVEN\"\r\n    return \"EVEN\"\r\n      "493    },494    {495        "instruction": "Write a python function to find the difference between largest and smallest value in a given array.",496        "response": "def big_diff(nums):\r\n     diff= max(nums)-min(nums)\r\n     return diff"497    },498    {499        "instruction": "Write a function to check if any list element is present in the given list.",500        "response": "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) "501    },502    {503        "instruction": "Write a python function to find the volume of a triangular prism.",504        "response": "def find_Volume(l,b,h) : \r\n    return ((l * b * h) / 2) "505    },506    {507        "instruction": "Write a python function to find the minimum length of sublist.",508        "response": "def Find_Min_Length(lst):  \r\n    minLength = min(len(x) for x in lst )\r\n    return minLength "509    },510    {511        "instruction": "Write a function to search an element in the given array by using sequential search.",512        "response": "def sequential_search(dlist, item):\r\n    pos = 0\r\n    found = False\r\n    while pos < len(dlist) and not found:\r\n        if dlist[pos] == item:\r\n            found = True\r\n        else:\r\n            pos = pos + 1\r\n    return found, pos"513    },514    {515        "instruction": "Write a function to iterate over elements repeating each as many times as its count.",516        "response": "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())"517    },518    {519        "instruction": "Write a python function to check for odd parity of a given number.",520        "response": "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"521    },522    {523        "instruction": "Write a function to perfom the rear element extraction from list of tuples records.",524        "response": "def rear_extract(test_list):\r\n  res = [lis[-1] for lis in test_list]\r\n  return (res) "525    },526    {527        "instruction": "Write a function to split a string at lowercase letters.",528        "response": "import re\r\ndef split_lowerstring(text):\r\n return (re.findall('[a-z][^a-z]*', text))"529    },530    {531        "instruction": "Write a python function to count numeric values in a given string.",532        "response": "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"533    },534    {535        "instruction": "Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.",536        "response": "def count_char_position(str1): \r\n    count_chars = 0\r\n    for i in range(len(str1)):\r\n        if ((i == ord(str1[i]) - ord('A')) or \r\n            (i == ord(str1[i]) - ord('a'))): \r\n            count_chars += 1\r\n    return count_chars "537    },538    {539        "instruction": "Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers.",540        "response": "def sum_difference(n):\r\n    sumofsquares = 0\r\n    squareofsum = 0\r\n    for num in range(1, n+1):\r\n        sumofsquares += num * num\r\n        squareofsum += num\r\n    squareofsum = squareofsum ** 2\r\n    return squareofsum - sumofsquares"541    },542    {543        "instruction": "Write a python function to find the first natural number whose factorial is divisible by x.",544        "response": "def first_Factorial_Divisible_Number(x): \r\n    i = 1;\r\n    fact = 1; \r\n    for i in range(1,x): \r\n        fact = fact * i \r\n        if (fact % x == 0): \r\n            break\r\n    return i "545    },546    {547        "instruction": "Write a function to get the n smallest items from a dataset.",548        "response": "import heapq\r\ndef small_nnum(list1,n):\r\n  smallest=heapq.nsmallest(n,list1)\r\n  return smallest"549    },550    {551        "instruction": "Write a python function to check whether an array is subarray of another or not.",552        "response": "def is_Sub_Array(A,B,n,m): \r\n    i = 0; j = 0; \r\n    while (i < n and j < m):  \r\n        if (A[i] == B[j]): \r\n            i += 1; \r\n            j += 1; \r\n            if (j == m): \r\n                return True;  \r\n        else: \r\n            i = i - j + 1; \r\n            j = 0;       \r\n    return False; "553    },554    {555        "instruction": "Write a python function to find the difference between highest and least frequencies in a given array.",556        "response": "def find_Diff(arr,n): \r\n    arr.sort()  \r\n    count = 0; max_count = 0; min_count = n \r\n    for i in range(0,(n-1)): \r\n        if arr[i] == arr[i + 1]: \r\n            count += 1\r\n            continue\r\n        else: \r\n            max_count = max(max_count,count) \r\n            min_count = min(min_count,count) \r\n            count = 0\r\n    return max_count - min_count "557    },558    {559        "instruction": "Write a function to check if the given array represents min heap or not.",560        "response": "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"561    },562    {563        "instruction": "Write a function to find if the given number is abundant or not.",564        "response": "import math \r\ndef get_sum(n): \r\n\tsum = 0\r\n\ti = 1\r\n\twhile i <= (math.sqrt(n)): \r\n\t\tif n%i == 0: \r\n\t\t\tif n/i == i : \r\n\t\t\t\tsum = sum + i \r\n\t\t\telse: \r\n\t\t\t\tsum = sum + i \r\n\t\t\t\tsum = sum + (n / i ) \r\n\t\ti = i + 1\r\n\tsum = sum - n \r\n\treturn sum\r\ndef check_abundant(n): \r\n\tif (get_sum(n) > n): \r\n\t\treturn True\r\n\telse: \r\n\t\treturn False"565    },566    {567        "instruction": "Write a python function to find the average of even numbers till a given even number.",568        "response": "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 "569    },570    {571        "instruction": "Write a python function to find number of integers with odd number of set bits.",572        "response": "def count_With_Odd_SetBits(n): \r\n    if (n % 2 != 0): \r\n        return (n + 1) / 2\r\n    count = bin(n).count('1') \r\n    ans = n / 2\r\n    if (count % 2 != 0): \r\n        ans += 1\r\n    return ans "573    },574    {575        "instruction": "Write a python function to find the last two digits in factorial of a given number.",576        "response": "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) "577    },578    {579        "instruction": "Write a python function to find the minimum operations required to make two numbers equal.",580        "response": "import math   \r\ndef min_Operations(A,B):  \r\n    if (A > B): \r\n        swap(A,B)  \r\n    B = B // math.gcd(A,B);  \r\n    return B - 1"581    },582    {583        "instruction": "Write a function to find the median of three specific numbers.",584        "response": "def median_numbers(a,b,c):\r\n if a > b:\r\n    if a < c:\r\n        median = a\r\n    elif b > c:\r\n        median = b\r\n    else:\r\n        median = c\r\n else:\r\n    if a > c:\r\n        median = a\r\n    elif b < c:\r\n        median = b\r\n    else:\r\n        median = c\r\n return median"585    },586    {587        "instruction": "Write a function to display sign of the chinese zodiac for given year.",588        "response": "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"589    },590    {591        "instruction": "Write a function to split the given string at uppercase letters by using regex.",592        "response": "import re\r\ndef split_list(text):\r\n  return (re.findall('[A-Z][^A-Z]*', text))"593    },594    {595        "instruction": "Write a function to remove all tuples with all none values in the given tuple list.",596        "response": "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)) "597    },598    {599        "instruction": "Write a python function to find odd numbers from a mixed list.",600        "response": "def Split(list): \r\n    od_li = [] \r\n    for i in list: \r\n        if (i % 2 != 0): \r\n            od_li.append(i)  \r\n    return od_li"601    },602    {603        "instruction": "Write a function to find the lateral surface area of a cone.",604        "response": "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"605    },606    {607        "instruction": "Write a python function to check whether the given two numbers have same number of digits or not.",608        "response": "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; "609    },610    {611        "instruction": "Write a function to find the list in a list of lists whose sum of elements is the highest.",612        "response": "def max_sum_list(lists):\r\n return max(lists, key=sum)"613    },614    {615        "instruction": "Write a function to extract year, month and date from a url by using regex.",616        "response": "import re\r\ndef extract_date(url):\r\n        return re.findall(r'/(\\d{4})/(\\d{1,2})/(\\d{1,2})/', url)"617    },618    {619        "instruction": "Write a function to find maximum of three numbers.",620        "response": "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"621    },622    {623        "instruction": "Write a function to check whether all dictionaries in a list are empty or not.",624        "response": "def empty_dit(list1):\r\n empty_dit=all(not d for d in list1)\r\n return empty_dit"625    },626    {627        "instruction": "Write a function to check if a substring is present in a given list of string values.",628        "response": "def find_substring(str1, sub_str):\r\n   if any(sub_str in s for s in str1):\r\n       return True\r\n   return False"629    },630    {631        "instruction": "Write a function to count occurrence of a character in a string.",632        "response": "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"633    },634    {635        "instruction": "Write a function to remove specific words from a given list.",636        "response": "def remove_words(list1, removewords):\r\n    for word in list(list1):\r\n        if word in removewords:\r\n            list1.remove(word)\r\n    return list1  "637    },638    {639        "instruction": "Write a python function to choose points from two ranges such that no point lies in both the ranges.",640        "response": "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)"641    },642    {643        "instruction": "Write a function to find the smallest multiple of the first n numbers.",644        "response": "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"645    },646    {647        "instruction": "Write a function to solve gold mine problem.",648        "response": "def get_maxgold(gold, m, n): \r\n    goldTable = [[0 for i in range(n)] \r\n                        for j in range(m)]   \r\n    for col in range(n-1, -1, -1): \r\n        for row in range(m):  \r\n            if (col == n-1): \r\n                right = 0\r\n            else: \r\n                right = goldTable[row][col+1] \r\n            if (row == 0 or col == n-1): \r\n                right_up = 0\r\n            else: \r\n                right_up = goldTable[row-1][col+1] \r\n            if (row == m-1 or col == n-1): \r\n                right_down = 0\r\n            else: \r\n                right_down = goldTable[row+1][col+1] \r\n            goldTable[row][col] = gold[row][col] + max(right, right_up, right_down) \r\n    res = goldTable[0][0] \r\n    for i in range(1, m): \r\n        res = max(res, goldTable[i][0])  \r\n    return res "649    },650    {651        "instruction": "Write a function to convert the given snake case string to camel case string by using regex.",652        "response": "import re\r\ndef snake_to_camel(word):\r\n  return ''.join(x.capitalize() or '_' for x in word.split('_'))"653    },654    {655        "instruction": "Write a function to calculate the sum of series 1³+2³+3³+….+n³.",656        "response": "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"657    },658    {659        "instruction": "Write a function to find the minimum difference in the tuple pairs of given tuples.",660        "response": "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) "661    },662    {663        "instruction": "Write a function to replace all occurrences of spaces, commas, or dots with a colon.",664        "response": "import re\r\ndef replace_specialchar(text):\r\n return (re.sub(\"[ ,.]\", \":\", text))\r"665    },666    {667        "instruction": "Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.",668        "response": "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\") "669    },670    {671        "instruction": "Write a function to extract a specified column from a given nested list.",672        "response": "def extract_column(list1, n):\r\n   result = [i.pop(n) for i in list1]\r\n   return result "673    },674    {675        "instruction": "Write a function to find the maximum total path sum in the given triangle.",676        "response": "def max_path_sum(tri, m, n): \r\n\tfor i in range(m-1, -1, -1): \r\n\t\tfor j in range(i+1): \r\n\t\t\tif (tri[i+1][j] > tri[i+1][j+1]): \r\n\t\t\t\ttri[i][j] += tri[i+1][j] \r\n\t\t\telse: \r\n\t\t\t\ttri[i][j] += tri[i+1][j+1] \r\n\treturn tri[0][0]"677    },678    {679        "instruction": "Write a python function to count the number of substrings with same first and last characters.",680        "response": "def check_Equality(s): \r\n    return (ord(s[0]) == ord(s[len(s) - 1])); \r\ndef count_Substring_With_Equal_Ends(s): \r\n    result = 0; \r\n    n = len(s); \r\n    for i in range(n):\r\n        for j in range(1,n-i+1): \r\n            if (check_Equality(s[i:i+j])): \r\n                result+=1; \r\n    return result; "681    },682    {683        "instruction": "Write a function of recursion list sum.",684        "response": "def recursive_list_sum(data_list):\r\n\ttotal = 0\r\n\tfor element in data_list:\r\n\t\tif type(element) == type([]):\r\n\t\t\ttotal = total + recursive_list_sum(element)\r\n\t\telse:\r\n\t\t\ttotal = total + element\r\n\treturn total"685    },686    {687        "instruction": "Write a function to find the number of rotations in a circularly sorted array.",688        "response": "def find_rotation_count(A):\r\n    (left, right) = (0, len(A) - 1)\r\n    while left <= right:\r\n        if A[left] <= A[right]:\r\n            return left\r\n        mid = (left + right) // 2\r\n        next = (mid + 1) % len(A)\r\n        prev = (mid - 1 + len(A)) % len(A)\r\n        if A[mid] <= A[next] and A[mid] <= A[prev]:\r\n            return mid\r\n        elif A[mid] <= A[right]:\r\n            right = mid - 1\r\n        elif A[mid] >= A[left]:\r\n            left = mid + 1\r\n    return -1"689    },690    {691        "instruction": "Write a function to find perfect squares between two given numbers.",692        "response": "def perfect_squares(a, b):\r\n    lists=[]\r\n    for i in range (a,b+1):\r\n        j = 1;\r\n        while j*j <= i:\r\n            if j*j == i:\r\n                 lists.append(i)  \r\n            j = j+1\r\n        i = i+1\r\n    return lists"693    },694    {695        "instruction": "Write a function to remove consecutive duplicates of a given list.",696        "response": "from itertools import groupby\r\ndef consecutive_duplicates(nums):\r\n    return [key for key, group in groupby(nums)] "697    },698    {699        "instruction": "Write a function to solve tiling problem.",700        "response": "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);"701    },702    {703        "instruction": "Write a python function to check whether a given sequence is linear or not.",704        "response": "def Seq_Linear(seq_nums):\r\n  seq_nums = [seq_nums[x] - seq_nums[x-1] for x in range(1, len(seq_nums))]\r\n  if len(set(seq_nums)) == 1: \r\n    return \"Linear Sequence\"\r\n  else:\r\n    return \"Non Linear Sequence\""705    },706    {707        "instruction": "Write a function to extract the ranges that are missing from the given list with the given start range and end range values.",708        "response": "def extract_missing(test_list, strt_val, stop_val):\r\n  res = []\r\n  for sub in test_list:\r\n    if sub[0] > strt_val:\r\n      res.append((strt_val, sub[0]))\r\n      strt_val = sub[1]\r\n    if strt_val < stop_val:\r\n      res.append((strt_val, stop_val))\r\n  return (res) "709    },710    {711        "instruction": "Write a python function to find the largest triangle that can be inscribed in the semicircle.",712        "response": "def triangle_area(r) :  \r\n    if r < 0 : \r\n        return -1\r\n    return r * r "713    },714    {715        "instruction": "Write a function to check if the common elements between two given lists are in the same order or not.",716        "response": "def same_order(l1, l2):\r\n    common_elements = set(l1) & set(l2)\r\n    l1 = [e for e in l1 if e in common_elements]\r\n    l2 = [e for e in l2 if e in common_elements]\r\n    return l1 == l2"717    },718    {719        "instruction": "Write a function to check if a nested list is a subset of another nested list.",720        "response": "def check_subset_list(list1, list2): \r\n    l1, l2 = list1[0], list2[0] \r\n    exist = True\r\n    for i in list2: \r\n        if i not in list1: \r\n            exist = False\r\n    return exist "721    },722    {723        "instruction": "Write a function that matches a word at the end of a string, with optional punctuation.",724        "response": "import re\r\ndef text_match_word(text):\r\n        patterns = '\\w+\\S*$'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return 'Not matched!'"725    },726    {727        "instruction": "Write a python function to find the sublist having maximum length.",728        "response": "def Find_Max(lst): \r\n    maxList = max((x) for x in lst) \r\n    return maxList"729    },730    {731        "instruction": "Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).",732        "response": "def sum_series(n):\r\n  if n < 1:\r\n    return 0\r\n  else:\r\n    return n + sum_series(n - 2)"733    },734    {735        "instruction": "Write a python function to count the number of digits of a given number.",736        "response": "def count_Digit(n):\r\n    count = 0\r\n    while n != 0:\r\n        n //= 10\r\n        count += 1\r\n    return count"737    },738    {739        "instruction": "Write a function to find the nested list elements which are present in another list.",740        "response": "def intersection_nested_lists(l1, l2):\r\n    result = [[n for n in lst if n in l1] for lst in l2]\r\n    return result"741    },742    {743        "instruction": "Write a function to calculate the sum of all digits of the base to the specified power.",744        "response": "def power_base_sum(base, power):\r\n    return sum([int(i) for i in str(pow(base, power))])"745    },746    {747        "instruction": "Write a function to find whether all the given tuples have equal length or not.",748        "response": "def find_equal_tuple(Input, k):\r\n  flag = 1\r\n  for tuple in Input:\r\n    if len(tuple) != k:\r\n      flag = 0\r\n      break\r\n  return flag\r\ndef get_equal(Input, k):\r\n  if find_equal_tuple(Input, k) == 1:\r\n    return (\"All tuples have same length\")\r\n  else:\r\n    return (\"All tuples do not have same length\")"749    },750    {751        "instruction": "Write a python function to check whether the product of digits of a number at even and odd places is equal or not.",752        "response": "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"753    },754    {755        "instruction": "Write a python function to find the first odd number in a given list of numbers.",756        "response": "def first_odd(nums):\r\n  first_odd = next((el for el in nums if el%2!=0),-1)\r\n  return first_odd"757    },758    {759        "instruction": "Write a function to find sum of the numbers in a list between the indices of a specified range.",760        "response": "def sum_range_list(list1, m, n):                                                                                                                                                                                                \r\n    sum_range = 0                                                                                                                                                                                                         \r\n    for i in range(m, n+1, 1):                                                                                                                                                                                        \r\n        sum_range += list1[i]                                                                                                                                                                                                  \r\n    return sum_range   "761    },762    {763        "instruction": "Write a python function to find the sum of all odd natural numbers within the range l and r.",764        "response": "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)"765    },766    {767        "instruction": "Write a python function to find the largest negative number from the given list.",768        "response": "def largest_neg(list1): \r\n    max = list1[0] \r\n    for x in list1: \r\n        if x < max : \r\n             max = x  \r\n    return max"769    },770    {771        "instruction": "Write a python function to count number of substrings with the sum of digits equal to their length.",772        "response": "from collections import defaultdict\r\ndef count_Substrings(s,n):\r\n    count,sum = 0,0\r\n    mp = defaultdict(lambda : 0)\r\n    mp[0] += 1\r\n    for i in range(n):\r\n        sum += ord(s[i]) - ord('0')\r\n        count += mp[sum - (i + 1)]\r\n        mp[sum - (i + 1)] += 1\r\n    return count"773    },774    {775        "instruction": "Write a python function to find the product of non-repeated elements in a given array.",776        "response": "def find_Product(arr,n): \r\n    arr.sort() \r\n    prod = 1\r\n    for i in range(0,n,1): \r\n        if (arr[i - 1] != arr[i]): \r\n            prod = prod * arr[i] \r\n    return prod; "777    },778    {779        "instruction": "Write a function to perform the adjacent element concatenation in the given tuples.",780        "response": "def concatenate_elements(test_tup):\r\n  res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))\r\n  return (res) "781    },782    {783        "instruction": "Write a function to extract values between quotation marks of a string.",784        "response": "import re\r\ndef extract_values(text):\r\n return (re.findall(r'\"(.*?)\"', text))"785    },786    {787        "instruction": "Write a python function to find the minimum sum of absolute differences of two arrays.",788        "response": "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"789    },790    {791        "instruction": "Write a python function to convert complex numbers to polar coordinates.",792        "response": "import cmath  \r\ndef convert(numbers):    \r\n  num = cmath.polar(numbers)  \r\n  return (num) "793    },794    {795        "instruction": "Write a function to sum elements in two lists.",796        "response": "def sum_list(lst1,lst2):\r\n  res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] \r\n  return res_list"797    },798    {799        "instruction": "Write a function to multiply two lists using map and lambda function.",800        "response": "def mul_list(nums1,nums2):\r\n  result = map(lambda x, y: x * y, nums1, nums2)\r\n  return list(result)"801    },802    {803        "instruction": "Write a function to find the largest palindromic number in the given array.",804        "response": "def is_palindrome(n) : \r\n\tdivisor = 1\r\n\twhile (n / divisor >= 10) : \r\n\t\tdivisor *= 10\r\n\twhile (n != 0) : \r\n\t\tleading = n // divisor \r\n\t\ttrailing = n % 10\r\n\t\tif (leading != trailing) : \r\n\t\t\treturn False\r\n\t\tn = (n % divisor) // 10\r\n\t\tdivisor = divisor // 100\r\n\treturn True\r\ndef largest_palindrome(A, n) : \r\n\tA.sort() \r\n\tfor i in range(n - 1, -1, -1) : \r\n\t\tif (is_palindrome(A[i])) : \r\n\t\t\treturn A[i] \r\n\treturn -1"805    },806    {807        "instruction": "Write a python function to find the surface area of the square pyramid.",808        "response": "def surface_Area(b,s): \r\n    return 2 * b * s + pow(b,2) "809    },810    {811        "instruction": "Write a function to find the combinations of sums with tuples in the given tuple list.",812        "response": "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) "813    },814    {815        "instruction": "Write a python function to left rotate the bits of a given number.",816        "response": "INT_BITS = 32\r\ndef left_Rotate(n,d):   \r\n    return (n << d)|(n >> (INT_BITS - d))  "817    },818    {819        "instruction": "Write a python function to find the hamming distance between given two integers.",820        "response": "def hamming_Distance(n1,n2) : \r\n    x = n1 ^ n2  \r\n    setBits = 0\r\n    while (x > 0) : \r\n        setBits += x & 1\r\n        x >>= 1\r\n    return setBits  "821    },822    {823        "instruction": "Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.",824        "response": "def sum_positivenum(nums):\r\n  sum_positivenum = list(filter(lambda nums:nums>0,nums))\r\n  return sum(sum_positivenum)"825    },826    {827        "instruction": "Write a python function to find the sum of fifth power of first n even natural numbers.",828        "response": "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*j); \r\n    return sum; "829    },830    {831        "instruction": "Write a python function to find the first repeated character in a given string.",832        "response": "def first_Repeated_Char(str): \r\n    h = {}\r\n    for ch in str:\r\n        if ch in h: \r\n            return ch;\r\n        else: \r\n            h[ch] = 0\r\n    return '\\0'"833    },834    {835        "instruction": "Write a python function to count the number of rectangles in a circle of radius r.",836        "response": "def count_Rectangles(radius):  \r\n    rectangles = 0 \r\n    diameter = 2 * radius \r\n    diameterSquare = diameter * diameter \r\n    for a in range(1, 2 * radius):  \r\n        for b in range(1, 2 * radius): \r\n            diagnalLengthSquare = (a * a +  b * b)  \r\n            if (diagnalLengthSquare <= diameterSquare) : \r\n                rectangles += 1\r\n    return rectangles "837    },838    {839        "instruction": "Write a function to perform the mathematical bitwise xor operation across the given tuples.",840        "response": "def bitwise_xor(test_tup1, test_tup2):\r\n  res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))\r\n  return (res) "841    },842    {843        "instruction": "Write a function to convert snake case string to camel case string.",844        "response": "def snake_to_camel(word):\r\n        import re\r\n        return ''.join(x.capitalize() or '_' for x in word.split('_'))"845    },846    {847        "instruction": "Write a function to count character frequency of a given string.",848        "response": "def char_frequency(str1):\r\n    dict = {}\r\n    for n in str1:\r\n        keys = dict.keys()\r\n        if n in keys:\r\n            dict[n] += 1\r\n        else:\r\n            dict[n] = 1\r\n    return dict"849    },850    {851        "instruction": "Write a function to find the item with maximum frequency in a given list.",852        "response": "from collections import defaultdict\r\ndef max_occurrences(nums):\r\n    dict = defaultdict(int)\r\n    for i in nums:\r\n        dict[i] += 1\r\n    result = max(dict.items(), key=lambda x: x[1]) \r\n    return result"853    },854    {855        "instruction": "Write a function to find minimum of three numbers.",856        "response": "def min_of_three(a,b,c): \r\n      if (a <= b) and (a <= c): \r\n        smallest = a \r\n      elif (b <= a) and (b <= c): \r\n        smallest = b \r\n      else: \r\n        smallest = c \r\n      return smallest "857    },858    {859        "instruction": "Write a function to search some literals strings in a string.",860        "response": "import re\r\ndef string_literals(patterns,text):\r\n  for pattern in patterns:\r\n     if re.search(pattern,  text):\r\n       return ('Matched!')\r\n     else:\r\n       return ('Not Matched!')"861    },862    {863        "instruction": "Write a function to put spaces between words starting with capital letters in a given string by using regex.",864        "response": "import re\r\ndef capital_words_spaces(str1):\r\n  return re.sub(r\"(\\w)([A-Z])\", r\"\\1 \\2\", str1)"865    },866    {867        "instruction": "Write a python function to find whether the given number is present in the infinite sequence or not.",868        "response": "def does_Contain_B(a,b,c): \r\n    if (a == b): \r\n        return True\r\n    if ((b - a) * c > 0 and (b - a) % c == 0): \r\n        return True\r\n    return False"869    },870    {871        "instruction": "Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.",872        "response": "import heapq\r\ndef k_smallest_pairs(nums1, nums2, k):\r\n   queue = []\r\n   def push(i, j):\r\n       if i < len(nums1) and j < len(nums2):\r\n           heapq.heappush(queue, [nums1[i] + nums2[j], i, j])\r\n   push(0, 0)\r\n   pairs = []\r\n   while queue and len(pairs) < k:\r\n       _, i, j = heapq.heappop(queue)\r\n       pairs.append([nums1[i], nums2[j]])\r\n       push(i, j + 1)\r\n       if j == 0:\r\n           push(i + 1, 0)\r\n   return pairs"873    },874    {875        "instruction": "Write a python function to accept the strings which contains all vowels.",876        "response": "def check(string): \r\n  if len(set(string).intersection(\"AEIOUaeiou\"))>=5: \r\n    return ('accepted') \r\n  else: \r\n    return (\"not accepted\") "877    },878    {879        "instruction": "Write a python function to find the difference between sum of even and odd digits.",880        "response": "def is_Diff(n): \r\n    return (n % 11 == 0) "881    },882    {883        "instruction": "Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.",884        "response": "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 "885    },886    {887        "instruction": "Write a function to find the inversions of tuple elements in the given tuple list.",888        "response": "def inversion_elements(test_tup):\r\n  res = tuple(list(map(lambda x: ~x, list(test_tup))))\r\n  return (res) "889    },890    {891        "instruction": "Write a function to find the directrix of a parabola.",892        "response": "def parabola_directrix(a, b, c): \r\n  directrix=((int)(c - ((b * b) + 1) * 4 * a ))\r\n  return directrix"893    },894    {895        "instruction": "Write a function to check whether an element exists within a tuple.",896        "response": "def check_tuplex(tuplex,tuple1): \r\n  if tuple1 in tuplex:\r\n    return True\r\n  else:\r\n     return False"897    },898    {899        "instruction": "Write a python function to print duplicants from a list of integers.",900        "response": "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 "901    },902    {903        "instruction": "Write a function to extract the maximum numeric value from a string by using regex.",904        "response": "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)"905    },906    {907        "instruction": "Write a python function to find the maximum element in a sorted and rotated array.",908        "response": "def find_Max(arr,low,high): \r\n    if (high < low): \r\n        return arr[0] \r\n    if (high == low): \r\n        return arr[low] \r\n    mid = low + (high - low) // 2 \r\n    if (mid < high and arr[mid + 1] < arr[mid]): \r\n        return arr[mid] \r\n    if (mid > low and arr[mid] < arr[mid - 1]): \r\n        return arr[mid - 1]  \r\n    if (arr[low] > arr[mid]): \r\n        return find_Max(arr,low,mid - 1) \r\n    else: \r\n        return find_Max(arr,mid + 1,high) "909    },910    {911        "instruction": "Write a function to add consecutive numbers of a given list.",912        "response": "def add_consecutive_nums(nums):\r\n    result = [b+a for a, b in zip(nums[:-1], nums[1:])]\r\n    return result"913    },914    {915        "instruction": "Write a function to remove all elements from a given list present in another list.",916        "response": "def remove_elements(list1, list2):\r\n    result = [x for x in list1 if x not in list2]\r\n    return result"917    },918    {919        "instruction": "Write a function to find the largest subset where each pair is divisible.",920        "response": "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)"921    },922    {923        "instruction": "Write a python function to interchange the first and last elements in a list.",924        "response": "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 "925    },926    {927        "instruction": "Write a python function to find the first digit of a given number.",928        "response": "def first_Digit(n) :  \r\n    while n >= 10:  \r\n        n = n / 10; \r\n    return int(n) "929    },930    {931        "instruction": "Write a function to check whether the given month number contains 30 days or not.",932        "response": "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"933    },934    {935        "instruction": "Write a python function to count number of vowels in the string.",936        "response": "def Check_Vow(string, vowels): \r\n    final = [each for each in string if each in vowels] \r\n    return(len(final)) \r\n"937    },938    {939        "instruction": "Write a function to get the frequency of the elements in a list.",940        "response": "import collections\r\ndef freq_count(list1):\r\n  freq_count= collections.Counter(list1)\r\n  return freq_count"941    },942    {943        "instruction": "Write a python function to convert a given string list to a tuple.",944        "response": "def string_list_to_tuple(str1):\r\n    result = tuple(x for x in str1 if not x.isspace()) \r\n    return result"945    },946    {947        "instruction": "Write a function to count total characters in a string.",948        "response": "def count_charac(str1):\r\n total = 0\r\n for i in str1:\r\n    total = total + 1\r\n return total"949    },950    {951        "instruction": "Write a python function to multiply all items in the list.",952        "response": "def multiply_list(items):\r\n    tot = 1\r\n    for x in items:\r\n        tot *= x\r\n    return tot"953    },954    {955        "instruction": "Write a function to find the median of a trapezium.",956        "response": "def median_trapezium(base1,base2,height):\r\n median = 0.5 * (base1+ base2)\r\n return median"957    },958    {959        "instruction": "Write a function to add the given list to the given tuples.",960        "response": "def add_lists(test_list, test_tup):\r\n  res = tuple(list(test_tup) + test_list)\r\n  return (res) "961    },962    {963        "instruction": "Write a python function to find the sum of absolute differences in all pairs of the given array.",964        "response": "def sum_Pairs(arr,n): \r\n    sum = 0\r\n    for i in range(n - 1,-1,-1): \r\n        sum += i*arr[i] - (n-1-i) * arr[i] \r\n    return sum"965    },966    {967        "instruction": "Write a function to repeat the given tuple n times.",968        "response": "def repeat_tuples(test_tup, N):\r\n  res = ((test_tup, ) * N)\r\n  return (res) "969    },970    {971        "instruction": "Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.",972        "response": "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"973    },974    {975        "instruction": "Write a function to find out the minimum no of swaps required for bracket balancing in the given string.",976        "response": "def swap_count(s):\r\n\tchars = s\r\n\tcount_left = 0\r\n\tcount_right = 0\r\n\tswap = 0\r\n\timbalance = 0; \r\n\tfor i in range(len(chars)):\r\n\t\tif chars[i] == '[':\r\n\t\t\tcount_left += 1\r\n\t\t\tif imbalance > 0:\r\n\t\t\t\tswap += imbalance\r\n\t\t\t\timbalance -= 1\r\n\t\telif chars[i] == ']':\r\n\t\t\tcount_right += 1\r\n\t\t\timbalance = (count_right - count_left) \r\n\treturn swap"977    },978    {979        "instruction": "Write a function to sort the given list based on the occurrence of first element of tuples.",980        "response": "def sort_on_occurence(lst): \r\n\tdct = {} \r\n\tfor i, j in lst: \r\n\t\tdct.setdefault(i, []).append(j) \r\n\treturn ([(i, *dict.fromkeys(j), len(j)) \r\n\t\t\t\tfor i, j in dct.items()]) "981    },982    {983        "instruction": "Write a function to split a given list into two parts where the length of the first part of the list is given.",984        "response": "def split_two_parts(list1, L):\r\n    return list1[:L], list1[L:]"985    },986    {987        "instruction": "Write a function to remove duplicate words from a given string using collections module.",988        "response": "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"989    },990    {991        "instruction": "Write a function to reverse each list in a given list of lists.",992        "response": "def reverse_list_lists(lists):\r\n    for l in lists:\r\n        l.sort(reverse = True)\r\n    return lists "993    },994    {995        "instruction": "Write a python function to find the first position of an element in a sorted array.",996        "response": "def first(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            high = mid - 1\r\n    return res"997    },998    {999        "instruction": "Write a function to extract unique values from the given dictionary values.",1000        "response": "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"1001    },1002    {1003        "instruction": "Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.",1004        "response": "def Check_Solution(a,b,c):  \r\n    if b == 0:  \r\n        return (\"Yes\")  \r\n    else: \r\n        return (\"No\")  "1005    },1006    {1007        "instruction": "Write a function to check if the given tuples contain the k or not.",1008        "response": "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) "1009    },1010    {1011        "instruction": "Write a function to find average value of the numbers in a given tuple of tuples.",1012        "response": "def average_tuple(nums):\r\n    result = [sum(x) / len(x) for x in zip(*nums)]\r\n    return result"1013    },1014    {1015        "instruction": "Write a function to separate and print the numbers and their position of a given string.",1016        "response": "import re\r\ndef num_position(text):\r\n for m in re.finditer(\"\\d+\", text):\r\n    return m.start()"1017    },1018    {1019        "instruction": "Write a python function to find the maximum length of sublist.",1020        "response": "def Find_Max_Length(lst):  \r\n    maxLength = max(len(x) for x in lst )\r\n    return maxLength "1021    },1022    {1023        "instruction": "Write a function to find all words starting with 'a' or 'e' in a given string.",1024        "response": "import re\r\ndef words_ae(text):\r\n list = re.findall(\"[ae]\\w+\", text)\r\n return list"1025    },1026    {1027        "instruction": "Write a function to find the longest common prefix in the given set of strings.",1028        "response": "def common_prefix_util(str1, str2): \r\n\tresult = \"\"; \r\n\tn1 = len(str1) \r\n\tn2 = len(str2) \r\n\ti = 0\r\n\tj = 0\r\n\twhile i <= n1 - 1 and j <= n2 - 1: \r\n\t\tif (str1[i] != str2[j]): \r\n\t\t\tbreak\r\n\t\tresult += str1[i] \r\n\t\ti += 1\r\n\t\tj += 1\r\n\treturn (result) \r\ndef common_prefix (arr, n): \r\n\tprefix = arr[0] \r\n\tfor i in range (1, n): \r\n\t\tprefix = common_prefix_util(prefix, arr[i]) \r\n\treturn (prefix) "1029    },1030    {1031        "instruction": "Write a function to find the number which occurs for odd number of times in the given array.",1032        "response": "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"1033    },1034    {1035        "instruction": "Write a function to check whether the given string starts and ends with the same character or not using regex.",1036        "response": "import re  \r\nregex = r'^[a-z]$|^([a-z]).*\\1$'\r\ndef check_char(string): \r\n\tif(re.search(regex, string)): \r\n\t\treturn \"Valid\" \r\n\telse: \r\n\t\treturn \"Invalid\" "1037    },1038    {1039        "instruction": "Write a function to sum all amicable numbers from 1 to a specified number.",1040        "response": "def amicable_numbers_sum(limit):\r\n    if not isinstance(limit, int):\r\n        return \"Input is not an integer!\"\r\n    if limit < 1:\r\n        return \"Input must be bigger than 0!\"\r\n    amicables = set()\r\n    for num in range(2, limit+1):\r\n        if num in amicables:\r\n            continue\r\n        sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])\r\n        sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])\r\n        if num == sum_fact2 and num != sum_fact:\r\n            amicables.add(num)\r\n            amicables.add(sum_fact2)\r\n    return sum(amicables)"1041    },1042    {1043        "instruction": "Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.",1044        "response": "def max_product(arr, n ): \r\n\tmpis =[0] * (n) \r\n\tfor i in range(n): \r\n\t\tmpis[i] = arr[i] \r\n\tfor i in range(1, n): \r\n\t\tfor j in range(i): \r\n\t\t\tif (arr[i] > arr[j] and\r\n\t\t\t\t\tmpis[i] < (mpis[j] * arr[i])): \r\n\t\t\t\t\t\tmpis[i] = mpis[j] * arr[i] \r\n\treturn max(mpis)"1045    },1046    {1047        "instruction": "Write a function to convert a tuple of string values to a tuple of integer values.",1048        "response": "def tuple_int_str(tuple_str):\r\n    result = tuple((int(x[0]), int(x[1])) for x in tuple_str)\r\n    return result"1049    },1050    {1051        "instruction": "Write a function to count repeated items of a tuple.",1052        "response": "def count_tuplex(tuplex,value):  \r\n  count = tuplex.count(value)\r\n  return count"1053    },1054    {1055        "instruction": "Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.",1056        "response": "import heapq as hq\r\ndef raw_heap(rawheap):\r\n  hq.heapify(rawheap)\r\n  return rawheap"1057    },1058    {1059        "instruction": "Write a python function to find common divisor between two numbers in a given pair.",1060        "response": "def ngcd(x,y):\r\n    i=1\r\n    while(i<=x and i<=y):\r\n        if(x%i==0 and y%i == 0):\r\n            gcd=i;\r\n        i+=1\r\n    return gcd;\r\ndef num_comm_div(x,y):\r\n  n = ngcd(x,y)\r\n  result = 0\r\n  z = int(n**0.5)\r\n  i = 1\r\n  while(i <= z):\r\n    if(n % i == 0):\r\n      result += 2 \r\n      if(i == n/i):\r\n        result-=1\r\n    i+=1\r\n  return result"1061    },1062    {1063        "instruction": "Write a python function to find the sum of fourth power of first n even natural numbers.",1064        "response": "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; "1065    },1066    {1067        "instruction": "Write a python function to find the largest prime factor of a given number.",1068        "response": "import math \r\ndef max_Prime_Factors (n): \r\n    maxPrime = -1 \r\n    while n%2 == 0: \r\n        maxPrime = 2\r\n        n >>= 1    \r\n    for i in range(3,int(math.sqrt(n))+1,2): \r\n        while n % i == 0: \r\n            maxPrime = i \r\n            n = n / i \r\n    if n > 2: \r\n        maxPrime = n  \r\n    return int(maxPrime)"1069    },1070    {1071        "instruction": "Write a function to find the focus of a parabola.",1072        "response": "def parabola_focus(a, b, c): \r\n  focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))\r\n  return focus"1073    },1074    {1075        "instruction": "Write a function to find the median of two sorted arrays of same size.",1076        "response": "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"1077    },1078    {1079        "instruction": "Write a python function to remove first and last occurrence of a given character from the string.",1080        "response": "def remove_Occ(s,ch): \r\n    for i in range(len(s)): \r\n        if (s[i] == ch): \r\n            s = s[0 : i] + s[i + 1:] \r\n            break\r\n    for i in range(len(s) - 1,-1,-1):  \r\n        if (s[i] == ch): \r\n            s = s[0 : i] + s[i + 1:] \r\n            break\r\n    return s "1081    },1082    {1083        "instruction": "Write a python function to count number of non-empty substrings of a given string.",1084        "response": "def number_of_substrings(str): \r\n\tstr_len = len(str); \r\n\treturn int(str_len * (str_len + 1) / 2); "1085    },1086    {1087        "instruction": "Write a python function to find the smallest missing number from the given array.",1088        "response": "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) "1089    },1090    {1091        "instruction": "Write a function to find the nth octagonal number.",1092        "response": "def is_octagonal(n): \r\n\treturn 3 * n * n - 2 * n "1093    },1094    {1095        "instruction": "Write a function to count those characters which have vowels as their neighbors in the given string.",1096        "response": "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) "1097    },1098    {1099        "instruction": "Write a function to find x and y that satisfies ax + by = n.",1100        "response": "def solution (a, b, n): \r\n\ti = 0\r\n\twhile i * a <= n: \r\n\t\tif (n - (i * a)) % b == 0: \r\n\t\t\treturn (\"x = \",i ,\", y = \", \r\n\t\t\tint((n - (i * a)) / b)) \r\n\t\t\treturn 0\r\n\t\ti = i + 1\r\n\treturn (\"No solution\") "1101    },1102    {1103        "instruction": "Write a function to remove all characters except letters and numbers using regex",1104        "response": "import re \r\ndef remove_char(S):\r\n  result = re.sub('[\\W_]+', '', S) \r\n  return result"1105    },1106    {1107        "instruction": "Write a function to check whether all items of a list are equal to a given string.",1108        "response": "def check_element(list,element):\r\n  check_element=all(v== element for v in list)\r\n  return check_element"1109    },1110    {1111        "instruction": "Write a function to check if a string represents an integer or not.",1112        "response": "def check_integer(text):\r\n text = text.strip()\r\n if len(text) < 1:\r\n    return None\r\n else:\r\n     if all(text[i] in \"0123456789\" for i in range(len(text))):\r\n          return True\r\n     elif (text[0] in \"+-\") and \\\r\n         all(text[i] in \"0123456789\" for i in range(1,len(text))):\r\n         return True\r\n     else:\r\n        return False"1113    },1114    {1115        "instruction": "Write a function to check whether a list contains the given sublist or not.",1116        "response": "def is_sublist(l, s):\r\n\tsub_set = False\r\n\tif s == []:\r\n\t\tsub_set = True\r\n\telif s == l:\r\n\t\tsub_set = True\r\n\telif len(s) > len(l):\r\n\t\tsub_set = False\r\n\telse:\r\n\t\tfor i in range(len(l)):\r\n\t\t\tif l[i] == s[0]:\r\n\t\t\t\tn = 1\r\n\t\t\t\twhile (n < len(s)) and (l[i+n] == s[n]):\r\n\t\t\t\t\tn += 1\t\t\t\t\r\n\t\t\t\tif n == len(s):\r\n\t\t\t\t\tsub_set = True\r\n\treturn sub_set"1117    },1118    {1119        "instruction": "Write a python function to find the maximum occurring character in a given string.",1120        "response": "def get_max_occuring_char(str1):\r\n  ASCII_SIZE = 256\r\n  ctr = [0] * ASCII_SIZE\r\n  max = -1\r\n  ch = ''\r\n  for i in str1:\r\n    ctr[ord(i)]+=1;\r\n  for i in str1:\r\n    if max < ctr[ord(i)]:\r\n      max = ctr[ord(i)]\r\n      ch = i\r\n  return ch"1121    },1122    {1123        "instruction": "Write a python function to find the minimun number of subsets with distinct elements.",1124        "response": "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 "1125    },1126    {1127        "instruction": "Write a python function to find the first repeated character in a given string.",1128        "response": "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\""1129    },1130    {1131        "instruction": "Write a function for nth catalan number.",1132        "response": "def catalan_number(num):\r\n    if num <=1:\r\n         return 1   \r\n    res_num = 0\r\n    for i in range(num):\r\n        res_num += catalan_number(i) * catalan_number(num-i-1)\r\n    return res_num"1133    },1134    {1135        "instruction": "Write a function to compute the sum of digits of each number of a given list.",1136        "response": "def sum_of_digits(nums):\r\n    return sum(int(el) for n in nums for el in str(n) if el.isdigit())"1137    },1138    {1139        "instruction": "Write a python function to find the sum of all even natural numbers within the range l and r.",1140        "response": "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))) "1141    },1142    {1143        "instruction": "Write a function to split a string at uppercase letters.",1144        "response": "import re\r\ndef split_upperstring(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))"1145    },1146    {1147        "instruction": "Write a function to check whether the given month name contains 31 days or not.",1148        "response": "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"1149    },1150    {1151        "instruction": "Write a function to find the surface area of a cuboid.",1152        "response": "def surfacearea_cuboid(l,w,h):\r\n  SA = 2*(l*w + l * h + w * h)\r\n  return SA"1153    },1154    {1155        "instruction": "Write a function to find the minimum total path sum in the given triangle.",1156        "response": "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]"1157    },1158    {1159        "instruction": "Write a function to trim each tuple by k in the given tuple list.",1160        "response": "def trim_tuple(test_list, K):\r\n  res = []\r\n  for ele in test_list:\r\n    N = len(ele)\r\n    res.append(tuple(list(ele)[K: N - K]))\r\n  return (str(res)) "1161    },1162    {1163        "instruction": "Write a function to remove all whitespaces from the given string using regex.",1164        "response": "import re\r\ndef remove_whitespaces(text1):\r\n  return (re.sub(r'\\s+', '',text1))"1165    },1166    {1167        "instruction": "Write a function to sort a given mixed list of integers and strings.",1168        "response": "def sort_mixed_list(mixed_list):\r\n    int_part = sorted([i for i in mixed_list if type(i) is int])\r\n    str_part = sorted([i for i in mixed_list if type(i) is str])\r\n    return int_part + str_part"1169    },1170    {1171        "instruction": "Write a function that matches a string that has an a followed by zero or one 'b'.",1172        "response": "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!')"1173    },1174    {1175        "instruction": "Write a function to convert an integer into a roman numeral.",1176        "response": "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"1177    },1178    {1179        "instruction": "Write 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.",1180        "response": "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"1181    },1182    {1183        "instruction": "Write a function to find the largest possible value of k such that k modulo x is y.",1184        "response": "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) "1185    },1186    {1187        "instruction": "Write a python function to find minimum possible value for the given periodic function.",1188        "response": "def floor_Min(A,B,N):\r\n    x = max(B - 1,N)\r\n    return (A*x) // B"1189    },1190    {1191        "instruction": "Write a python function to find k number of operations required to make all elements equal.",1192        "response": "def min_Ops(arr,n,k): \r\n    max1 = max(arr) \r\n    res = 0\r\n    for i in range(0,n):  \r\n        if ((max1 - arr[i]) % k != 0): \r\n            return -1 \r\n        else: \r\n            res += (max1 - arr[i]) / k \r\n    return int(res) "1193    },1194    {1195        "instruction": "Write a python function to toggle all even bits of a given number.",1196        "response": "def even_bit_toggle_number(n) : \r\n    res = 0; count = 0; temp = n \r\n    while (temp > 0) :     \r\n        if (count % 2 == 1) : \r\n            res = res | (1 << count)      \r\n        count = count + 1\r\n        temp >>= 1 \r\n    return n ^ res "1197    },1198    {1199        "instruction": "Write a function to check if the given tuple has any none value or not.",1200        "response": "def check_none(test_tup):\r\n  res = any(map(lambda ele: ele is None, test_tup))\r\n  return (res) "

Showing the first 1,200 of 3118 lines. Download the file for the rest.