task_id int32 11 510 | text stringlengths 37 191 | code stringlengths 37 1.33k | test_list listlengths 3 3 | test_setup_code stringclasses 2
values | challenge_test_list listlengths 0 3 | generated_code listlengths 1 1 | gt_rewards listlengths 1 1 |
|---|---|---|---|---|---|---|---|
311 | Write a python function to set the left most unset bit. | def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos))) | [
"assert set_left_most_unset_bit(10) == 14",
"assert set_left_most_unset_bit(12) == 14",
"assert set_left_most_unset_bit(15) == 15"
] | [] | [
"Here is a Python function that sets the left most unset bit of a given number:\n\n```python\ndef set_left_most_unset_bit(n):\n \"\"\"\n Write a python function to set the left most unset bit.\n \"\"\"\n # Find the position of the leftmost unset bit\n position = 0\n while n & 1 == 1:\n posi... | [
0
] | |
312 | Write a function to find the volume of a cone. | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | [
"assert volume_cone(5,12)==314.15926535897927",
"assert volume_cone(10,15)==1570.7963267948965",
"assert volume_cone(19,17)==6426.651371693521"
] | [] | [
"Sure, here is the Python function to find the volume of a cone:\n\n```python\ndef volume_cone(r, h):\n \"\"\"\n Write a function to find the volume of a cone.\n \"\"\"\n return (1/3) * 3.14159 * r**2 * h\n```\n\nThis function takes two arguments, `r` and `h`, which represent the radius and height of th... | [
0
] | |
313 | Write a python function to print positive numbers in a list. | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | [
"assert pos_nos([-1,-2,1,2]) == 1,2",
"assert pos_nos([3,4,-5]) == 3,4",
"assert pos_nos([-2,-3,1]) == 1"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef pos_nos(list1):\n \"\"\"\n Write a python function to print positive numbers in a list.\n \"\"\"\n for num in list1:\n if num > 0:\n print(num)\n```\n\nThis function takes a list as input and iterates over each number in the list.... | [
0
] | |
314 | Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n. | def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | [
"assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7",
"assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24",
"assert max_sum_rectangular_grid([ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5) == 81"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef max_sum_rectangular_grid(grid, n):\n if n == 0:\n return 0\n if n == 1:\n return max(grid[0])\n \n # Initialize the maximum sum to the first element of the grid\n max_sum = grid[0]\n \n # Iterate over the grid\n for ... | [
0
] | |
315 | Write a python function to find the first maximum length of even word. | def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while (i < n):
if (str[i] == ' '):
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
... | [
"assert find_Max_Len_Even(\"python language\") == \"language\"",
"assert find_Max_Len_Even(\"maximum even length\") == \"length\"",
"assert find_Max_Len_Even(\"eve\") == \"-1\""
] | [] | [
"Here is the Python function to find the first maximum length of even word:\n\n```python\ndef find_Max_Len_Even(str):\n # Split the string into words\n words = str.split()\n \n # Initialize the maximum length of even word to 0\n max_len = 0\n \n # Iterate over each word in the list\n for wor... | [
0
] | |
316 | Write a function to find the index of the last occurrence of a given number in a sorted array. | def find_last_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
left = mid + 1
elif x < A[mid]:
right = mid - 1
else:
left = mid ... | [
"assert find_last_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 3",
"assert find_last_occurrence([2, 3, 5, 8, 6, 6, 8, 9, 9, 9], 9) == 9",
"assert find_last_occurrence([2, 2, 1, 5, 6, 6, 6, 9, 9, 9], 6) == 6"
] | [] | [
"Here is the Python function to find the index of the last occurrence of a given number in a sorted array:\n\n```python\ndef find_last_occurrence(A, x):\n left, right = 0, len(A) - 1\n result = -1\n \n while left <= right:\n mid = (left + right) // 2\n \n if A[mid] == x:\n ... | [
1
] | |
317 | Write a function to reflect the modified run-length encoding from a list. | from itertools import groupby
def modified_encode(alist):
def ctr_ele(el):
if len(el)>1: return [len(el), el[0]]
else: return el[0]
return [ctr_ele(list(group)) for key, group in groupby(alist)] | [
"assert modified_encode([1,1,2,3,4,4,5,1])==[[2, 1], 2, 3, [2, 4], 5, 1]",
"assert modified_encode('automatically')==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y']",
"assert modified_encode('python')==['p', 'y', 't', 'h', 'o', 'n']"
] | [] | [
"Here is a Python function that implements the modified run-length encoding:\n\n```python\ndef modified_encode(alist):\n result = []\n count = 1\n for i in range(1, len(alist)):\n if alist[i] == alist[i-1]:\n count += 1\n else:\n result.append((count, alist[i-1]))\n ... | [
0
] | |
318 | Write a python function to find the maximum volume of a cuboid with given sum of sides. | def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue | [
"assert max_volume(8) == 18",
"assert max_volume(4) == 2",
"assert max_volume(1) == 0"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef max_volume(s):\n # The maximum volume of a cuboid is achieved when the sides are as close to each other as possible.\n # Therefore, we can divide the sum of sides by 3 to get the maximum volume.\n return s // 3\n```\n\nThis function take... | [
0
] | |
319 | Write a function to find all five characters long word in the given string by using regex. | import re
def find_long_word(text):
return (re.findall(r"\b\w{5}\b", text)) | [
"assert find_long_word('Please move back to strem') == ['strem']",
"assert find_long_word('4K Ultra HD streaming player') == ['Ultra']",
"assert find_long_word('Streaming Media Player') == ['Media']"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\nimport re\n\ndef find_long_word(text):\n \"\"\"\n Write a function to find all five characters long word in the given string by using regex.\n \"\"\"\n return re.findall(r'\\b\\w{5}\\b', text)\n```\n\nThis function uses the `re.findall()` meth... | [
1
] | |
320 | 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. | def sum_difference(n):
sumofsquares = 0
squareofsum = 0
for num in range(1, n+1):
sumofsquares += num * num
squareofsum += num
squareofsum = squareofsum ** 2
return squareofsum - sumofsquares | [
"assert sum_difference(12)==5434",
"assert sum_difference(20)==41230",
"assert sum_difference(54)==2151270"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\ndef sum_difference(n):\n \"\"\"\n 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.\n \"\"\"\n sum_n = n * (n + 1) // 2\n sum_n_squared = sum_n * ... | [
0
] | |
321 | Write a function to find the demlo number for the given number. | def find_demlo(s):
l = len(s)
res = ""
for i in range(1,l+1):
res = res + str(i)
for i in range(l-1,0,-1):
res = res + str(i)
return res | [
"assert find_demlo(\"111111\") == '12345654321'",
"assert find_demlo(\"1111\") == '1234321'",
"assert find_demlo(\"13333122222\") == '123456789101110987654321'"
] | [] | [
"Sure, I can help you with that. The demlo number for a given number is a sequence of digits that starts with the number itself and then continues with the digits of the number in reverse order. For example, the demlo number for 123 is 123321.\n\nHere's the Python function to find the demlo number for a given numbe... | [
0
] | |
322 | Write a function to find all index positions of the minimum values in a given list. | def position_min(list1):
min_val = min(list1)
min_result = [i for i, j in enumerate(list1) if j == min_val]
return min_result | [
"assert position_min([12,33,23,10,67,89,45,667,23,12,11,10,54])==[3,11]",
"assert position_min([1,2,2,2,4,4,4,5,5,5,5])==[0]",
"assert position_min([2,1,5,6,8,3,4,9,10,11,8,12])==[1]"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef position_min(list1):\n \"\"\"\n Write a function to find all index positions of the minimum values in a given list.\n \"\"\"\n min_value = min(list1)\n return [i for i, x in enumerate(list1) if x == min_value]\n```\n\nThis function... | [
1
] | |
323 | Write a function to re-arrange the given array in alternating positive and negative items. | def right_rotate(arr, n, out_of_place, cur):
temp = arr[cur]
for i in range(cur, out_of_place, -1):
arr[i] = arr[i - 1]
arr[out_of_place] = temp
return arr
def re_arrange(arr, n):
out_of_place = -1
for index in range(n):
if (out_of_place >= 0):
if ((arr[index] >= 0 and arr[out_of_place] < 0) or
... | [
"assert re_arrange([-5, -2, 5, 2, 4,\t7, 1, 8, 0, -8], 10) == [-5, 5, -2, 2, -8, 4, 7, 1, 8, 0]",
"assert re_arrange([1, 2, 3, -4, -1, 4], 6) == [-4, 1, -1, 2, 3, 4]",
"assert re_arrange([4, 7, 9, 77, -4, 5, -3, -9], 8) == [-4, 4, -3, 7, -9, 9, 77, 5]"
] | [] | [
"Here is a Python function that re-arranges the given array in alternating positive and negative items:\n\n```python\ndef re_arrange(arr, n):\n \"\"\"\n Write a function to re-arrange the given array in alternating positive and negative items.\n \"\"\"\n pos = 0\n neg = 1\n while pos < n and neg <... | [
0
] | |
324 | Write a function to extract the sum of alternate chains of tuples. | def sum_of_alternates(test_tuple):
sum1 = 0
sum2 = 0
for idx, ele in enumerate(test_tuple):
if idx % 2:
sum1 += ele
else:
sum2 += ele
return ((sum1),(sum2)) | [
"assert sum_of_alternates((5, 6, 3, 6, 10, 34)) == (46, 18)",
"assert sum_of_alternates((1, 2, 3, 4, 5)) == (6, 9)",
"assert sum_of_alternates((6, 7, 8, 9, 4, 5)) == (21, 18)"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef sum_of_alternates(test_tuple):\n \"\"\"\n Write a function to extract the sum of alternate chains of tuples.\n \"\"\"\n sum = 0\n for i in range(0, len(test_tuple), 2):\n sum += test_tuple[i][0] + test_tuple[i][1]\n return sum\n`... | [
0
] | |
325 | Write a python function to find the minimum number of squares whose sum is equal to a given number. | def get_Min_Squares(n):
if n <= 3:
return n;
res = n
for x in range(1,n + 1):
temp = x * x;
if temp > n:
break
else:
res = min(res,1 + get_Min_Squares(n - temp))
return res; | [
"assert get_Min_Squares(6) == 3",
"assert get_Min_Squares(2) == 2",
"assert get_Min_Squares(4) == 1"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef get_Min_Squares(n):\n # Base case: if n is 0, return 0\n if n == 0:\n return 0\n \n # Initialize the minimum number of squares to n\n min_squares = n\n \n # Iterate through all possible square numbers less than or equa... | [
1
] | |
326 | Write a function to get the word with most number of occurrences in the given strings list. | from collections import defaultdict
def most_occurrences(test_list):
temp = defaultdict(int)
for sub in test_list:
for wrd in sub.split():
temp[wrd] += 1
res = max(temp, key=temp.get)
return (str(res)) | [
"assert most_occurrences([\"UTS is best for RTF\", \"RTF love UTS\", \"UTS is best\"] ) == 'UTS'",
"assert most_occurrences([\"Its been a great year\", \"this year is so worse\", \"this year is okay\"] ) == 'year'",
"assert most_occurrences([\"Families can be reunited\", \"people can be reunited\", \"Tasks can ... | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef most_occurrences(test_list):\n # Create a dictionary to store the count of each word\n word_count = {}\n \n # Iterate over each string in the list\n for string in test_list:\n # Split the string into words\n words = s... | [
0
] | |
327 | Write a function to print check if the triangle is isosceles or not. | def check_isosceles(x,y,z):
if x==y or y==z or z==x:
return True
else:
return False | [
"assert check_isosceles(6,8,12)==False ",
"assert check_isosceles(6,6,12)==True",
"assert check_isosceles(6,16,20)==False"
] | [] | [
"Sure, here is the Python function to check if a triangle is isosceles or not:\n\n```python\ndef check_isosceles(x,y,z):\n \"\"\"\n Write a function to print check if the triangle is isosceles or not.\n \"\"\"\n if x == y or y == z or x == z:\n print(\"The triangle is isosceles.\")\n else:\n ... | [
0
] | |
328 | Write a function to rotate a given list by specified number of items to the left direction. | def rotate_left(list1,m,n):
result = list1[m:]+list1[:n]
return result | [
"assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]",
"assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[3, 4, 5, 6, 7, 8, 9, 10, 1, 2]",
"assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2]"
] | [] | [
"Here is a Python function that rotates a given list by specified number of items to the left direction:\n\n```python\ndef rotate_left(list1, m, n):\n \"\"\"\n Write a function to rotate a given list by specified number of items to the left direction.\n \"\"\"\n # Calculate the effective rotation needed... | [
0
] | |
329 | Write a python function to count negative numbers in a list. | def neg_count(list):
neg_count= 0
for num in list:
if num <= 0:
neg_count += 1
return neg_count | [
"assert neg_count([-1,-2,3,-4,-5]) == 4",
"assert neg_count([1,2,3]) == 0",
"assert neg_count([1,2,-3,-10,20]) == 2"
] | [] | [
"Here is the Python function to count negative numbers in a list:\n\n```python\ndef neg_count(list):\n \"\"\"\n Write a python function to count negative numbers in a list.\n \"\"\"\n count = 0\n for num in list:\n if num < 0:\n count += 1\n return count\n```\n\nYou can use this ... | [
0
] | |
330 | Write a function to find all three, four, five characters long words in the given string by using regex. | import re
def find_char(text):
return (re.findall(r"\b\w{3,5}\b", text)) | [
"assert find_char('For the four consumer complaints contact manager AKR reddy') == ['For', 'the', 'four', 'AKR', 'reddy']",
"assert find_char('Certain service are subject to change MSR') == ['are', 'MSR']",
"assert find_char('Third party legal desclaimers') == ['Third', 'party', 'legal']"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\nimport re\n\ndef find_char(text):\n \"\"\"\n Write a function to find all three, four, five characters long words in the given string by using regex.\n \"\"\"\n return re.findall(r'\\b\\w{3,5}\\b', text)\n```\n\nThis function uses the `re.findall... | [
1
] | |
331 | Write a python function to count unset bits of a given number. | def count_unset_bits(n):
count = 0
x = 1
while(x < n + 1):
if ((x & n) == 0):
count += 1
x = x << 1
return count | [
"assert count_unset_bits(2) == 1",
"assert count_unset_bits(4) == 2",
"assert count_unset_bits(6) == 1"
] | [] | [
"Here is the Python function to count unset bits of a given number:\n\n```python\ndef count_unset_bits(n):\n count = 0\n while n:\n if n & 1 == 0:\n count += 1\n n >>= 1\n return count\n```\n\nThis function works by iterating over each bit of the number `n`. If the bit is unset (i.... | [
1
] | |
332 | Write a function to count character frequency of a given string. | def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict | [
"assert char_frequency('python')=={'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}",
"assert char_frequency('program')=={'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1}",
"assert char_frequency('language')=={'l': 1, 'a': 2, 'n': 1, 'g': 2, 'u': 1, 'e': 1}"
] | [] | [
"Here is the Python function to count character frequency of a given string:\n\n```python\ndef char_frequency(str1):\n frequency = {}\n for char in str1:\n if char in frequency:\n frequency[char] += 1\n else:\n frequency[char] = 1\n return frequency\n```\n\nYou can use t... | [
0
] | |
333 | Write a python function to sort a list according to the second element in sublist. | def Sort(sub_li):
sub_li.sort(key = lambda x: x[1])
return sub_li | [
"assert Sort([['a', 10], ['b', 5], ['c', 20], ['d', 15]]) == [['b', 5], ['a', 10], ['d', 15], ['c', 20]]",
"assert Sort([['452', 10], ['256', 5], ['100', 20], ['135', 15]]) == [['256', 5], ['452', 10], ['135', 15], ['100', 20]]",
"assert Sort([['rishi', 10], ['akhil', 5], ['ramya', 20], ['gaur', 15]]) == [['akh... | [] | [
"Here is the Python function to sort a list according to the second element in sublist:\n\n```python\ndef Sort(sub_li):\n sub_li.sort(key=lambda x: x[1])\n return sub_li\n```\n\nThis function uses the built-in `sort()` method of Python lists, which sorts the list in-place. The `key` parameter of the `sort()` ... | [
1
] | |
334 | Write a python function to check whether the triangle is valid or not if sides are given. | def check_Validity(a,b,c):
if (a + b <= c) or (a + c <= b) or (b + c <= a) :
return False
else:
return True | [
"assert check_Validity(1,2,3) == False",
"assert check_Validity(2,3,5) == False",
"assert check_Validity(7,10,5) == True"
] | [] | [
"Sure, here is a Python function that checks whether a triangle is valid or not based on the given sides:\n\n```python\ndef check_Validity(a, b, c):\n \"\"\"\n Write a python function to check whether the triangle is valid or not if sides are given.\n \"\"\"\n if a + b > c and a + c > b and b + c > a:\n... | [
1
] | |
335 | Write a function to find the sum of arithmetic progression. | def ap_sum(a,n,d):
total = (n * (2 * a + (n - 1) * d)) / 2
return total | [
"assert ap_sum(1,5,2)==25",
"assert ap_sum(2,6,4)==72",
"assert ap_sum(1,4,5)==34"
] | [] | [
"Sure, here is the Python function to find the sum of an arithmetic progression:\n\n```python\ndef ap_sum(a, n, d):\n \"\"\"\n Write a function to find the sum of arithmetic progression.\n \"\"\"\n return (n/2) * (2*a + (n-1)*d)\n```\n\nThis function takes three parameters: `a` (the first term of the ar... | [
1
] | |
336 | Write a function to check whether the given month name contains 28 days or not. | def check_monthnum(monthname1):
if monthname1 == "February":
return True
else:
return False | [
"assert check_monthnum(\"February\")==True",
"assert check_monthnum(\"January\")==False",
"assert check_monthnum(\"March\")==False"
] | [] | [
"Sure, here is the Python function to check whether the given month name contains 28 days or not:\n\n```python\ndef check_monthnum(monthname1):\n \"\"\"\n Write a function to check whether the given month name contains 28 days or not.\n \"\"\"\n if monthname1 in ['February']:\n return True\n e... | [
1
] | |
337 | Write a function that matches a word at the end of a string, with optional punctuation. | import re
def text_match_word(text):
patterns = '\w+\S*$'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!' | [
"assert text_match_word(\"python.\")==('Found a match!')",
"assert text_match_word(\"python.\")==('Found a match!')",
"assert text_match_word(\" lang .\")==('Not matched!')"
] | [] | [
"Here is a Python function that matches a word at the end of a string, with optional punctuation:\n\n```python\nimport re\n\ndef text_match_word(text):\n \"\"\"\n Write a function that matches a word at the end of a string, with optional punctuation.\n \"\"\"\n pattern = r'\\b\\w+\\b'\n match = re.se... | [
0
] | |
338 | Write a python function to count the number of substrings with same first and last characters. | def check_Equality(s):
return (ord(s[0]) == ord(s[len(s) - 1]));
def count_Substring_With_Equal_Ends(s):
result = 0;
n = len(s);
for i in range(n):
for j in range(1,n-i+1):
if (check_Equality(s[i:i+j])):
result+=1;
return result; | [
"assert count_Substring_With_Equal_Ends('aba') == 4",
"assert count_Substring_With_Equal_Ends('abcab') == 7",
"assert count_Substring_With_Equal_Ends('abc') == 3"
] | [] | [
"Here is the Python function to count the number of substrings with same first and last characters:\n\n```python\ndef count_Substring_With_Equal_Ends(s):\n count = 0\n for i in range(len(s)):\n for j in range(i, len(s)):\n if s[i] == s[j]:\n count += 1\n return count\n```\n... | [
1
] | |
339 | Write a python function to find the maximum occuring divisor in an interval. | def find_Divisor(x,y):
if (x==y):
return y
return 2 | [
"assert find_Divisor(2,2) == 2",
"assert find_Divisor(2,5) == 2",
"assert find_Divisor(5,10) == 2"
] | [] | [
"Here is a Python function that finds the maximum occurring divisor in an interval:\n\n```python\ndef find_Divisor(x,y):\n \"\"\"\n Write a python function to find the maximum occuring divisor in an interval.\n \"\"\"\n max_divisor = 1\n for i in range(1, min(x, y) + 1):\n if x % i == 0 and y ... | [
0
] | |
340 | Write a python function to find the sum of the three lowest positive numbers from a given list of numbers. | def sum_three_smallest_nums(lst):
return sum(sorted([x for x in lst if x > 0])[:3]) | [
"assert sum_three_smallest_nums([10,20,30,40,50,60,7]) == 37",
"assert sum_three_smallest_nums([1,2,3,4,5]) == 6",
"assert sum_three_smallest_nums([0,1,2,3,4,5]) == 6"
] | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef sum_three_smallest_nums(lst):\n # Filter out negative numbers and sort the remaining numbers\n lst = [num for num in lst if num > 0]\n lst.sort()\n \n # Return the sum of the first three numbers\n return sum(lst[:3])\n```\n\nThis... | [
1
] | |
341 | Write a function to convert the given set into ordered tuples. | def set_to_tuple(s):
t = tuple(sorted(s))
return (t) | [
"assert set_to_tuple({1, 2, 3, 4, 5}) == (1, 2, 3, 4, 5)",
"assert set_to_tuple({6, 7, 8, 9, 10, 11}) == (6, 7, 8, 9, 10, 11)",
"assert set_to_tuple({12, 13, 14, 15, 16}) == (12, 13, 14, 15, 16)"
] | [] | [
"Here is the Python function to convert a set into ordered tuples:\n\n```python\ndef set_to_tuple(s):\n \"\"\"\n Write a function to convert the given set into ordered tuples.\n \"\"\"\n return tuple(sorted(s))\n```\n\nThis function takes a set as input and returns a tuple containing the elements of the... | [
1
] | |
342 | Write a function to find the smallest range that includes at-least one element from each of the given arrays. | from heapq import heappop, heappush
class Node:
def __init__(self, value, list_num, index):
self.value = value
self.list_num = list_num
self.index = index
def __lt__(self, other):
return self.value < other.value
def find_minimum_range(list):
high = float('-inf')
... | [
"assert find_minimum_range([[3, 6, 8, 10, 15], [1, 5, 12], [4, 8, 15, 16], [2, 6]]) == (4, 6)",
"assert find_minimum_range([[ 2, 3, 4, 8, 10, 15 ], [1, 5, 12], [7, 8, 15, 16], [3, 6]]) == (4, 7)",
"assert find_minimum_range([[4, 7, 9, 11, 16], [2, 6, 13], [5, 9, 16, 17], [3, 7]]) == (5, 7)"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef find_minimum_range(list):\n # Initialize the minimum range to be the maximum possible value\n min_range = float('inf')\n # Initialize the start and end indices of the minimum range\n start = 0\n end = 0\n \n # Create a dictionary to ... | [
0
] | |
343 | Write a function to calculate the number of digits and letters in a string. | def dig_let(s):
d=l=0
for c in s:
if c.isdigit():
d=d+1
elif c.isalpha():
l=l+1
else:
pass
return (l,d) | [
"assert dig_let(\"python\")==(6,0)",
"assert dig_let(\"program\")==(7,0)",
"assert dig_let(\"python3.0\")==(6,2)"
] | [] | [
"Here is a Python function that calculates the number of digits and letters in a string:\n\n```python\ndef dig_let(s):\n digits = 0\n letters = 0\n for char in s:\n if char.isdigit():\n digits += 1\n elif char.isalpha():\n letters += 1\n return digits, letters\n```\n\... | [
0
] | |
344 | Write a python function to find number of elements with odd factors in a given range. | def count_Odd_Squares(n,m):
return int(m**0.5) - int((n-1)**0.5) | [
"assert count_Odd_Squares(5,100) == 8",
"assert count_Odd_Squares(8,65) == 6",
"assert count_Odd_Squares(2,5) == 1"
] | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef count_Odd_Squares(n,m):\n \"\"\"\n Write a python function to find number of elements with odd factors in a given range.\n \"\"\"\n count = 0\n for i in range(n, m+1):\n if i**0.5 == int(i**0.5):\n count += 1\n ... | [
1
] | |
345 | Write a function to find the difference between two consecutive numbers in a given list. | def diff_consecutivenums(nums):
result = [b-a for a, b in zip(nums[:-1], nums[1:])]
return result | [
"assert diff_consecutivenums([1, 1, 3, 4, 4, 5, 6, 7])==[0, 2, 1, 0, 1, 1, 1]",
"assert diff_consecutivenums([4, 5, 8, 9, 6, 10])==[1, 3, 1, -3, 4]",
"assert diff_consecutivenums([0, 1, 2, 3, 4, 4, 4, 4, 5, 7])==[1, 1, 1, 1, 0, 0, 0, 1, 2]"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\ndef diff_consecutivenums(nums):\n \"\"\"\n Write a function to find the difference between two consecutive numbers in a given list.\n \"\"\"\n if len(nums) < 2:\n return \"List must contain at least two elements.\"\n \n diff = []\... | [
1
] | |
346 | Write a function to find entringer number e(n, k). | def zigzag(n, k):
if (n == 0 and k == 0):
return 1
if (k == 0):
return 0
return zigzag(n, k - 1) + zigzag(n - 1, n - k) | [
"assert zigzag(4, 3) == 5",
"assert zigzag(4, 2) == 4",
"assert zigzag(3, 1) == 1"
] | [] | [
"Sure, I can help you solve the problem. The entringer number e(n, k) is a sequence of numbers that follows a specific pattern. Here's a Python function to calculate it:\n\n```python\ndef zigzag(n, k):\n \"\"\"\n Calculate the entringer number e(n, k).\n \"\"\"\n if n == 0:\n return 0\n elif n... | [
0
] | |
347 | Write a python function to count the number of squares in a rectangle. | def count_Squares(m,n):
if (n < m):
temp = m
m = n
n = temp
return n * (n + 1) * (3 * m - n + 1) // 6 | [
"assert count_Squares(4,3) == 20",
"assert count_Squares(1,2) == 2",
"assert count_Squares(2,2) == 5"
] | [] | [
"Sure, here is a Python function that counts the number of squares in a rectangle:\n\n```python\ndef count_Squares(m, n):\n \"\"\"\n Write a python function to count the number of squares in a rectangle.\n \"\"\"\n count = 0\n for i in range(1, m+1):\n for j in range(1, n+1):\n if i... | [
0
] | |
348 | Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values. | def bin_coff(n, r):
val = 1
if (r > (n - r)):
r = (n - r)
for i in range(0, r):
val *= (n - i)
val //= (i + 1)
return val
def find_ways(M):
n = M // 2
a = bin_coff(2 * n, n)
b = a // (n + 1)
return (b) | [
"assert find_ways(4) == 2",
"assert find_ways(6) == 5",
"assert find_ways(8) == 14"
] | [] | [
"Here is a Python function that counts sequences of given length having non-negative prefix sums that can be generated by given values:\n\n```python\ndef find_ways(M):\n n = len(M)\n dp = [[0 for _ in range(n+1)] for _ in range(n+1)]\n \n for i in range(1, n+1):\n for j in range(1, n+1):\n ... | [
0
] | |
349 | Write a python function to check whether the given string is a binary string or not. | def check(string) :
p = set(string)
s = {'0', '1'}
if s == p or p == {'0'} or p == {'1'}:
return ("Yes")
else :
return ("No") | [
"assert check(\"01010101010\") == \"Yes\"",
"assert check(\"name0\") == \"No\"",
"assert check(\"101\") == \"Yes\""
] | [] | [
"Sure, here is the Python function to check whether the given string is a binary string or not:\n\n```python\ndef check(string):\n \"\"\"\n Write a python function to check whether the given string is a binary string or not.\n \"\"\"\n for char in string:\n if char not in ['0', '1']:\n ... | [
0
] | |
350 | Write a python function to minimize the length of the string by removing occurrence of only one character. | def minimum_Length(s) :
maxOcc = 0
n = len(s)
arr = [0]*26
for i in range(n) :
arr[ord(s[i]) -ord('a')] += 1
for i in range(26) :
if arr[i] > maxOcc :
maxOcc = arr[i]
return n - maxOcc | [
"assert minimum_Length(\"mnm\") == 1",
"assert minimum_Length(\"abcda\") == 3",
"assert minimum_Length(\"abcb\") == 2"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef minimum_Length(s):\n \"\"\"\n Write a python function to minimize the length of the string by removing occurrence of only one character.\n \"\"\"\n if len(s) == 0:\n return 0\n else:\n return len(set(s))\n```\n\nThis ... | [
0
] | |
351 | Write a python function to find the first element occurring k times in a given array. | def first_Element(arr,n,k):
count_map = {};
for i in range(0, n):
if(arr[i] in count_map.keys()):
count_map[arr[i]] += 1
else:
count_map[arr[i]] = 1
i += 1
for i in range(0, n):
if (count_map[arr[i]] == k):
return arr[i]
... | [
"assert first_Element([0,1,2,3,4,5],6,1) == 0",
"assert first_Element([1,2,1,3,4],5,2) == 1",
"assert first_Element([2,3,4,3,5,7,1,2,3,5],10,2) == 2"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef first_Element(arr,n,k):\n count = [0]*n\n for i in range(n):\n count[arr[i]] += 1\n for i in range(n):\n if count[arr[i]] == k:\n return arr[i]\n return -1\n```\n\nThis function first creates a count array of ... | [
1
] | |
352 | Write a python function to check whether all the characters in a given string are unique. | def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1,len(str)):
if (str[i] == str[j]):
return False;
return True; | [
"assert unique_Characters('aba') == False",
"assert unique_Characters('abc') == True",
"assert unique_Characters('abab') == False"
] | [] | [
"Here is the Python function to check whether all the characters in a given string are unique:\n\n```python\ndef unique_characters(str):\n \"\"\"\n Write a python function to check whether all the characters in a given string are unique.\n \"\"\"\n return len(set(str)) == len(str)\n```\n\nThis function ... | [
0
] | |
353 | Write a function to remove a specified column from a given nested list. | def remove_column(list1, n):
for i in list1:
del i[n]
return list1 | [
"assert remove_column([[1, 2, 3], [2, 4, 5], [1, 1, 1]],0)==[[2, 3], [4, 5], [1, 1]]",
"assert remove_column([[1, 2, 3], [-2, 4, -5], [1, -1, 1]],2)==[[1, 2], [-2, 4], [1, -1]]",
"assert remove_column([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]],0)==[[3], [7], [3], [15, 17], [7], [11]]"
] | [] | [
"Here is a Python function that removes a specified column from a given nested list:\n\n```python\ndef remove_column(list1, n):\n \"\"\"\n Write a function to remove a specified column from a given nested list.\n \"\"\"\n return [sublist[:n] + sublist[n+1:] for sublist in list1]\n```\n\nThis function ta... | [
1
] | |
354 | Write a function to find t-nth term of arithemetic progression. | def tn_ap(a,n,d):
tn = a + (n - 1) * d
return tn | [
"assert tn_ap(1,5,2)==9",
"assert tn_ap(2,6,4)==22",
"assert tn_ap(1,4,5)==16"
] | [] | [
"Sure, here is the Python function to find the t-nth term of an arithmetic progression:\n\n```python\ndef tn_ap(a, n, d):\n \"\"\"\n Write a function to find t-nth term of arithemetic progression.\n \"\"\"\n return a + (n-1)*d\n```\n\nThis function takes three arguments: `a` (the first term of the arith... | [
1
] | |
355 | Write a python function to count the number of rectangles in a circle of radius r. | def count_Rectangles(radius):
rectangles = 0
diameter = 2 * radius
diameterSquare = diameter * diameter
for a in range(1, 2 * radius):
for b in range(1, 2 * radius):
diagnalLengthSquare = (a * a + b * b)
if (diagnalLengthSquare <= diameterSquare) :
... | [
"assert count_Rectangles(2) == 8",
"assert count_Rectangles(1) == 1",
"assert count_Rectangles(0) == 0"
] | [] | [
"Here is a Python function that counts the number of rectangles in a circle of radius r:\n\n```python\nimport math\n\ndef count_Rectangles(radius):\n \"\"\"\n Write a python function to count the number of rectangles in a circle of radius r.\n \"\"\"\n count = 0\n for x in range(-radius, radius + 1):... | [
0
] | |
356 | Write a function to find the third angle of a triangle using two angles. | def find_angle(a,b):
c = 180 - (a + b)
return c
| [
"assert find_angle(47,89)==44",
"assert find_angle(45,95)==40",
"assert find_angle(50,40)==90"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef find_angle(a,b):\n \"\"\"\n Write a function to find the third angle of a triangle using two angles.\n \"\"\"\n return 180 - (a + b)\n```\n\nThis function takes two angles as input and returns the third angle of the triangle. The formula used is th... | [
1
] | |
357 | Write a function to find the maximum element of all the given tuple records. | def find_max(test_list):
res = max(int(j) for i in test_list for j in i)
return (res) | [
"assert find_max([(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)]) == 10",
"assert find_max([(3, 5), (7, 8), (6, 2), (7, 11), (9, 8)]) == 11",
"assert find_max([(4, 6), (8, 9), (7, 3), (8, 12), (10, 9)]) == 12"
] | [] | [
"Here is the Python function to find the maximum element of all the given tuple records:\n\n```python\ndef find_max(test_list):\n \"\"\"\n Write a function to find the maximum element of all the given tuple records.\n \"\"\"\n return max(test_list)\n```\n\nThis function uses the built-in `max()` functio... | [
0
] | |
358 | Write a function to find modulo division of two lists using map and lambda function. | def moddiv_list(nums1,nums2):
result = map(lambda x, y: x % y, nums1, nums2)
return list(result) | [
"assert moddiv_list([4,5,6],[1, 2, 3])==[0, 1, 0]",
"assert moddiv_list([3,2],[1,4])==[0, 2]",
"assert moddiv_list([90,120],[50,70])==[40, 50]"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef moddiv_list(nums1, nums2):\n \"\"\"\n Write a function to find modulo division of two lists using map and lambda function.\n \"\"\"\n return list(map(lambda x, y: x % y, nums1, nums2))\n\n# Test the function\nnums1 = [10, 20, 30, 40, 50]\nnums2 = [... | [
1
] | |
359 | Write a python function to check whether one root of the quadratic equation is twice of the other or not. | def Check_Solution(a,b,c):
if (2*b*b == 9*a*c):
return ("Yes");
else:
return ("No"); | [
"assert Check_Solution(1,3,2) == \"Yes\"",
"assert Check_Solution(1,2,3) == \"No\"",
"assert Check_Solution(1,-5,6) == \"No\""
] | [] | [
"Sure, here is the Python function to check whether one root of the quadratic equation is twice of the other or not:\n\n```python\ndef Check_Solution(a, b, c):\n \"\"\"\n Write a python function to check whether one root of the quadratic equation is twice of the other or not.\n \"\"\"\n # Calculate the ... | [
0
] | |
360 | Write a function to find the n’th carol number. | def get_carol(n):
result = (2**n) - 1
return result * result - 2 | [
"assert get_carol(2) == 7",
"assert get_carol(4) == 223",
"assert get_carol(5) == 959"
] | [] | [
"Sure, here is the Python function to find the n'th Carol number:\n\n```python\ndef get_carol(n):\n \"\"\"\n Write a function to find the n’th carol number.\n \"\"\"\n return 2**n - 1\n```\n\nThe Carol number is defined as:\n\nC(n) = 2^n - 1\n\nSo, the function `get_carol(n)` simply calculates 2^n - 1 a... | [
0
] | |
361 | Write a function to remove empty lists from a given list of lists. | def remove_empty(list1):
remove_empty = [x for x in list1 if x]
return remove_empty | [
"assert remove_empty([[], [], [], 'Red', 'Green', [1,2], 'Blue', [], []])==['Red', 'Green', [1, 2], 'Blue']",
"assert remove_empty([[], [], [],[],[], 'Green', [1,2], 'Blue', [], []])==[ 'Green', [1, 2], 'Blue']",
"assert remove_empty([[], [], [], 'Python',[],[], 'programming', 'language',[],[],[], [], []])==['P... | [] | [
"Here is the Python function to remove empty lists from a given list of lists:\n\n```python\ndef remove_empty(list1):\n \"\"\"\n Write a function to remove empty lists from a given list of lists.\n \"\"\"\n return [sublist for sublist in list1 if sublist]\n```\n\nThis function uses a list comprehension ... | [
1
] | |
362 | Write a python function to find the item with maximum occurrences in a given list. | def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
occu = nums.count(i)
if occu > max_val:
max_val = occu
result = i
return result | [
"assert max_occurrences([1,2,3,1,2,3,12,4,2]) == 2",
"assert max_occurrences([1,2,6,7,0,1,0,1,0]) == 1,0",
"assert max_occurrences([1,2,3,1,2,4,1]) == 1"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef max_occurrences(nums):\n # Create a dictionary to store the count of each number\n count_dict = {}\n \n # Iterate over the list and update the count of each number\n for num in nums:\n if num in count_dict:\n coun... | [
1
] | |
363 | Write a function to add the k elements to each element in the tuple. | def add_K_element(test_list, K):
res = [tuple(j + K for j in sub ) for sub in test_list]
return (res) | [
"assert add_K_element([(1, 3, 4), (2, 4, 6), (3, 8, 1)], 4) == [(5, 7, 8), (6, 8, 10), (7, 12, 5)]",
"assert add_K_element([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 8) == [(9, 10, 11), (12, 13, 14), (15, 16, 17)]",
"assert add_K_element([(11, 12, 13), (14, 15, 16), (17, 18, 19)], 9) == [(20, 21, 22), (23, 24, 25), (26... | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef add_K_element(test_list, K):\n \"\"\"\n Write a function to add the k elements to each element in the tuple.\n \"\"\"\n return tuple([x + K for x in test_list])\n```\n\nThis function takes a tuple `test_list` and an integer `K` as inpu... | [
0
] | |
364 | Write a function to find the number of flips required to make the given binary string a sequence of alternate characters. | def make_flip(ch):
return '1' if (ch == '0') else '0'
def get_flip_with_starting_charcter(str, expected):
flip_count = 0
for i in range(len( str)):
if (str[i] != expected):
flip_count += 1
expected = make_flip(expected)
return flip_count
def min_flip_to_make_string_alternate(str):
return mi... | [
"assert min_flip_to_make_string_alternate(\"0001010111\") == 2",
"assert min_flip_to_make_string_alternate(\"001\") == 1",
"assert min_flip_to_make_string_alternate(\"010111011\") == 2 "
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef min_flip_to_make_string_alternate(str):\n # Initialize the count of flips\n flip_count = 0\n \n # Iterate through the string\n for i in range(len(str)):\n # If the current character is different from the previous one, increment the ... | [
0
] | |
365 | Write a python function to count the number of digits of a given number. | def count_Digit(n):
count = 0
while n != 0:
n //= 10
count += 1
return count | [
"assert count_Digit(12345) == 5",
"assert count_Digit(11223305) == 8",
"assert count_Digit(4123459) == 7"
] | [] | [
"Here is the Python function to count the number of digits of a given number:\n\n```python\ndef count_Digit(n):\n \"\"\"\n Write a python function to count the number of digits of a given number.\n \"\"\"\n count = 0\n while n > 0:\n n //= 10\n count += 1\n return count\n```\n\nThis ... | [
1
] | |
366 | Write a python function to find the largest product of the pair of adjacent elements from a given list of integers. | def adjacent_num_product(list_nums):
return max(a*b for a, b in zip(list_nums, list_nums[1:])) | [
"assert adjacent_num_product([1,2,3,4,5,6]) == 30",
"assert adjacent_num_product([1,2,3,4,5]) == 20",
"assert adjacent_num_product([2,3]) == 6"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef adjacent_num_product(list_nums):\n \"\"\"\n Write a python function to find the largest product of the pair of adjacent elements from a given list of integers.\n \"\"\"\n if len(list_nums) < 2:\n return \"List must contain at least two eleme... | [
1
] | |
367 | Write a function to check if a binary tree is balanced or not. | class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def get_height(root):
if root is None:
return 0
return max(get_height(root.left), get_height(root.right)) + 1
def is_tree_balanced(root):
if root is None:
return True
lh = get_height(root.left)
... | [
"assert is_tree_balanced(root) == False",
"assert is_tree_balanced(root1) == True",
"assert is_tree_balanced(root2) == False "
] | root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
root.left.left.left = Node(8)
root1 = Node(1)
root1.left = Node(2)
root1.right = Node(3)
root1.left.left = Node(4)
root1.left.right = Node(5)
root1.right.left = Node(6)
root1.left.left.left... | [] | [
"Sure, I can help you solve this problem. A binary tree is considered balanced if the height difference between the left and right subtrees of every node is at most 1. Here's a Python function to check if a binary tree is balanced:\n\n```python\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):... | [
0
] |
368 | Write a function to repeat the given tuple n times. | def repeat_tuples(test_tup, N):
res = ((test_tup, ) * N)
return (res) | [
"assert repeat_tuples((1, 3), 4) == ((1, 3), (1, 3), (1, 3), (1, 3))",
"assert repeat_tuples((1, 2), 3) == ((1, 2), (1, 2), (1, 2))",
"assert repeat_tuples((3, 4), 5) == ((3, 4), (3, 4), (3, 4), (3, 4), (3, 4))"
] | [] | [
"Here is the Python function to repeat a given tuple n times:\n\n```python\ndef repeat_tuples(test_tup, N):\n \"\"\"\n Write a function to repeat the given tuple n times.\n \"\"\"\n return test_tup * N\n```\n\nYou can use this function by passing a tuple and an integer as arguments. For example:\n\n```p... | [
0
] | |
369 | Write a function to find the lateral surface area of cuboid | def lateralsurface_cuboid(l,w,h):
LSA = 2*h*(l+w)
return LSA | [
"assert lateralsurface_cuboid(8,5,6)==156",
"assert lateralsurface_cuboid(7,9,10)==320",
"assert lateralsurface_cuboid(10,20,30)==1800"
] | [] | [
"Sure, here is the Python function to find the lateral surface area of a cuboid:\n\n```python\ndef lateralsurface_cuboid(l, w, h):\n \"\"\"\n Write a function to find the lateral surface area of cuboid\n \"\"\"\n return 2 * (l * w + l * h + w * h)\n```\n\nThis function takes three arguments: `l` (length... | [
0
] | |
370 | Write a function to sort a tuple by its float element. | def float_sort(price):
float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True)
return float_sort | [
"assert float_sort([('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')])==[('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')] ",
"assert float_sort([('item1', '15'), ('item2', '10'), ('item3', '20')])==[('item3', '20'), ('item1', '15'), ('item2', '10')] ",
"assert float_sort([('item1', '5'), ('it... | [] | [
"Here is the solution to the problem:\n\n```python\ndef float_sort(price):\n \"\"\"\n Write a function to sort a tuple by its float element.\n \"\"\"\n return sorted(price, key=lambda x: x[1])\n```\n\nIn this solution, the `sorted()` function is used to sort the tuple. The `key` parameter is set to a la... | [
0
] | |
371 | Write a function to find the smallest missing element in a sorted array. | def smallest_missing(A, left_element, right_element):
if left_element > right_element:
return left_element
mid = left_element + (right_element - left_element) // 2
if A[mid] == mid:
return smallest_missing(A, mid + 1, right_element)
else:
return smallest_missing(A, left_el... | [
"assert smallest_missing([0, 1, 2, 3, 4, 5, 6], 0, 6) == 7",
"assert smallest_missing([0, 1, 2, 6, 9, 11, 15], 0, 6) == 3",
"assert smallest_missing([1, 2, 3, 4, 6, 9, 11, 15], 0, 7) == 0"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef smallest_missing(A, left_element, right_element):\n if left_element > right_element:\n return left_element\n mid = (left_element + right_element) // 2\n if A[mid] == mid + 1:\n return smallest_missing(A, mid + 1, right_element)\n ... | [
0
] | |
372 | Write a function to sort a given list of elements in ascending order using heap queue algorithm. | import heapq as hq
def heap_assending(nums):
hq.heapify(nums)
s_result = [hq.heappop(nums) for i in range(len(nums))]
return s_result | [
"assert heap_assending([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==[1, 2, 3, 4, 7, 8, 9, 9, 10, 14, 18]",
"assert heap_assending([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]",
"assert heap_assending([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\nimport heapq\n\ndef heap_assending(nums):\n \"\"\"\n Write a function to sort a given list of elements in ascending order using heap queue algorithm.\n \"\"\"\n heapq.heapify(nums)\n return [heapq.heappop(nums) for _ in range(len(nums))]\n\... | [
1
] | |
373 | Write a function to find the volume of a cuboid. | def volume_cuboid(l,w,h):
volume=l*w*h
return volume | [
"assert volume_cuboid(1,2,3)==6",
"assert volume_cuboid(5,7,9)==315",
"assert volume_cuboid(10,15,21)==3150"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\ndef volume_cuboid(l,w,h):\n \"\"\"\n Write a function to find the volume of a cuboid.\n \"\"\"\n return l * w * h\n```\n\nThis function takes three arguments, `l`, `w`, and `h`, which represent the length, width, and height of the cuboid respe... | [
1
] | |
374 | Write a function to print all permutations of a given string including duplicates. | def permute_string(str):
if len(str) == 0:
return ['']
prev_list = permute_string(str[1:len(str)])
next_list = []
for i in range(0,len(prev_list)):
for j in range(0,len(str)):
new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]
if new_str not in ... | [
"assert permute_string('ab')==['ab', 'ba']",
"assert permute_string('abc')==['abc', 'bac', 'bca', 'acb', 'cab', 'cba']",
"assert permute_string('abcd')==['abcd', 'bacd', 'bcad', 'bcda', 'acbd', 'cabd', 'cbad', 'cbda', 'acdb', 'cadb', 'cdab', 'cdba', 'abdc', 'badc', 'bdac', 'bdca', 'adbc', 'dabc', 'dbac', 'dbca'... | [] | [
"Here is a Python function that prints all permutations of a given string including duplicates:\n\n```python\ndef permute_string(str):\n if len(str) == 1:\n print(str)\n else:\n for i in range(len(str)):\n char = str[i]\n remaining = str[:i] + str[i+1:]\n for per... | [
0
] | |
375 | Write a function to round the given number to the nearest multiple of a specific number. | def round_num(n,m):
a = (n //m) * m
b = a + m
return (b if n - a > b - n else a) | [
"assert round_num(4722,10)==4720",
"assert round_num(1111,5)==1110",
"assert round_num(219,2)==218"
] | [] | [
"Here is a Python function that rounds a given number to the nearest multiple of a specific number:\n\n```python\ndef round_num(n, m):\n \"\"\"\n Write a function to round the given number to the nearest multiple of a specific number.\n \"\"\"\n return round(n / m) * m\n```\n\nThis function works by fir... | [
0
] | |
376 | Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value. | def remove_replica(test_tup):
temp = set()
res = tuple(ele if ele not in temp and not temp.add(ele)
else 'MSP' for ele in test_tup)
return (res) | [
"assert remove_replica((1, 1, 4, 4, 4, 5, 5, 6, 7, 7)) == (1, 'MSP', 4, 'MSP', 'MSP', 5, 'MSP', 6, 7, 'MSP')",
"assert remove_replica((2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9)) == (2, 3, 4, 'MSP', 5, 6, 'MSP', 7, 8, 9, 'MSP')",
"assert remove_replica((2, 2, 5, 4, 5, 7, 5, 6, 7, 7)) == (2, 'MSP', 5, 4, 'MSP', 7, 'MSP', ... | [] | [
"Here is a Python function that removes tuple elements that occur more than once and replaces the duplicates with some custom value:\n\n```python\ndef remove_replica(test_tup, custom_value):\n # Convert the tuple to a set to remove duplicates\n unique_set = set(test_tup)\n \n # Convert the set back to a... | [
0
] | |
377 | Write a python function to remove all occurrences of a character in a given string. | def remove_Char(s,c) :
counts = s.count(c)
s = list(s)
while counts :
s.remove(c)
counts -= 1
s = '' . join(s)
return (s) | [
"assert remove_Char(\"aba\",'a') == \"b\"",
"assert remove_Char(\"toggle\",'g') == \"tole\"",
"assert remove_Char(\"aabbc\",'b') == \"aac\""
] | [] | [
"Here is the Python function to remove all occurrences of a character in a given string:\n\n```python\ndef remove_Char(s,c):\n return s.replace(c, '')\n```\n\nThis function uses the `replace()` method of Python strings to replace all occurrences of the character `c` with an empty string, effectively removing the... | [
1
] | |
378 | Write a python function to shift last element to first position in the given list. | def move_first(test_list):
test_list = test_list[-1:] + test_list[:-1]
return test_list | [
"assert move_first([1,2,3,4]) == [4,1,2,3]",
"assert move_first([0,1,2,3]) == [3,0,1,2]",
"assert move_first([9,8,7,1]) == [1,9,8,7]"
] | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef move_first(test_list):\n \"\"\"\n Write a python function to shift last element to first position in the given list.\n \"\"\"\n if len(test_list) == 0:\n return test_list\n else:\n last_element = test_list.pop()\n ... | [
1
] | |
379 | Write a function to find the surface area of a cuboid. | def surfacearea_cuboid(l,w,h):
SA = 2*(l*w + l * h + w * h)
return SA | [
"assert surfacearea_cuboid(1,2,3)==22",
"assert surfacearea_cuboid(5,7,9)==286",
"assert surfacearea_cuboid(10,15,21)==1350"
] | [] | [
"Sure, here is the Python function to calculate the surface area of a cuboid:\n\n```python\ndef surfacearea_cuboid(l, w, h):\n \"\"\"\n Write a function to find the surface area of a cuboid.\n \"\"\"\n return 2 * (l * w + w * h + h * l)\n```\n\nThis function takes three arguments: `l` (length), `w` (wid... | [
1
] | |
380 | Write a function to generate a two-dimensional array. | def multi_list(rownum,colnum):
multi_list = [[0 for col in range(colnum)] for row in range(rownum)]
for row in range(rownum):
for col in range(colnum):
multi_list[row][col]= row*col
return multi_list
| [
"assert multi_list(3,4)==[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]] ",
"assert multi_list(5,7)==[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 2, 4, 6, 8, 10, 12], [0, 3, 6, 9, 12, 15, 18], [0, 4, 8, 12, 16, 20, 24]]",
"assert multi_list(10,15)==[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4... | [] | [
"Sure, here is a Python function that generates a two-dimensional array with the specified number of rows and columns:\n\n```python\ndef multi_list(rownum, colnum):\n \"\"\"\n Write a function to generate a two-dimensional array.\n \"\"\"\n return [[0 for _ in range(colnum)] for _ in range(rownum)]\n```... | [
0
] | |
381 | Write a function to sort a list of lists by a given index of the inner list. | from operator import itemgetter
def index_on_inner_list(list_data, index_no):
result = sorted(list_data, key=itemgetter(index_no))
return result | [
"assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]",
"assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent... | [] | [
"Here is the solution to the problem:\n\n```python\ndef index_on_inner_list(list_data, index_no):\n \"\"\"\n Write a function to sort a list of lists by a given index of the inner list.\n \"\"\"\n return sorted(list_data, key=lambda x: x[index_no])\n```\n\nThis function takes a list of lists (`list_data... | [
1
] | |
382 | Write a function to find the number of rotations in a circularly sorted array. | def find_rotation_count(A):
(left, right) = (0, len(A) - 1)
while left <= right:
if A[left] <= A[right]:
return left
mid = (left + right) // 2
next = (mid + 1) % len(A)
prev = (mid - 1 + len(A)) % len(A)
if A[mid] <= A[next] and A[mid] <= A[prev]:
... | [
"assert find_rotation_count([8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 3",
"assert find_rotation_count([8, 9, 10,2, 5, 6]) == 3",
"assert find_rotation_count([2, 5, 6, 8, 9, 10]) == 0"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef find_rotation_count(A):\n \"\"\"\n Write a function to find the number of rotations in a circularly sorted array.\n \"\"\"\n low = 0\n high = len(A) - 1\n\n while low <= high:\n mid = (low + high) // 2\n\n # If the middle ... | [
1
] | |
383 | Write a python function to toggle all odd bits of a given number. | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while(temp > 0 ) :
if (count % 2 == 0) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | [
"assert even_bit_toggle_number(10) == 15",
"assert even_bit_toggle_number(20) == 1",
"assert even_bit_toggle_number(30) == 11"
] | [] | [
"Here is the Python function to toggle all odd bits of a given number:\n\n```python\ndef even_bit_toggle_number(n):\n # Initialize the result to 0\n result = 0\n \n # Iterate over each bit of the number\n for i in range(32):\n # Check if the current bit is odd\n if i % 2 != 0:\n ... | [
0
] | |
384 | Write a python function to find the frequency of the smallest value in a given array. | def frequency_Of_Smallest(n,arr):
mn = arr[0]
freq = 1
for i in range(1,n):
if (arr[i] < mn):
mn = arr[i]
freq = 1
elif (arr[i] == mn):
freq += 1
return freq | [
"assert frequency_Of_Smallest(5,[1,2,3,4,3]) == 1",
"assert frequency_Of_Smallest(7,[3,1,2,5,6,2,3]) == 1",
"assert frequency_Of_Smallest(7,[3,3,6,3,7,4,9]) == 3"
] | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef frequency_Of_Smallest(n,arr):\n \"\"\"\n Write a python function to find the frequency of the smallest value in a given array.\n \"\"\"\n if n <= 0:\n return \"Invalid input\"\n \n min_val = arr[0]\n for i in range(1, n... | [
1
] | |
385 | Write a function to find the n'th perrin number using recursion. | def get_perrin(n):
if (n == 0):
return 3
if (n == 1):
return 0
if (n == 2):
return 2
return get_perrin(n - 2) + get_perrin(n - 3) | [
"assert get_perrin(9) == 12",
"assert get_perrin(4) == 2",
"assert get_perrin(6) == 5"
] | [] | [
"Sure, here is the Python function to find the n'th Perrin number using recursion:\n\n```python\ndef get_perrin(n):\n if n == 0:\n return 3\n elif n == 1:\n return 0\n elif n == 2:\n return 2\n else:\n return get_perrin(n-2) + get_perrin(n-3)\n```\n\nThis function works by ch... | [
1
] | |
386 | Write a function to find out the minimum no of swaps required for bracket balancing in the given string. | def swap_count(s):
chars = s
count_left = 0
count_right = 0
swap = 0
imbalance = 0;
for i in range(len(chars)):
if chars[i] == '[':
count_left += 1
if imbalance > 0:
swap += imbalance
imbalance -= 1
elif chars[i] == ']':
count_right += 1
imbalance = (count_right - count_left... | [
"assert swap_count(\"[]][][\") == 2",
"assert swap_count(\"[[][]]\") == 0",
"assert swap_count(\"[[][]]][\") == 1"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef swap_count(s):\n balance = 0\n swaps = 0\n for char in s:\n if char == '(':\n balance += 1\n else:\n balance -= 1\n if balance < 0:\n swaps += 1\n balance = 0\n... | [
0
] | |
387 | Write a python function to check whether the hexadecimal number is even or odd. | def even_or_odd(N):
l = len(N)
if (N[l-1] =='0'or N[l-1] =='2'or
N[l-1] =='4'or N[l-1] =='6'or
N[l-1] =='8'or N[l-1] =='A'or
N[l-1] =='C'or N[l-1] =='E'):
return ("Even")
else:
return ("Odd") | [
"assert even_or_odd(\"AB3454D\") ==\"Odd\"",
"assert even_or_odd(\"ABC\") == \"Even\"",
"assert even_or_odd(\"AAD\") == \"Odd\""
] | [] | [
"Here is the Python function to check whether a hexadecimal number is even or odd:\n\n```python\ndef even_or_odd(N):\n \"\"\"\n Write a python function to check whether the hexadecimal number is even or odd.\n \"\"\"\n # Convert the hexadecimal number to decimal\n decimal = int(N, 16)\n \n # Ch... | [
0
] | |
388 | Write a python function to find the highest power of 2 that is less than or equal to n. | def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res; | [
"assert highest_Power_of_2(10) == 8",
"assert highest_Power_of_2(19) == 16",
"assert highest_Power_of_2(32) == 32"
] | [] | [
"Here is the Python function to find the highest power of 2 that is less than or equal to n:\n\n```python\ndef highest_Power_of_2(n):\n \"\"\"\n Write a python function to find the highest power of 2 that is less than or equal to n.\n \"\"\"\n if n == 0:\n return 0\n power = 1\n while power... | [
1
] | |
389 | Write a function to find the n'th lucas number. | def find_lucas(n):
if (n == 0):
return 2
if (n == 1):
return 1
return find_lucas(n - 1) + find_lucas(n - 2) | [
"assert find_lucas(9) == 76",
"assert find_lucas(4) == 7",
"assert find_lucas(3) == 4"
] | [] | [
"Sure, here is a Python function to find the n'th Lucas number:\n\n```python\ndef find_lucas(n):\n if n == 0:\n return 2\n elif n == 1:\n return 1\n else:\n return find_lucas(n-1) + find_lucas(n-2)\n```\n\nThis function uses recursion to calculate the Lucas number. The Lucas numbers ar... | [
1
] | |
390 | Write a function to insert a given string at the beginning of all items in a list. | def add_string(list,string):
add_string=[string.format(i) for i in list]
return add_string | [
"assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']",
"assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']",
"assert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']"
] | [] | [
"Here is the Python function to solve the problem:\n\n```python\ndef add_string(list,string):\n \"\"\"\n Write a function to insert a given string at the beginning of all items in a list.\n \"\"\"\n return [string + item for item in list]\n```\n\nThis function takes a list and a string as input. It then... | [
0
] | |
391 | Write a function to convert more than one list to nested dictionary. | def convert_list_dictionary(l1, l2, l3):
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
return result | [
"assert convert_list_dictionary([\"S001\", \"S002\", \"S003\", \"S004\"],[\"Adina Park\", \"Leyton Marsh\", \"Duncan Boyle\", \"Saim Richards\"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]",
"assert convert_lis... | [] | [
"Here is a Python function that converts more than one list to a nested dictionary:\n\n```python\ndef convert_list_dictionary(l1, l2, l3):\n \"\"\"\n Write a function to convert more than one list to nested dictionary.\n \"\"\"\n nested_dict = {}\n for i in range(len(l1)):\n nested_dict[l1[i]]... | [
0
] | |
392 | Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n). | def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.append(max(i, (res[int(i / 2)]
+ res[int(i / 3)] +
res[int(i / 4)]
+ res[int(i / 5)])))
i = i + 1
return res[n] | [
"assert get_max_sum(60) == 106",
"assert get_max_sum(10) == 12",
"assert get_max_sum(2) == 2"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef get_max_sum(n):\n if n == 1:\n return 1\n else:\n return max(get_max_sum(n//2) + get_max_sum(n//3) + get_max_sum(n//4) + get_max_sum(n//5), n)\n```\n\nThis function uses recursion to calculate the maximum sum possible by using the giv... | [
0
] | |
393 | Write a function to find the list with maximum length using lambda function. | def max_length_list(input_list):
max_length = max(len(x) for x in input_list )
max_list = max(input_list, key = lambda i: len(i))
return(max_length, max_list) | [
"assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])",
"assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])",
"assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef max_length_list(input_list):\n \"\"\"\n Write a function to find the list with maximum length using lambda function.\n \"\"\"\n return max(input_list, key=lambda x: len(x))\n```\n\nThis function takes a list as input and returns the list with the m... | [
0
] | |
394 | Write a function to check if given tuple is distinct or not. | def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return (res) | [
"assert check_distinct((1, 4, 5, 6, 1, 4)) == False",
"assert check_distinct((1, 4, 5, 6)) == True",
"assert check_distinct((2, 3, 4, 5, 6)) == True"
] | [] | [
"Here is a Python function that checks if a given tuple is distinct or not:\n\n```python\ndef check_distinct(test_tup):\n return len(set(test_tup)) == len(test_tup)\n```\n\nThis function works by converting the tuple to a set, which automatically removes any duplicate elements. Then it compares the length of the... | [
1
] | |
395 | Write a python function to find the first non-repeated character in a given string. | def first_non_repeating_character(str1):
char_order = []
ctr = {}
for c in str1:
if c in ctr:
ctr[c] += 1
else:
ctr[c] = 1
char_order.append(c)
for c in char_order:
if ctr[c] == 1:
return c
return None | [
"assert first_non_repeating_character(\"abcabc\") == None",
"assert first_non_repeating_character(\"abc\") == \"a\"",
"assert first_non_repeating_character(\"ababc\") == \"c\""
] | [] | [
"Here is the Python function to find the first non-repeated character in a given string:\n\n```python\ndef first_non_repeating_character(str1):\n char_count = {}\n for char in str1:\n if char in char_count:\n char_count[char] += 1\n else:\n char_count[char] = 1\n \n f... | [
1
] | |
396 | Write a function to check whether the given string starts and ends with the same character or not using regex. | import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
if(re.search(regex, string)):
return "Valid"
else:
return "Invalid" | [
"assert check_char(\"abba\") == \"Valid\"",
"assert check_char(\"a\") == \"Valid\"",
"assert check_char(\"abcd\") == \"Invalid\""
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\nimport re\n\ndef check_char(string):\n \"\"\"\n Write a function to check whether the given string starts and ends with the same character or not using regex.\n \"\"\"\n pattern = r'^[a-zA-Z]$'\n if re.match(pattern, string):\n retur... | [
0
] | |
397 | Write a function to find the median of three specific numbers. | def median_numbers(a,b,c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
return median | [
"assert median_numbers(25,55,65)==55.0",
"assert median_numbers(20,10,30)==20.0",
"assert median_numbers(15,45,75)==45.0"
] | [] | [
"Here is the Python function to find the median of three specific numbers:\n\n```python\ndef median_numbers(a, b, c):\n \"\"\"\n Write a function to find the median of three specific numbers.\n \"\"\"\n numbers = [a, b, c]\n numbers.sort()\n return numbers[1]\n```\n\nThis function first creates a ... | [
1
] | |
398 | Write a function to compute the sum of digits of each number of a given list. | def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit()) | [
"assert sum_of_digits([10,2,56])==14",
"assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19",
"assert sum_of_digits([10,20,-4,5,-70])==19"
] | [] | [
"Here is the Python code to solve the problem:\n\n```python\ndef sum_of_digits(nums):\n \"\"\"\n Write a function to compute the sum of digits of each number of a given list.\n \"\"\"\n return [sum(int(digit) for digit in str(num)) for num in nums]\n```\n\nThis function takes a list of numbers as input ... | [
0
] | |
399 | Write a function to perform the mathematical bitwise xor operation across the given tuples. | def bitwise_xor(test_tup1, test_tup2):
res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [
"assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)",
"assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)",
"assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)"
] | [] | [
"Here is the solution to the problem:\n\n```python\ndef bitwise_xor(test_tup1, test_tup2):\n \"\"\"\n Write a function to perform the mathematical bitwise xor operation across the given tuples.\n \"\"\"\n return tuple(a ^ b for a, b in zip(test_tup1, test_tup2))\n```\n\nThis function takes two tuples as... | [
1
] | |
400 | Write a function to extract the frequency of unique tuples in the given list order irrespective. | def extract_freq(test_list):
res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
return (res) | [
"assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3",
"assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4",
"assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef extract_freq(test_list):\n # Convert the list of tuples to a set to remove duplicates\n unique_tuples = set(test_list)\n \n # Create a dictionary to store the frequency of each unique tuple\n freq_dict = {}\n \n # Iterate over the un... | [
0
] | |
401 | Write a function to perform index wise addition of tuple elements in the given two nested tuples. | def add_nested_tuples(test_tup1, test_tup2):
res = tuple(tuple(a + b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [
"assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))",
"assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15))",
"assert add_nested_tuples(((3, 5), ... | [] | [
"Here is the solution to the problem:\n\n```python\ndef add_nested_tuples(test_tup1, test_tup2):\n \"\"\"\n Write a function to perform index wise addition of tuple elements in the given two nested tuples.\n \"\"\"\n result = ()\n for i in range(len(test_tup1)):\n result += (test_tup1[i] + tes... | [
0
] | |
402 | Write a function to compute the value of ncr%p. | def ncr_modp(n, r, p):
C = [0 for i in range(r+1)]
C[0] = 1
for i in range(1, n+1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j-1]) % p
return C[r] | [
"assert ncr_modp(10,2,13)==6",
"assert ncr_modp(15,12,43)==25",
"assert ncr_modp(17,9,18)==10"
] | [] | [
"Sure, here is a Python function to compute the value of ncr%p:\n\n```python\ndef ncr_modp(n, r, p):\n \"\"\"\n Write a function to compute the value of ncr%p.\n \"\"\"\n if r > n:\n return 0\n if r == 0 or r == n:\n return 1\n if r == 1:\n return n\n if r == 2:\n re... | [
0
] | |
403 | Write a function to check if a url is valid or not using regex. | import re
def is_valid_URL(str):
regex = ("((http|https)://)(www.)?" +
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
"{2,256}\\.[a-z]" +
"{2,6}\\b([-a-zA-Z0-9@:%" +
"._\\+~#?&//=]*)")
p = re.compile(regex)
if (str == None):
return False
if(re.search(p, str)):
return True
else:
return False | [
"assert is_valid_URL(\"https://www.google.com\") == True",
"assert is_valid_URL(\"https:/www.gmail.com\") == False",
"assert is_valid_URL(\"https:// www.redit.com\") == False"
] | [] | [
"Sure, here is a Python function that uses regular expressions to check if a URL is valid or not:\n\n```python\nimport re\n\ndef is_valid_URL(str):\n pattern = r'^(https?:\\/\\/)?(www\\.)?[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$'\n if re.match(pattern, str):\n return True\n else:\n return False\n```\n\... | [
1
] | |
404 | Write a python function to find the minimum of two numbers. | def minimum(a,b):
if a <= b:
return a
else:
return b | [
"assert minimum(1,2) == 1",
"assert minimum(-5,-4) == -5",
"assert minimum(0,0) == 0"
] | [] | [
"Sure, here is the Python function to find the minimum of two numbers:\n\n```python\ndef minimum(a, b):\n \"\"\"\n Write a python function to find the minimum of two numbers.\n \"\"\"\n return min(a, b)\n```\n\nYou can use this function by passing two numbers as arguments, like this:\n\n```python\nprint... | [
0
] | |
405 | Write a function to check whether an element exists within a tuple. | def check_tuplex(tuplex,tuple1):
if tuple1 in tuplex:
return True
else:
return False | [
"assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'r')==True",
"assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'5')==False",
"assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\",\"e\"),3)==True"
] | [] | [
"Here is the Python function to check whether an element exists within a tuple:\n\n```python\ndef check_tuplex(tuplex, tuple1):\n \"\"\"\n Write a function to check whether an element exists within a tuple.\n \"\"\"\n if tuple1 in tuplex:\n return True\n else:\n return False\n```\n\nYou... | [
0
] | |
406 | Write a python function to find the parity of a given number. | def find_Parity(x):
y = x ^ (x >> 1);
y = y ^ (y >> 2);
y = y ^ (y >> 4);
y = y ^ (y >> 8);
y = y ^ (y >> 16);
if (y & 1):
return ("Odd Parity");
return ("Even Parity"); | [
"assert find_Parity(12) == \"Even Parity\"",
"assert find_Parity(7) == \"Odd Parity\"",
"assert find_Parity(10) == \"Even Parity\""
] | [] | [
"Sure, here is the Python function to find the parity of a given number:\n\n```python\ndef find_Parity(x):\n \"\"\"\n Write a python function to find the parity of a given number.\n \"\"\"\n return x % 2\n```\n\nThis function takes an integer `x` as input and returns the parity of `x`. The parity of a n... | [
0
] | |
407 | Write a function to create the next bigger number by rearranging the digits of a given number. | def rearrange_bigger(n):
nums = list(str(n))
for i in range(len(nums)-2,-1,-1):
if nums[i] < nums[i+1]:
z = nums[i:]
y = min(filter(lambda x: x > z[0], z))
z.remove(y)
z.sort()
nums[i:] = [y] + z
return int("".join(nums))
... | [
"assert rearrange_bigger(12)==21",
"assert rearrange_bigger(10)==False",
"assert rearrange_bigger(102)==120"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef rearrange_bigger(n):\n # Convert the number to a list of digits\n digits = list(str(n))\n \n # Find the first digit from the right that is smaller than the digit immediately to its right\n i = len(digits) - 2\n while i >= 0 and ... | [
0
] | |
408 | 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. | import heapq
def k_smallest_pairs(nums1, nums2, k):
queue = []
def push(i, j):
if i < len(nums1) and j < len(nums2):
heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
push(0, 0)
pairs = []
while queue and len(pairs) < k:
_, i, j = heapq.heappop(queue)
pairs.appe... | [
"assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]"
] | [] | [
"Here is a Python function that solves the problem:\n\n```python\ndef k_smallest_pairs(nums1, nums2, k):\n # Initialize a min-heap with the first element of each array\n heap = [(nums1[0], nums2[0], 0, 0)]\n result = []\n \n # While the heap is not empty and we have not found k pairs\n while heap ... | [
0
] | |
409 | Write a function to find the minimum product from the pairs of tuples within a given list. | def min_product_tuple(list1):
result_min = min([abs(x * y) for x, y in list1] )
return result_min | [
"assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8",
"assert min_product_tuple([(10,20), (15,2), (5,10)] )==30",
"assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100"
] | [] | [
"Here is a Python solution for the problem:\n\n```python\ndef min_product_tuple(list1):\n # Initialize the minimum product to a large number\n min_product = float('inf')\n \n # Iterate over each tuple in the list\n for tup in list1:\n # Calculate the product of the two numbers in the tuple\n ... | [
1
] | |
410 | Write a function to find the minimum value in a given heterogeneous list. | def min_val(listval):
min_val = min(i for i in listval if isinstance(i, int))
return min_val | [
"assert min_val(['Python', 3, 2, 4, 5, 'version'])==2",
"assert min_val(['Python', 15, 20, 25])==15",
"assert min_val(['Python', 30, 20, 40, 50, 'version'])==20"
] | [] | [
"Here is a Python function that finds the minimum value in a heterogeneous list:\n\n```python\ndef min_val(listval):\n \"\"\"\n Write a function to find the minimum value in a given heterogeneous list.\n \"\"\"\n if not listval:\n return None\n min_val = listval[0]\n for val in listval:\n ... | [
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.