File size: 69,806 Bytes
6fbe100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
{"text": "### Instruction\nWrite a python function to remove first and last occurrence of a given character from the string.\n\n### Response\ndef 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 ", "source_id": "11"}
{"text": "### Instruction\nWrite a function to sort a given matrix in ascending order according to the sum of its rows.\n\n### Response\ndef sort_matrix(M):\r\n    result = sorted(M, key=sum)\r\n    return result", "source_id": "12"}
{"text": "### Instruction\nWrite a function to count the most common words in a dictionary.\n\n### Response\nfrom collections import Counter\r\ndef count_common(words):\r\n  word_counts = Counter(words)\r\n  top_four = word_counts.most_common(4)\r\n  return (top_four)\r\n", "source_id": "13"}
{"text": "### Instruction\nWrite a python function to find the volume of a triangular prism.\n\n### Response\ndef find_Volume(l,b,h) : \r\n    return ((l * b * h) / 2) ", "source_id": "14"}
{"text": "### Instruction\nWrite a function to split a string at lowercase letters.\n\n### Response\nimport re\r\ndef split_lowerstring(text):\r\n return (re.findall('[a-z][^a-z]*', text))", "source_id": "15"}
{"text": "### Instruction\nWrite a function to find sequences of lowercase letters joined with an underscore.\n\n### Response\nimport 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!')", "source_id": "16"}
{"text": "### Instruction\nWrite a function to find the perimeter of a square.\n\n### Response\ndef square_perimeter(a):\r\n  perimeter=4*a\r\n  return perimeter", "source_id": "17"}
{"text": "### Instruction\nWrite a function to remove characters from the first string which are present in the second string.\n\n### Response\nNO_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]) ", "source_id": "18"}
{"text": "### Instruction\nWrite a function to find whether a given array of integers contains any duplicate element.\n\n### Response\ndef test_duplicate(arraynums):\r\n    nums_set = set(arraynums)    \r\n    return len(arraynums) != len(nums_set)     ", "source_id": "19"}
{"text": "### Instruction\nWrite a function to check if the given number is woodball or not.\n\n### Response\ndef is_woodall(x): \r\n\tif (x % 2 == 0): \r\n\t\treturn False\r\n\tif (x == 1): \r\n\t\treturn True\r\n\tx = x + 1 \r\n\tp = 0\r\n\twhile (x % 2 == 0): \r\n\t\tx = x/2\r\n\t\tp = p + 1\r\n\t\tif (p == x): \r\n\t\t\treturn True\r\n\treturn False", "source_id": "20"}
{"text": "### Instruction\nWrite a function to find m number of multiples of n.\n\n### Response\ndef multiples_of_num(m,n): \r\n    multiples_of_num= list(range(n,(m+1)*n, n)) \r\n    return list(multiples_of_num)", "source_id": "21"}
{"text": "### Instruction\nWrite a function to find the first duplicate element in a given array of integers.\n\n### Response\ndef find_first_duplicate(nums):\r\n    num_set = set()\r\n    no_duplicate = -1\r\n\r\n    for i in range(len(nums)):\r\n\r\n        if nums[i] in num_set:\r\n            return nums[i]\r\n        else:\r\n            num_set.add(nums[i])\r\n\r\n    return no_duplicate", "source_id": "22"}
{"text": "### Instruction\nWrite a python function to find the maximum sum of elements of list in a list of lists.\n\n### Response\ndef maximum_Sum(list1): \r\n    maxi = -100000\r\n    for x in list1: \r\n        sum = 0 \r\n        for y in x: \r\n            sum+= y      \r\n        maxi = max(sum,maxi)     \r\n    return maxi ", "source_id": "23"}
{"text": "### Instruction\nWrite a function to convert the given binary number to its decimal equivalent.\n\n### Response\ndef binary_to_decimal(binary): \r\n    binary1 = binary \r\n    decimal, i, n = 0, 0, 0\r\n    while(binary != 0): \r\n        dec = binary % 10\r\n        decimal = decimal + dec * pow(2, i) \r\n        binary = binary//10\r\n        i += 1\r\n    return (decimal)", "source_id": "24"}
{"text": "### Instruction\nWrite a python function to find the product of non-repeated elements in a given array.\n\n### Response\ndef 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; ", "source_id": "25"}
{"text": "### Instruction\nWrite a function to check if the given tuple list has all k elements.\n\n### Response\ndef check_k_elements(test_list, K):\r\n  res = True\r\n  for tup in test_list:\r\n    for ele in tup:\r\n      if ele != K:\r\n        res = False\r\n  return (res) ", "source_id": "26"}
{"text": "### Instruction\nWrite a python function to remove all digits from a list of strings.\n\n### Response\nimport re  \r\ndef remove(list): \r\n    pattern = '[0-9]'\r\n    list = [re.sub(pattern, '', i) for i in list] \r\n    return list", "source_id": "27"}
{"text": "### Instruction\nWrite a python function to find binomial co-efficient.\n\n### Response\ndef binomial_Coeff(n,k): \r\n    if k > n : \r\n       return 0\r\n    if k==0 or k ==n : \r\n        return 1 \r\n    return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) ", "source_id": "28"}
{"text": "### Instruction\nWrite a python function to find the element occurring odd number of times.\n\n### Response\ndef get_Odd_Occurrence(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", "source_id": "29"}
{"text": "### Instruction\nWrite a python function to count all the substrings starting and ending with same characters.\n\n### Response\ndef 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; ", "source_id": "30"}
{"text": "### Instruction\nWrite a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.\n\n### Response\ndef 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", "source_id": "31"}
{"text": "### Instruction\nWrite a python function to find the largest prime factor of a given number.\n\n### Response\nimport 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)", "source_id": "32"}
{"text": "### Instruction\nWrite a python function to convert a decimal number to binary number.\n\n### Response\ndef decimal_To_Binary(N): \r\n    B_Number = 0\r\n    cnt = 0\r\n    while (N != 0): \r\n        rem = N % 2\r\n        c = pow(10,cnt)  \r\n        B_Number += rem*c  \r\n        N //= 2 \r\n        cnt += 1\r\n    return B_Number  ", "source_id": "33"}
{"text": "### Instruction\nWrite a python function to find the missing number in a sorted array.\n\n### Response\ndef find_missing(ar,N): \r\n    l = 0\r\n    r = N - 1\r\n    while (l <= r):  \r\n        mid = (l + r) / 2\r\n        mid= int (mid) \r\n        if (ar[mid] != mid + 1 and ar[mid - 1] == mid): \r\n            return (mid + 1)  \r\n        elif (ar[mid] != mid + 1): \r\n            r = mid - 1 \r\n        else: \r\n            l = mid + 1\r\n    return (-1) ", "source_id": "34"}
{"text": "### Instruction\nWrite a function to find the n-th rectangular number.\n\n### Response\ndef find_rect_num(n):\r\n  return n*(n + 1) ", "source_id": "35"}
{"text": "### Instruction\nWrite a python function to find the nth digit in the proper fraction of two given numbers.\n\n### Response\ndef 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;  ", "source_id": "36"}
{"text": "### Instruction\nWrite a function to sort a given mixed list of integers and strings.\n\n### Response\ndef 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", "source_id": "37"}
{"text": "### Instruction\nWrite a function to find the division of first even and odd number of a given list.\n\n### Response\ndef 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)", "source_id": "38"}
{"text": "### Instruction\nWrite a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.\n\n### Response\nimport heapq\r\nfrom collections import Counter\r\ndef rearange_string(S):\r\n    ctr = Counter(S)\r\n    heap = [(-value, key) for key, value in ctr.items()]\r\n    heapq.heapify(heap)\r\n    if (-heap[0][0]) * 2 > len(S) + 1: \r\n        return \"\"\r\n    ans = []\r\n    while len(heap) >= 2:\r\n        nct1, char1 = heapq.heappop(heap)\r\n        nct2, char2 = heapq.heappop(heap)\r\n        ans.extend([char1, char2])\r\n        if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))\r\n        if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))\r\n    return \"\".join(ans) + (heap[0][1] if heap else \"\")", "source_id": "39"}
{"text": "### Instruction\nWrite a function to find frequency of the elements in a given list of lists using collections module.\n\n### Response\nfrom collections import Counter\r\nfrom itertools import chain\r\ndef freq_element(nums):\r\n  result = Counter(chain.from_iterable(nums))\r\n  return result", "source_id": "40"}
{"text": "### Instruction\nWrite a function to filter even numbers using lambda function.\n\n### Response\ndef filter_evennumbers(nums):\r\n even_nums = list(filter(lambda x: x%2 == 0, nums))\r\n return even_nums", "source_id": "41"}
{"text": "### Instruction\nWrite a python function to find the sum of repeated elements in a given array.\n\n### Response\ndef find_Sum(arr,n): \r\n    return sum([x for x in arr if arr.count(x) > 1])", "source_id": "42"}
{"text": "### Instruction\nWrite a function to find sequences of lowercase letters joined with an underscore using regex.\n\n### Response\nimport re\r\ndef text_match(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!')", "source_id": "43"}
{"text": "### Instruction\nWrite a function that matches a word at the beginning of a string.\n\n### Response\nimport re\r\ndef text_match_string(text):\r\n        patterns = '^\\w+'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return 'Not matched!'", "source_id": "44"}
{"text": "### Instruction\nWrite a function to find the gcd of the given array elements.\n\n### Response\ndef find_gcd(x, y): \r\n\twhile(y): \r\n\t\tx, y = y, x % y \r\n\treturn x \r\ndef get_gcd(l):\r\n  num1 = l[0]\r\n  num2 = l[1]\r\n  gcd = find_gcd(num1, num2)\r\n  for i in range(2, len(l)):\r\n    gcd = find_gcd(gcd, l[i])\r\n  return gcd", "source_id": "45"}
{"text": "### Instruction\nWrite a python function to determine whether all the numbers are different from each other are not.\n\n### Response\ndef test_distinct(data):\r\n  if len(data) == len(set(data)):\r\n    return True\r\n  else:\r\n    return False;", "source_id": "46"}
{"text": "### Instruction\nWrite a python function to find the last digit when factorial of a divides factorial of b.\n\n### Response\ndef compute_Last_Digit(A,B): \r\n    variable = 1\r\n    if (A == B): \r\n        return 1\r\n    elif ((B - A) >= 5):  \r\n        return 0\r\n    else:   \r\n        for i in range(A + 1,B + 1): \r\n            variable = (variable * (i % 10)) % 10\r\n        return variable % 10", "source_id": "47"}
{"text": "### Instruction\nWrite a python function to set all odd bits of a given number.\n\n### Response\ndef odd_bit_set_number(n):\r\n    count = 0;res = 0;temp = n\r\n    while temp > 0:\r\n        if count % 2 == 0:\r\n            res |= (1 << count)\r\n        count += 1\r\n        temp >>= 1\r\n    return (n | res)", "source_id": "48"}
{"text": "### Instruction\nWrite a function to extract every first or specified element from a given two-dimensional list.\n\n### Response\ndef specified_element(nums, N):\r\n    result = [i[N] for i in nums]\r\n    return result\r\n    ", "source_id": "49"}
{"text": "### Instruction\nWrite a function to find the list with minimum length using lambda function.\n\n### Response\ndef min_length_list(input_list):\r\n    min_length = min(len(x) for x in input_list )  \r\n    min_list = min(input_list, key = lambda i: len(i))\r\n    return(min_length, min_list)", "source_id": "50"}
{"text": "### Instruction\nWrite a function to print check if the triangle is equilateral or not.\n\n### Response\ndef check_equilateral(x,y,z):\r\n  if x == y == z:\r\n\t   return True\r\n  else:\r\n     return False", "source_id": "51"}
{"text": "### Instruction\nWrite a function to caluclate area of a parallelogram.\n\n### Response\ndef parallelogram_area(b,h):\r\n  area=b*h\r\n  return area", "source_id": "52"}
{"text": "### Instruction\nWrite a python function to check whether the first and last characters of a given string are equal or not.\n\n### Response\ndef check_Equality(str):\r\n  if (str[0] == str[-1]):  \r\n    return (\"Equal\") \r\n  else:  \r\n    return (\"Not Equal\") ", "source_id": "53"}
{"text": "### Instruction\nWrite a function to sort the given array by using counting sort.\n\n### Response\ndef counting_sort(my_list):\r\n    max_value = 0\r\n    for i in range(len(my_list)):\r\n        if my_list[i] > max_value:\r\n            max_value = my_list[i]\r\n    buckets = [0] * (max_value + 1)\r\n    for i in my_list:\r\n        buckets[i] += 1\r\n    i = 0\r\n    for j in range(max_value + 1):\r\n         for a in range(buckets[j]):\r\n             my_list[i] = j\r\n             i += 1\r\n    return my_list", "source_id": "54"}
{"text": "### Instruction\nWrite a function to find t-nth term of geometric series.\n\n### Response\nimport math\r\ndef tn_gp(a,n,r):\r\n  tn = a * (math.pow(r, n - 1))\r\n  return tn", "source_id": "55"}
{"text": "### Instruction\nWrite a python function to check if a given number is one less than twice its reverse.\n\n### Response\ndef rev(num):    \r\n    rev_num = 0\r\n    while (num > 0):  \r\n        rev_num = (rev_num * 10 + num % 10) \r\n        num = num // 10  \r\n    return rev_num  \r\ndef check(n):    \r\n    return (2 * rev(n) == n + 1)  ", "source_id": "56"}
{"text": "### Instruction\nWrite a python function to find the largest number that can be formed with the given digits.\n\n### Response\ndef find_Max_Num(arr,n) : \r\n    arr.sort(reverse = True) \r\n    num = arr[0] \r\n    for i in range(1,n) : \r\n        num = num * 10 + arr[i] \r\n    return num ", "source_id": "57"}
{"text": "### Instruction\nWrite a python function to check whether the given two integers have opposite sign or not.\n\n### Response\ndef opposite_Signs(x,y): \r\n    return ((x ^ y) < 0); ", "source_id": "58"}
{"text": "### Instruction\nWrite a function to find the nth octagonal number.\n\n### Response\ndef is_octagonal(n): \r\n\treturn 3 * n * n - 2 * n ", "source_id": "59"}
{"text": "### Instruction\nWrite a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.\n\n### Response\ndef max_len_sub( arr, n): \r\n\tmls=[] \r\n\tmax = 0\r\n\tfor i in range(n): \r\n\t\tmls.append(1) \r\n\tfor i in range(n): \r\n\t\tfor j in range(i): \r\n\t\t\tif (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): \r\n\t\t\t\tmls[i] = mls[j] + 1\r\n\tfor i in range(n): \r\n\t\tif (max < mls[i]): \r\n\t\t\tmax = mls[i] \r\n\treturn max", "source_id": "60"}
{"text": "### Instruction\nWrite a python function to count number of substrings with the sum of digits equal to their length.\n\n### Response\nfrom 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", "source_id": "61"}
{"text": "### Instruction\nWrite a python function to find smallest number in a list.\n\n### Response\ndef smallest_num(xs):\n  return min(xs)\n", "source_id": "62"}
{"text": "### Instruction\nWrite a function to find the maximum difference between available pairs in the given tuple list.\n\n### Response\ndef 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) ", "source_id": "63"}
{"text": "### Instruction\nWrite a function to sort a list of tuples using lambda.\n\n### Response\ndef subject_marks(subjectmarks):\r\n#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])\r\n subjectmarks.sort(key = lambda x: x[1])\r\n return subjectmarks", "source_id": "64"}
{"text": "### Instruction\nWrite a function of recursion list sum.\n\n### Response\ndef 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", "source_id": "65"}
{"text": "### Instruction\nWrite a python function to count positive numbers in a list.\n\n### Response\ndef pos_count(list):\r\n  pos_count= 0\r\n  for num in list: \r\n    if num >= 0: \r\n      pos_count += 1\r\n  return pos_count ", "source_id": "66"}
{"text": "### Instruction\nWrite a function to find the number of ways to partition a set of bell numbers.\n\n### Response\ndef bell_number(n):   \r\n    bell = [[0 for i in range(n+1)] for j in range(n+1)] \r\n    bell[0][0] = 1\r\n    for i in range(1, n+1): \r\n        bell[i][0] = bell[i-1][i-1]  \r\n        for j in range(1, i+1): \r\n            bell[i][j] = bell[i-1][j-1] + bell[i][j-1]   \r\n    return bell[n][0] ", "source_id": "67"}
{"text": "### Instruction\nWrite a python function to check whether the given array is monotonic or not.\n\n### Response\ndef is_Monotonic(A): \r\n    return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or\r\n            all(A[i] >= A[i + 1] for i in range(len(A) - 1))) ", "source_id": "68"}
{"text": "### Instruction\nWrite a function to check whether a list contains the given sublist or not.\n\n### Response\ndef 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", "source_id": "69"}
{"text": "### Instruction\nWrite a function to find whether all the given tuples have equal length or not.\n\n### Response\ndef 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\")", "source_id": "70"}
{"text": "### Instruction\nWrite a function to sort a list of elements using comb sort.\n\n### Response\ndef comb_sort(nums):\r\n    shrink_fact = 1.3\r\n    gaps = len(nums)\r\n    swapped = True\r\n    i = 0\r\n    while gaps > 1 or swapped:\r\n        gaps = int(float(gaps) / shrink_fact)\r\n        swapped = False\r\n        i = 0\r\n        while gaps + i < len(nums):\r\n            if nums[i] > nums[i+gaps]:\r\n                nums[i], nums[i+gaps] = nums[i+gaps], nums[i]\r\n                swapped = True\r\n            i += 1\r\n    return nums", "source_id": "71"}
{"text": "### Instruction\nWrite a python function to check whether the given number can be represented as difference of two squares or not.\n\n### Response\ndef dif_Square(n): \r\n    if (n % 4 != 2): \r\n        return True\r\n    return False", "source_id": "72"}
{"text": "### Instruction\nWrite a function to split the given string with multiple delimiters by using regex.\n\n### Response\nimport re\r\ndef multiple_split(text):\r\n  return (re.split('; |, |\\*|\\n',text))", "source_id": "73"}
{"text": "### Instruction\nWrite a function to check whether it follows the sequence given in the patterns array.\n\n### Response\ndef is_samepatterns(colors, patterns):    \r\n    if len(colors) != len(patterns):\r\n        return False    \r\n    sdict = {}\r\n    pset = set()\r\n    sset = set()    \r\n    for i in range(len(patterns)):\r\n        pset.add(patterns[i])\r\n        sset.add(colors[i])\r\n        if patterns[i] not in sdict.keys():\r\n            sdict[patterns[i]] = []\r\n\r\n        keys = sdict[patterns[i]]\r\n        keys.append(colors[i])\r\n        sdict[patterns[i]] = keys\r\n\r\n    if len(pset) != len(sset):\r\n        return False   \r\n\r\n    for values in sdict.values():\r\n\r\n        for i in range(len(values) - 1):\r\n            if values[i] != values[i+1]:\r\n                return False\r\n\r\n    return True", "source_id": "74"}
{"text": "### Instruction\nWrite a function to find tuples which have all elements divisible by k from the given list of tuples.\n\n### Response\ndef 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)) ", "source_id": "75"}
{"text": "### Instruction\nWrite a python function to count the number of squares in a rectangle.\n\n### Response\ndef 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))", "source_id": "76"}
{"text": "### Instruction\nWrite a python function to find the difference between sum of even and odd digits.\n\n### Response\ndef is_Diff(n): \r\n    return (n % 11 == 0) ", "source_id": "77"}
{"text": "### Instruction\nWrite a python function to find number of integers with odd number of set bits.\n\n### Response\ndef 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 ", "source_id": "78"}
{"text": "### Instruction\nWrite a python function to check whether the length of the word is odd or not.\n\n### Response\ndef word_len(s): \r\n    s = s.split(' ')   \r\n    for word in s:    \r\n        if len(word)%2!=0: \r\n            return True  \r\n        else:\r\n          return False", "source_id": "79"}
{"text": "### Instruction\nWrite a function to find the nth tetrahedral number.\n\n### Response\ndef tetrahedral_number(n): \r\n\treturn (n * (n + 1) * (n + 2)) / 6", "source_id": "80"}
{"text": "### Instruction\nWrite a function to zip the two given tuples.\n\n### Response\ndef 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) ", "source_id": "81"}
{"text": "### Instruction\nWrite a function to find the volume of a sphere.\n\n### Response\nimport math\r\ndef volume_sphere(r):\r\n  volume=(4/3)*math.pi*r*r*r\r\n  return volume", "source_id": "82"}
{"text": "### Instruction\nWrite a python function to find the character made by adding all the characters of the given string.\n\n### Response\ndef get_Char(strr):  \r\n    summ = 0\r\n    for i in range(len(strr)): \r\n        summ += (ord(strr[i]) - ord('a') + 1)  \r\n    if (summ % 26 == 0): \r\n        return ord('z') \r\n    else: \r\n        summ = summ % 26\r\n        return chr(ord('a') + summ - 1)", "source_id": "83"}
{"text": "### Instruction\nWrite a function to find the n-th number in newman conway sequence.\n\n### Response\ndef sequence(n): \r\n\tif n == 1 or n == 2: \r\n\t\treturn 1\r\n\telse: \r\n\t\treturn sequence(sequence(n-1)) + sequence(n-sequence(n-1))", "source_id": "84"}
{"text": "### Instruction\nWrite a function to find the surface area of a sphere.\n\n### Response\nimport math\r\ndef surfacearea_sphere(r):\r\n  surfacearea=4*math.pi*r*r\r\n  return surfacearea", "source_id": "85"}
{"text": "### Instruction\nWrite a function to find nth centered hexagonal number.\n\n### Response\ndef centered_hexagonal_number(n):\r\n  return 3 * n * (n - 1) + 1", "source_id": "86"}
{"text": "### Instruction\nWrite a function to merge three dictionaries into a single expression.\n\n### Response\nimport collections as ct\r\ndef merge_dictionaries_three(dict1,dict2, dict3):\r\n    merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))\r\n    return merged_dict", "source_id": "87"}
{"text": "### Instruction\nWrite a function to get the frequency of the elements in a list.\n\n### Response\nimport collections\r\ndef freq_count(list1):\r\n  freq_count= collections.Counter(list1)\r\n  return freq_count", "source_id": "88"}
{"text": "### Instruction\nWrite a function to find the closest smaller number than n.\n\n### Response\ndef closest_num(N):\r\n  return (N - 1)", "source_id": "89"}
{"text": "### Instruction\nWrite a python function to find the length of the longest word.\n\n### Response\ndef len_log(list1):\r\n    max=len(list1[0])\r\n    for i in list1:\r\n        if len(i)>max:\r\n            max=len(i)\r\n    return max", "source_id": "90"}
{"text": "### Instruction\nWrite a function to check if a substring is present in a given list of string values.\n\n### Response\ndef 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", "source_id": "91"}
{"text": "### Instruction\nWrite a function to check whether the given number is undulating or not.\n\n### Response\ndef is_undulating(n): \r\n\tif (len(n) <= 2): \r\n\t\treturn False\r\n\tfor i in range(2, len(n)): \r\n\t\tif (n[i - 2] != n[i]): \r\n\t\t\treturn False\r\n\treturn True", "source_id": "92"}
{"text": "### Instruction\nWrite a function to calculate the value of 'a' to the power 'b'.\n\n### Response\ndef power(a,b):\r\n\tif b==0:\r\n\t\treturn 1\r\n\telif a==0:\r\n\t\treturn 0\r\n\telif b==1:\r\n\t\treturn a\r\n\telse:\r\n\t\treturn a*power(a,b-1)", "source_id": "93"}
{"text": "### Instruction\nWrite a function to extract the index minimum value record from the given tuples.\n\n### Response\nfrom operator import itemgetter \r\ndef index_minimum(test_list):\r\n  res = min(test_list, key = itemgetter(1))[0]\r\n  return (res) ", "source_id": "94"}
{"text": "### Instruction\nWrite a python function to find the minimum length of sublist.\n\n### Response\ndef Find_Min_Length(lst):  \r\n    minLength = min(len(x) for x in lst )\r\n    return minLength ", "source_id": "95"}
{"text": "### Instruction\nWrite a python function to find the number of divisors of a given integer.\n\n### Response\ndef divisor(n):\r\n  for i in range(n):\r\n    x = len([i for i in range(1,n+1) if not n % i])\r\n  return x", "source_id": "96"}
{"text": "### Instruction\nWrite a function to find frequency count of list of lists.\n\n### Response\ndef frequency_lists(list1):\r\n    list1 = [item for sublist in list1 for item in sublist]\r\n    dic_data = {}\r\n    for num in list1:\r\n        if num in dic_data.keys():\r\n            dic_data[num] += 1\r\n        else:\r\n            key = num\r\n            value = 1\r\n            dic_data[key] = value\r\n    return dic_data\r\n", "source_id": "97"}
{"text": "### Instruction\nWrite a function to multiply all the numbers in a list and divide with the length of the list.\n\n### Response\ndef multiply_num(numbers):  \r\n    total = 1\r\n    for x in numbers:\r\n        total *= x  \r\n    return total/len(numbers) ", "source_id": "98"}
{"text": "### Instruction\nWrite a function to convert the given decimal number to its binary equivalent.\n\n### Response\ndef decimal_to_binary(n): \r\n    return bin(n).replace(\"0b\",\"\") ", "source_id": "99"}
{"text": "### Instruction\nWrite a function to find the next smallest palindrome of a specified number.\n\n### Response\nimport sys\r\ndef next_smallest_palindrome(num):\r\n    numstr = str(num)\r\n    for i in range(num+1,sys.maxsize):\r\n        if str(i) == str(i)[::-1]:\r\n            return i", "source_id": "100"}
{"text": "### Instruction\nWrite a function to find the kth element in the given array.\n\n### Response\ndef kth_element(arr, n, k):\r\n  for i in range(n):\r\n    for j in range(0, n-i-1):\r\n      if arr[j] > arr[j+1]:\r\n        arr[j], arr[j+1] == arr[j+1], arr[j]\r\n  return arr[k-1]", "source_id": "101"}
{"text": "### Instruction\nWrite a function to convert snake case string to camel case string.\n\n### Response\ndef snake_to_camel(word):\r\n        import re\r\n        return ''.join(x.capitalize() or '_' for x in word.split('_'))", "source_id": "102"}
{"text": "### Instruction\nWrite a function to find eulerian number a(n, m).\n\n### Response\ndef 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))", "source_id": "103"}
{"text": "### Instruction\nWrite a function to sort each sublist of strings in a given list of lists using lambda function.\n\n### Response\ndef sort_sublists(input_list):\r\n    result = [sorted(x, key = lambda x:x[0]) for x in input_list] \r\n    return result\r", "source_id": "104"}
{"text": "### Instruction\nWrite a python function to count true booleans in the given list.\n\n### Response\ndef count(lst):   \r\n    return sum(lst) ", "source_id": "105"}
{"text": "### Instruction\nWrite a function to add the given list to the given tuples.\n\n### Response\ndef add_lists(test_list, test_tup):\r\n  res = tuple(list(test_tup) + test_list)\r\n  return (res) ", "source_id": "106"}
{"text": "### Instruction\nWrite a python function to count hexadecimal numbers for a given range.\n\n### Response\ndef count_Hexadecimal(L,R) :  \r\n    count = 0;  \r\n    for i in range(L,R + 1) : \r\n        if (i >= 10 and i <= 15) : \r\n            count += 1;  \r\n        elif (i > 15) : \r\n            k = i;  \r\n            while (k != 0) :  \r\n                if (k % 16 >= 10) : \r\n                    count += 1;  \r\n                k = k // 16;  \r\n    return count;  ", "source_id": "107"}
{"text": "### Instruction\nWrite a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.\n\n### Response\nimport heapq\r\ndef merge_sorted_list(num1,num2,num3):\r\n  num1=sorted(num1)\r\n  num2=sorted(num2)\r\n  num3=sorted(num3)\r\n  result = heapq.merge(num1,num2,num3)\r\n  return list(result)", "source_id": "108"}
{"text": "### Instruction\nWrite a python function to find the count of rotations of a binary string with odd value.\n\n### Response\ndef odd_Equivalent(s,n): \r\n    count=0\r\n    for i in range(0,n): \r\n        if (s[i] == '1'): \r\n            count = count + 1\r\n    return count ", "source_id": "109"}
{"text": "### Instruction\nWrite a function to extract the ranges that are missing from the given list with the given start range and end range values.\n\n### Response\ndef 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) ", "source_id": "110"}
{"text": "### Instruction\nWrite a function to find common elements in given nested lists. * list item * list item * list item * list item\n\n### Response\ndef common_in_nested_lists(nestedlist):\r\n    result = list(set.intersection(*map(set, nestedlist)))\r\n    return result", "source_id": "111"}
{"text": "### Instruction\nWrite a python function to find the perimeter of a cylinder.\n\n### Response\ndef perimeter(diameter,height) : \r\n    return 2*(diameter+height)  ", "source_id": "112"}
{"text": "### Instruction\nWrite a function to check if a string represents an integer or not.\n\n### Response\ndef 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", "source_id": "113"}
{"text": "### Instruction\nWrite a function to assign frequency to each tuple in the given tuple list.\n\n### Response\nfrom collections import Counter \r\ndef assign_freq(test_list):\r\n  res = [(*key, val) for key, val in Counter(test_list).items()]\r\n  return (str(res)) ", "source_id": "114"}
{"text": "### Instruction\nWrite a function to check whether all dictionaries in a list are empty or not.\n\n### Response\ndef empty_dit(list1):\r\n empty_dit=all(not d for d in list1)\r\n return empty_dit", "source_id": "115"}
{"text": "### Instruction\nWrite a function to convert a given tuple of positive integers into an integer.\n\n### Response\ndef tuple_to_int(nums):\r\n    result = int(''.join(map(str,nums)))\r\n    return result", "source_id": "116"}
{"text": "### Instruction\nWrite a function to convert all possible convertible elements in the list to float.\n\n### Response\ndef list_to_float(test_list):\r\n  res = []\r\n  for tup in test_list:\r\n    temp = []\r\n    for ele in tup:\r\n      if ele.isalpha():\r\n        temp.append(ele)\r\n      else:\r\n        temp.append(float(ele))\r\n    res.append((temp[0],temp[1])) \r\n  return (str(res)) ", "source_id": "117"}
{"text": "### Instruction\n[link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list.\n\n### Response\ndef string_to_list(string): \r\n    lst = list(string.split(\" \")) \r\n    return lst", "source_id": "118"}
{"text": "### Instruction\nWrite a python function to find the element that appears only once in a sorted array.\n\n### Response\ndef search(arr,n) :\r\n    XOR = 0\r\n    for i in range(n) :\r\n        XOR = XOR ^ arr[i]\r\n    return (XOR)", "source_id": "119"}
{"text": "### Instruction\nWrite a function to find the maximum product from the pairs of tuples within a given list.\n\n### Response\ndef max_product_tuple(list1):\r\n    result_max = max([abs(x * y) for x, y in list1] )\r\n    return result_max", "source_id": "120"}
{"text": "### Instruction\nWrite a function to find the triplet with sum of the given array\n\n### Response\ndef check_triplet(A, n, sum, count):\r\n    if count == 3 and sum == 0:\r\n        return True\r\n    if count == 3 or n == 0 or sum < 0:\r\n        return False\r\n    return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\\\r\n           check_triplet(A, n - 1, sum, count)", "source_id": "121"}
{"text": "### Instruction\nWrite a function to find n’th smart number.\n\n### Response\nMAX = 3000 \r\ndef smartNumber(n): \r\n\tprimes = [0] * MAX \r\n\tresult = [] \r\n\tfor i in range(2, MAX): \r\n\t\tif (primes[i] == 0): \r\n\t\t\tprimes[i] = 1 \r\n\t\t\tj = i * 2 \r\n\t\t\twhile (j < MAX): \r\n\t\t\t\tprimes[j] -= 1 \r\n\t\t\t\tif ( (primes[j] + 3) == 0): \r\n\t\t\t\t\tresult.append(j) \r\n\t\t\t\tj = j + i \r\n\tresult.sort() \r\n\treturn result[n - 1] ", "source_id": "122"}
{"text": "### Instruction\nWrite a function to sum all amicable numbers from 1 to a specified number.\n\n### Response\ndef 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)", "source_id": "123"}
{"text": "### Instruction\nWrite a function to get the angle of a complex number.\n\n### Response\nimport cmath\r\ndef angle_complex(a,b):\r\n  cn=complex(a,b)\r\n  angle=cmath.phase(a+b)\r\n  return angle", "source_id": "124"}
{"text": "### Instruction\nWrite a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.\n\n### Response\ndef find_length(string, n): \r\n\tcurrent_sum = 0\r\n\tmax_sum = 0\r\n\tfor i in range(n): \r\n\t\tcurrent_sum += (1 if string[i] == '0' else -1) \r\n\t\tif current_sum < 0: \r\n\t\t\tcurrent_sum = 0\r\n\t\tmax_sum = max(current_sum, max_sum) \r\n\treturn max_sum if max_sum else 0", "source_id": "125"}
{"text": "### Instruction\nWrite a python function to find the sum of common divisors of two given numbers.\n\n### Response\ndef 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", "source_id": "126"}
{"text": "### Instruction\nWrite a function to multiply two integers without using the * operator in python.\n\n### Response\ndef multiply_int(x, y):\r\n    if y < 0:\r\n        return -multiply_int(x, -y)\r\n    elif y == 0:\r\n        return 0\r\n    elif y == 1:\r\n        return x\r\n    else:\r\n        return x + multiply_int(x, y - 1)", "source_id": "127"}
{"text": "### Instruction\nWrite a function to shortlist words that are longer than n from a given list of words.\n\n### Response\ndef 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", "source_id": "128"}
{"text": "### Instruction\nWrite a function to calculate magic square.\n\n### Response\ndef magic_square_test(my_matrix):\r\n    iSize = len(my_matrix[0])\r\n    sum_list = []\r\n    sum_list.extend([sum (lines) for lines in my_matrix])   \r\n    for col in range(iSize):\r\n        sum_list.append(sum(row[col] for row in my_matrix))\r\n    result1 = 0\r\n    for i in range(0,iSize):\r\n        result1 +=my_matrix[i][i]\r\n    sum_list.append(result1)      \r\n    result2 = 0\r\n    for i in range(iSize-1,-1,-1):\r\n        result2 +=my_matrix[i][i]\r\n    sum_list.append(result2)\r\n    if len(set(sum_list))>1:\r\n        return False\r\n    return True", "source_id": "129"}
{"text": "### Instruction\nWrite a function to find the item with maximum frequency in a given list.\n\n### Response\nfrom 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", "source_id": "130"}
{"text": "### Instruction\nWrite a python function to reverse only the vowels of a given string.\n\n### Response\ndef reverse_vowels(str1):\r\n\tvowels = \"\"\r\n\tfor char in str1:\r\n\t\tif char in \"aeiouAEIOU\":\r\n\t\t\tvowels += char\r\n\tresult_string = \"\"\r\n\tfor char in str1:\r\n\t\tif char in \"aeiouAEIOU\":\r\n\t\t\tresult_string += vowels[-1]\r\n\t\t\tvowels = vowels[:-1]\r\n\t\telse:\r\n\t\t\tresult_string += char\r\n\treturn result_string", "source_id": "131"}
{"text": "### Instruction\nWrite a function to convert tuple to a string.\n\n### Response\ndef tup_string(tup1):\r\n  str =  ''.join(tup1)\r\n  return str", "source_id": "132"}
{"text": "### Instruction\nWrite a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.\n\n### Response\ndef sum_negativenum(nums):\r\n  sum_negativenum = list(filter(lambda nums:nums<0,nums))\r\n  return sum(sum_negativenum)", "source_id": "133"}
{"text": "### Instruction\nWrite a python function to check whether the last element of given array is even or odd after performing an operation p times.\n\n### Response\ndef 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      ", "source_id": "134"}
{"text": "### Instruction\nWrite a function to find the nth hexagonal number.\n\n### Response\ndef hexagonal_num(n): \r\n\treturn n*(2*n - 1) ", "source_id": "135"}
{"text": "### Instruction\nWrite a function to calculate electricity bill.\n\n### Response\ndef cal_electbill(units):\r\n if(units < 50):\r\n    amount = units * 2.60\r\n    surcharge = 25\r\n elif(units <= 100):\r\n    amount = 130 + ((units - 50) * 3.25)\r\n    surcharge = 35\r\n elif(units <= 200):\r\n    amount = 130 + 162.50 + ((units - 100) * 5.26)\r\n    surcharge = 45\r\n else:\r\n    amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)\r\n    surcharge = 75\r\n total = amount + surcharge\r\n return total", "source_id": "136"}
{"text": "### Instruction\nWrite a function to find the ration of zeroes in an array of integers.\n\n### Response\nfrom array import array\r\ndef zero_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)", "source_id": "137"}
{"text": "### Instruction\nWrite a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.\n\n### Response\ndef is_Sum_Of_Powers_Of_Two(n): \r\n    if (n % 2 == 1): \r\n        return False\r\n    else: \r\n        return True", "source_id": "138"}
{"text": "### Instruction\nWrite a function to find the circumference of a circle.\n\n### Response\ndef circle_circumference(r):\r\n  perimeter=2*3.1415*r\r\n  return perimeter", "source_id": "139"}
{"text": "### Instruction\nWrite a function to extract elements that occur singly in the given tuple list.\n\n### Response\ndef extract_singly(test_list):\r\n  res = []\r\n  temp = set()\r\n  for inner in test_list:\r\n    for ele in inner:\r\n      if not ele in temp:\r\n        temp.add(ele)\r\n        res.append(ele)\r\n  return (res) ", "source_id": "140"}
{"text": "### Instruction\nWrite a function to sort a list of elements using pancake sort.\n\n### Response\ndef 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", "source_id": "141"}
{"text": "### Instruction\nWrite a function to count the same pair in three given lists.\n\n### Response\ndef count_samepair(list1,list2,list3):\r\n    result = sum(m == n == o for m, n, o in zip(list1,list2,list3))\r\n    return result", "source_id": "142"}
{"text": "### Instruction\nWrite a function to find number of lists present in the given tuple.\n\n### Response\ndef find_lists(Input): \r\n\tif isinstance(Input, list): \r\n\t\treturn 1\r\n\telse: \r\n\t\treturn len(Input) ", "source_id": "143"}
{"text": "### Instruction\nWrite a python function to find the sum of absolute differences in all pairs of the given array.\n\n### Response\ndef 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", "source_id": "144"}
{"text": "### Instruction\nWrite a python function to find the maximum difference between any two elements in a given array.\n\n### Response\ndef max_Abs_Diff(arr,n): \r\n    minEle = arr[0] \r\n    maxEle = arr[0] \r\n    for i in range(1, n): \r\n        minEle = min(minEle,arr[i]) \r\n        maxEle = max(maxEle,arr[i]) \r\n    return (maxEle - minEle) ", "source_id": "145"}
{"text": "### Instruction\nWrite a function to find the ascii value of total characters in a string.\n\n### Response\ndef ascii_value_string(str1):\r\n  for i in range(len(str1)):\r\n   return ord(str1[i])", "source_id": "146"}
{"text": "### Instruction\nWrite a function to find the maximum total path sum in the given triangle.\n\n### Response\ndef 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]", "source_id": "147"}
{"text": "### Instruction\nWrite a function to divide a number into two parts such that the sum of digits is maximum.\n\n### Response\ndef sum_digits_single(x) : \r\n    ans = 0\r\n    while x : \r\n        ans += x % 10\r\n        x //= 10  \r\n    return ans \r\ndef closest(x) : \r\n    ans = 0\r\n    while (ans * 10 + 9 <= x) : \r\n        ans = ans * 10 + 9  \r\n    return ans   \r\ndef sum_digits_twoparts(N) : \r\n    A = closest(N)  \r\n    return sum_digits_single(A) + sum_digits_single(N - A) ", "source_id": "148"}
{"text": "### Instruction\nWrite a function to find the longest subsequence such that the difference between adjacents is one for the given array.\n\n### Response\ndef longest_subseq_with_diff_one(arr, n): \r\n\tdp = [1 for i in range(n)] \r\n\tfor i in range(n): \r\n\t\tfor j in range(i): \r\n\t\t\tif ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): \r\n\t\t\t\tdp[i] = max(dp[i], dp[j]+1) \r\n\tresult = 1\r\n\tfor i in range(n): \r\n\t\tif (result < dp[i]): \r\n\t\t\tresult = dp[i] \r\n\treturn result", "source_id": "149"}
{"text": "### Instruction\nWrite a python function to find whether the given number is present in the infinite sequence or not.\n\n### Response\ndef 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", "source_id": "150"}
{"text": "### Instruction\nWrite a python function to check whether the given number is co-prime or not.\n\n### Response\ndef gcd(p,q):\r\n    while q != 0:\r\n        p, q = q,p%q\r\n    return p\r\ndef is_coprime(x,y):\r\n    return gcd(x,y) == 1", "source_id": "151"}
{"text": "### Instruction\nWrite a function to sort the given array by using merge sort.\n\n### Response\ndef merge(a,b):\r\n    c = []\r\n    while len(a) != 0 and len(b) != 0:\r\n        if a[0] < b[0]:\r\n            c.append(a[0])\r\n            a.remove(a[0])\r\n        else:\r\n            c.append(b[0])\r\n            b.remove(b[0])\r\n    if len(a) == 0:\r\n        c += b\r\n    else:\r\n        c += a\r\n    return c\r\ndef merge_sort(x):\r\n    if len(x) == 0 or len(x) == 1:\r\n        return x\r\n    else:\r\n        middle = len(x)//2\r\n        a = merge_sort(x[:middle])\r\n        b = merge_sort(x[middle:])\r\n        return merge(a,b)\r\n", "source_id": "152"}
{"text": "### Instruction\nWrite a function to find the vertex of a parabola.\n\n### Response\ndef parabola_vertex(a, b, c): \r\n  vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))\r\n  return vertex", "source_id": "153"}
{"text": "### Instruction\nWrite a function to extract every specified element from a given two dimensional list.\n\n### Response\ndef specified_element(nums, N):\r\n    result = [i[N] for i in nums]\r\n    return result", "source_id": "154"}
{"text": "### Instruction\nWrite a python function to toggle all even bits of a given number.\n\n### Response\ndef 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 ", "source_id": "155"}
{"text": "### Instruction\nWrite a function to convert a tuple of string values to a tuple of integer values.\n\n### Response\ndef tuple_int_str(tuple_str):\r\n    result = tuple((int(x[0]), int(x[1])) for x in tuple_str)\r\n    return result", "source_id": "156"}
{"text": "### Instruction\nWrite a function to reflect the run-length encoding from a list.\n\n### Response\nfrom itertools import groupby\r\ndef encode_list(list1):\r\n    return [[len(list(group)), key] for key, group in groupby(list1)]", "source_id": "157"}
{"text": "### Instruction\nWrite a python function to find k number of operations required to make all elements equal.\n\n### Response\ndef 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) ", "source_id": "158"}
{"text": "### Instruction\nWrite a function to print the season for the given month and day.\n\n### Response\ndef month_season(month,days):\r\n if month in ('January', 'February', 'March'):\r\n\t season = 'winter'\r\n elif month in ('April', 'May', 'June'):\r\n\t season = 'spring'\r\n elif month in ('July', 'August', 'September'):\r\n\t season = 'summer'\r\n else:\r\n\t season = 'autumn'\r\n if (month == 'March') and (days > 19):\r\n\t season = 'spring'\r\n elif (month == 'June') and (days > 20):\r\n\t season = 'summer'\r\n elif (month == 'September') and (days > 21):\r\n\t season = 'autumn'\r\n elif (month == 'October') and (days > 21):\r\n\t season = 'autumn'\r\n elif (month == 'November') and (days > 21):\r\n\t season = 'autumn'\r\n elif (month == 'December') and (days > 20):\r\n\t season = 'winter'\r\n return season", "source_id": "159"}
{"text": "### Instruction\nWrite a function to find x and y that satisfies ax + by = n.\n\n### Response\ndef 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\") ", "source_id": "160"}
{"text": "### Instruction\nWrite a function to remove all elements from a given list present in another list.\n\n### Response\ndef remove_elements(list1, list2):\r\n    result = [x for x in list1 if x not in list2]\r\n    return result", "source_id": "161"}
{"text": "### Instruction\nWrite a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).\n\n### Response\ndef sum_series(n):\r\n  if n < 1:\r\n    return 0\r\n  else:\r\n    return n + sum_series(n - 2)", "source_id": "162"}
{"text": "### Instruction\nWrite a function to calculate the area of a regular polygon.\n\n### Response\nfrom math import tan, pi\r\ndef area_polygon(s,l):\r\n  area = s * (l ** 2) / (4 * tan(pi / s))\r\n  return area", "source_id": "163"}
{"text": "### Instruction\nWrite a python function to check whether the sum of divisors are same or not.\n\n### Response\nimport math \r\ndef divSum(n): \r\n    sum = 1; \r\n    i = 2; \r\n    while(i * i <= n): \r\n        if (n % i == 0): \r\n            sum = (sum + i +math.floor(n / i)); \r\n        i += 1; \r\n    return sum; \r\ndef areEquivalent(num1,num2): \r\n    return divSum(num1) == divSum(num2); ", "source_id": "164"}
{"text": "### Instruction\nWrite a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.\n\n### Response\ndef 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 ", "source_id": "165"}
{"text": "### Instruction\nWrite a python function to count the pairs with xor as an even number.\n\n### Response\ndef find_even_Pair(A,N): \r\n    evenPair = 0\r\n    for i in range(0,N): \r\n        for j in range(i+1,N): \r\n            if ((A[i] ^ A[j]) % 2 == 0): \r\n                evenPair+=1\r\n    return evenPair; ", "source_id": "166"}
{"text": "### Instruction\nWrite a python function to find smallest power of 2 greater than or equal to n.\n\n### Response\ndef next_Power_Of_2(n): \r\n    count = 0; \r\n    if (n and not(n & (n - 1))): \r\n        return n   \r\n    while( n != 0): \r\n        n >>= 1\r\n        count += 1\r\n    return 1 << count; ", "source_id": "167"}
{"text": "### Instruction\nWrite a python function to find the frequency of a number in a given array.\n\n### Response\ndef frequency(a,x): \r\n    count = 0  \r\n    for i in a: \r\n        if i == x: count += 1\r\n    return count ", "source_id": "168"}
{"text": "### Instruction\nWrite a function to calculate the nth pell number.\n\n### Response\ndef get_pell(n): \r\n\tif (n <= 2): \r\n\t\treturn n \r\n\ta = 1\r\n\tb = 2\r\n\tfor i in range(3, n+1): \r\n\t\tc = 2 * b + a \r\n\t\ta = b \r\n\t\tb = c \r\n\treturn b ", "source_id": "169"}
{"text": "### Instruction\nWrite a function to find sum of the numbers in a list between the indices of a specified range.\n\n### Response\ndef 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   ", "source_id": "170"}
{"text": "### Instruction\nWrite a function to find the perimeter of a pentagon.\n\n### Response\nimport math\r\ndef perimeter_pentagon(a):\r\n  perimeter=(5*a)\r\n  return perimeter", "source_id": "171"}
{"text": "### Instruction\nWrite a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item\n\n### Response\ndef count_occurance(s):\r\n  count=0\r\n  for i in range(len(s)):\r\n    if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):\r\n      count = count + 1\r\n  return count", "source_id": "172"}
{"text": "### Instruction\nWrite a function to remove everything except alphanumeric characters from a string.\n\n### Response\nimport re\r\ndef remove_splchar(text): \r\n pattern = re.compile('[\\W_]+')\r\n return (pattern.sub('', text))", "source_id": "173"}
{"text": "### Instruction\nWrite a function to group a sequence of key-value pairs into a dictionary of lists.\n\n### Response\ndef group_keyvalue(l):\r\n    result = {}\r\n    for k, v in l:\r\n         result.setdefault(k, []).append(v)\r\n    return result", "source_id": "174"}
{"text": "### Instruction\nWrite a function to verify validity of a string of parentheses.\n\n### Response\ndef is_valid_parenthese( str1):\r\n        stack, pchar = [], {\"(\": \")\", \"{\": \"}\", \"[\": \"]\"}\r\n        for parenthese in str1:\r\n            if parenthese in pchar:\r\n                stack.append(parenthese)\r\n            elif len(stack) == 0 or pchar[stack.pop()] != parenthese:\r\n                return False\r\n        return len(stack) == 0", "source_id": "175"}
{"text": "### Instruction\nWrite a function to find the perimeter of a triangle.\n\n### Response\ndef perimeter_triangle(a,b,c):\r\n  perimeter=a+b+c\r\n  return perimeter", "source_id": "176"}
{"text": "### Instruction\nWrite a python function to find two distinct numbers such that their lcm lies within the given range.\n\n### Response\ndef answer(L,R): \r\n    if (2 * L <= R): \r\n        return (L ,2*L)\r\n    else: \r\n        return (-1) ", "source_id": "177"}
{"text": "### Instruction\nWrite a function to search some literals strings in a string.\n\n### Response\nimport 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!')", "source_id": "178"}
{"text": "### Instruction\nWrite a function to find if the given number is a keith number or not.\n\n### Response\ndef is_num_keith(x): \r\n\tterms = [] \r\n\ttemp = x \r\n\tn = 0 \r\n\twhile (temp > 0): \r\n\t\tterms.append(temp % 10) \r\n\t\ttemp = int(temp / 10) \r\n\t\tn+=1 \r\n\tterms.reverse() \r\n\tnext_term = 0 \r\n\ti = n \r\n\twhile (next_term < x): \r\n\t\tnext_term = 0 \r\n\t\tfor j in range(1,n+1): \r\n\t\t\tnext_term += terms[i - j] \r\n\t\tterms.append(next_term) \r\n\t\ti+=1 \r\n\treturn (next_term == x) ", "source_id": "179"}
{"text": "### Instruction\nWrite a function to calculate distance between two points using latitude and longitude.\n\n### Response\nfrom math import radians, sin, cos, acos\r\ndef distance_lat_long(slat,slon,elat,elon):\r\n dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))\r\n return dist", "source_id": "180"}
{"text": "### Instruction\nWrite a function to find the longest common prefix in the given set of strings.\n\n### Response\ndef 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) ", "source_id": "181"}
{"text": "### Instruction\nWrite a function to find uppercase, lowercase, special character and numeric values using regex.\n\n### Response\nimport re\r\ndef find_character(string):\r\n  uppercase_characters = re.findall(r\"[A-Z]\", string) \r\n  lowercase_characters = re.findall(r\"[a-z]\", string) \r\n  numerical_characters = re.findall(r\"[0-9]\", string) \r\n  special_characters = re.findall(r\"[, .!?]\", string) \r\n  return uppercase_characters, lowercase_characters, numerical_characters, special_characters", "source_id": "182"}
{"text": "### Instruction\nWrite a function to count all the distinct pairs having a difference of k in any array.\n\n### Response\ndef count_pairs(arr, n, k):\r\n  count=0;\r\n  for i in range(0,n):\r\n    for j in range(i+1, n):\r\n      if arr[i] - arr[j] == k or arr[j] - arr[i] == k:\r\n        count += 1\r\n  return count", "source_id": "183"}
{"text": "### Instruction\nWrite a function to find all the values in a list that are greater than a specified number.\n\n### Response\ndef greater_specificnum(list,num):\r\n greater_specificnum=all(x >= num for x in list)\r\n return greater_specificnum", "source_id": "184"}
{"text": "### Instruction\nWrite a function to find the focus of a parabola.\n\n### Response\ndef parabola_focus(a, b, c): \r\n  focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))\r\n  return focus", "source_id": "185"}
{"text": "### Instruction\nWrite a function to search some literals strings in a string by using regex.\n\n### Response\nimport re\r\ndef check_literals(text, patterns):\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!')", "source_id": "186"}
{"text": "### Instruction\nWrite a function to find the longest common subsequence for the given two sequences.\n\n### Response\ndef longest_common_subsequence(X, Y, m, n): \r\n    if m == 0 or n == 0: \r\n       return 0 \r\n    elif X[m-1] == Y[n-1]: \r\n       return 1 + longest_common_subsequence(X, Y, m-1, n-1) \r\n    else: \r\n       return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))", "source_id": "187"}
{"text": "### Instruction\nWrite a python function to check whether the given number can be represented by product of two squares or not.\n\n### Response\ndef prod_Square(n):\r\n    for i in range(2,(n) + 1):\r\n        if (i*i < (n+1)):\r\n            for j in range(2,n + 1):\r\n                if ((i*i*j*j) == n):\r\n                    return True;\r\n    return False;", "source_id": "188"}
{"text": "### Instruction\nWrite a python function to find the first missing positive number.\n\n### Response\ndef first_Missing_Positive(arr,n): \r\n    ptr = 0\r\n    for i in range(n):\r\n        if arr[i] == 1:\r\n            ptr = 1\r\n            break\r\n    if ptr == 0:\r\n        return(1)\r\n    for i in range(n):\r\n        if arr[i] <= 0 or arr[i] > n:\r\n            arr[i] = 1\r\n    for i in range(n):\r\n        arr[(arr[i] - 1) % n] += n\r\n    for i in range(n):\r\n        if arr[i] <= n:\r\n            return(i + 1)\r\n    return(n + 1)", "source_id": "189"}
{"text": "### Instruction\nWrite a python function to count the number of integral co-ordinates that lie inside a square.\n\n### Response\ndef count_Intgral_Points(x1,y1,x2,y2): \r\n    return ((y2 - y1 - 1) * (x2 - x1 - 1)) ", "source_id": "190"}
{"text": "### Instruction\nWrite a function to check whether the given month name contains 30 days or not.\n\n### Response\ndef check_monthnumber(monthname3):\r\n  if monthname3 ==\"April\" or monthname3== \"June\" or monthname3== \"September\" or monthname3== \"November\":\r\n    return True\r\n  else:\r\n    return False", "source_id": "191"}
{"text": "### Instruction\nWrite a python function to check whether a string has atleast one letter and one number.\n\n### Response\ndef check_String(str): \r\n    flag_l = False\r\n    flag_n = False\r\n    for i in str: \r\n        if i.isalpha(): \r\n            flag_l = True  \r\n        if i.isdigit(): \r\n            flag_n = True\r\n    return flag_l and flag_n ", "source_id": "192"}
{"text": "### Instruction\nWrite a function to remove the duplicates from the given tuple.\n\n### Response\ndef remove_tuple(test_tup):\r\n  res = tuple(set(test_tup))\r\n  return (res) ", "source_id": "193"}
{"text": "### Instruction\nWrite a python function to convert octal number to decimal number.\n\n### Response\ndef octal_To_Decimal(n):  \r\n    num = n; \r\n    dec_value = 0; \r\n    base = 1; \r\n    temp = num; \r\n    while (temp): \r\n        last_digit = temp % 10; \r\n        temp = int(temp / 10); \r\n        dec_value += last_digit*base; \r\n        base = base * 8; \r\n    return dec_value; ", "source_id": "194"}
{"text": "### Instruction\nWrite a python function to find the first position of an element in a sorted array.\n\n### Response\ndef 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", "source_id": "195"}
{"text": "### Instruction\nWrite a function to remove all the tuples with length k.\n\n### Response\ndef remove_tuples(test_list, K):\r\n  res = [ele for ele in test_list if len(ele) != K]\r\n  return (res) ", "source_id": "196"}
{"text": "### Instruction\nWrite a function to perform the exponentiation of the given two tuples.\n\n### Response\ndef find_exponentio(test_tup1, test_tup2):\r\n  res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2))\r\n  return (res)\r\n", "source_id": "197"}
{"text": "### Instruction\nWrite a function to find the largest triangle that can be inscribed in an ellipse.\n\n### Response\nimport math\r\ndef largest_triangle(a,b): \r\n    if (a < 0 or b < 0): \r\n        return -1 \r\n    area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b);  \r\n    return area ", "source_id": "198"}
{"text": "### Instruction\nWrite a python function to find highest power of 2 less than or equal to given number.\n\n### Response\ndef highest_Power_of_2(n): \r\n    res = 0; \r\n    for i in range(n, 0, -1):  \r\n        if ((i & (i - 1)) == 0): \r\n            res = i; \r\n            break;      \r\n    return res; ", "source_id": "199"}
{"text": "### Instruction\nWrite a function to find all index positions of the maximum values in a given list.\n\n### Response\ndef position_max(list1):\r\n    max_val = max(list1)\r\n    max_result = [i for i, j in enumerate(list1) if j == max_val]\r\n    return max_result", "source_id": "200"}
{"text": "### Instruction\nWrite a python function to check whether the elements in a list are same or not.\n\n### Response\ndef chkList(lst): \r\n    return len(set(lst)) == 1", "source_id": "201"}
{"text": "### Instruction\nWrite a function to remove even characters in a string.\n\n### Response\ndef 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", "source_id": "202"}
{"text": "### Instruction\nWrite a python function to find the hamming distance between given two integers.\n\n### Response\ndef 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  ", "source_id": "203"}
{"text": "### Instruction\nWrite a python function to count the occurrence of a given character in a string.\n\n### Response\ndef count(s,c) : \r\n    res = 0 \r\n    for i in range(len(s)) : \r\n        if (s[i] == c): \r\n            res = res + 1\r\n    return res ", "source_id": "204"}
{"text": "### Instruction\nWrite a function to find the inversions of tuple elements in the given tuple list.\n\n### Response\ndef inversion_elements(test_tup):\r\n  res = tuple(list(map(lambda x: ~x, list(test_tup))))\r\n  return (res) ", "source_id": "205"}
{"text": "### Instruction\nWrite a function to perform the adjacent element concatenation in the given tuples.\n\n### Response\ndef concatenate_elements(test_tup):\r\n  res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))\r\n  return (res) ", "source_id": "206"}
{"text": "### Instruction\nWrite a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions.\n\n### Response\ndef find_longest_repeating_subseq(str): \r\n\tn = len(str) \r\n\tdp = [[0 for k in range(n+1)] for l in range(n+1)] \r\n\tfor i in range(1, n+1): \r\n\t\tfor j in range(1, n+1): \r\n\t\t\tif (str[i-1] == str[j-1] and i != j): \r\n\t\t\t\tdp[i][j] = 1 + dp[i-1][j-1] \r\n\t\t\telse: \r\n\t\t\t\tdp[i][j] = max(dp[i][j-1], dp[i-1][j]) \r\n\treturn dp[n][n]", "source_id": "207"}
{"text": "### Instruction\nWrite a function to check the given decimal with a precision of 2 by using regex.\n\n### Response\nimport re\r\ndef is_decimal(num):\r\n  num_fetch = re.compile(r\"\"\"^[0-9]+(\\.[0-9]{1,2})?$\"\"\")\r\n  result = num_fetch.search(num)\r\n  return bool(result)", "source_id": "208"}
{"text": "### Instruction\nWrite a function to delete the smallest element from the given heap and then insert a new item.\n\n### Response\nimport heapq as hq\r\ndef heap_replace(heap,a):\r\n  hq.heapify(heap)\r\n  hq.heapreplace(heap, a)\r\n  return heap", "source_id": "209"}
{"text": "### Instruction\nWrite a function to check that the given string contains only a certain set of characters(in this case a-z, a-z and 0-9) by using regex.\n\n### Response\nimport re\r\ndef is_allowed_specific_char(string):\r\n    get_char = re.compile(r'[^a-zA-Z0-9.]')\r\n    string = get_char.search(string)\r\n    return not bool(string)", "source_id": "210"}