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
111
Write a function to find common elements in given nested lists. * list item * list item * list item * list item
def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result
[ "assert common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]])==[18, 12]", "assert common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]])==[5,23]", "assert common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]])==[4]" ]
[]
[ "Here is a Python function that finds common elements in given nested lists:\n\n```python\ndef common_in_nested_lists(nestedlist):\n # Initialize an empty set to store common elements\n common_elements = set()\n \n # Iterate over each sublist in the nested list\n for sublist in nestedlist:\n #...
[ 0 ]
112
Write a python function to find the perimeter of a cylinder.
def perimeter(diameter,height) : return 2*(diameter+height)
[ "assert perimeter(2,4) == 12", "assert perimeter(1,2) == 6", "assert perimeter(3,1) == 8" ]
[]
[ "Sure, here is the Python function to find the perimeter of a cylinder:\n\n```python\ndef perimeter(diameter, height):\n \"\"\"\n Write a python function to find the perimeter of a cylinder.\n \"\"\"\n return 2 * 3.14159 * diameter + 2 * 3.14159 * height\n```\n\nThis function takes two parameters: `diam...
[ 0 ]
113
Write a function to check if a string represents an integer or not.
def check_integer(text): text = text.strip() if len(text) < 1: return None else: if all(text[i] in "0123456789" for i in range(len(text))): return True elif (text[0] in "+-") and \ all(text[i] in "0123456789" for i in range(1,len(text))): return True else: ...
[ "assert check_integer(\"python\")==False", "assert check_integer(\"1\")==True", "assert check_integer(\"12345\")==True" ]
[]
[ "Here is the Python function to check if a string represents an integer or not:\n\n```python\ndef check_integer(text):\n try:\n int(text)\n return True\n except ValueError:\n return False\n```\n\nThis function uses the built-in `int()` function to try to convert the input string to an int...
[ 1 ]
114
Write a function to assign frequency to each tuple in the given tuple list.
from collections import Counter def assign_freq(test_list): res = [(*key, val) for key, val in Counter(test_list).items()] return (str(res))
[ "assert assign_freq([(6, 5, 8), (2, 7), (6, 5, 8), (6, 5, 8), (9, ), (2, 7)] ) == '[(6, 5, 8, 3), (2, 7, 2), (9, 1)]'", "assert assign_freq([(4, 2, 4), (7, 1), (4, 8), (4, 2, 4), (9, 2), (7, 1)] ) == '[(4, 2, 4, 2), (7, 1, 2), (4, 8, 1), (9, 2, 1)]'", "assert assign_freq([(11, 13, 10), (17, 21), (4, 2, 3), (17,...
[]
[ "Here is a Python solution for the problem:\n\n```python\ndef assign_freq(test_list):\n freq_dict = {}\n for item in test_list:\n if item in freq_dict:\n freq_dict[item] += 1\n else:\n freq_dict[item] = 1\n return freq_dict\n```\n\nThis function takes a tuple list as inp...
[ 0 ]
115
Write a function to check whether all dictionaries in a list are empty or not.
def empty_dit(list1): empty_dit=all(not d for d in list1) return empty_dit
[ "assert empty_dit([{},{},{}])==True", "assert empty_dit([{1,2},{},{}])==False", "assert empty_dit({})==True" ]
[]
[ "Here is the solution to the problem:\n\n```python\ndef empty_dit(list1):\n \"\"\"\n Write a function to check whether all dictionaries in a list are empty or not.\n \"\"\"\n return all(not d for d in list1)\n```\n\nThis function uses the built-in `all()` function in Python, which returns `True` if all ...
[ 1 ]
116
Write a function to convert a given tuple of positive integers into an integer.
def tuple_to_int(nums): result = int(''.join(map(str,nums))) return result
[ "assert tuple_to_int((1,2,3))==123", "assert tuple_to_int((4,5,6))==456", "assert tuple_to_int((5,6,7))==567" ]
[]
[ "Here is the Python function to convert a given tuple of positive integers into an integer:\n\n```python\ndef tuple_to_int(nums):\n \"\"\"\n Write a function to convert a given tuple of positive integers into an integer.\n \"\"\"\n return int(''.join(map(str, nums)))\n```\n\nThis function works by first...
[ 1 ]
117
Write a function to convert all possible convertible elements in the list to float.
def list_to_float(test_list): res = [] for tup in test_list: temp = [] for ele in tup: if ele.isalpha(): temp.append(ele) else: temp.append(float(ele)) res.append((temp[0],temp[1])) return (str(res))
[ "assert list_to_float( [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ) == '[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]'", "assert list_to_float( [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ) == '[(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]'", "a...
[]
[ "Here is the Python function to convert all possible convertible elements in the list to float:\n\n```python\ndef list_to_float(test_list):\n return [float(x) for x in test_list if isinstance(x, (int, float))]\n```\n\nThis function uses a list comprehension to iterate over each element in the input list. It chec...
[ 0 ]
118
[link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list.
def string_to_list(string): lst = list(string.split(" ")) return lst
[ "assert string_to_list(\"python programming\")==['python','programming']", "assert string_to_list(\"lists tuples strings\")==['lists','tuples','strings']", "assert string_to_list(\"write a program\")==['write','a','program']" ]
[]
[ "Here is the Python function to convert a string to a list:\n\n```python\ndef string_to_list(string):\n \"\"\"\n Convert a string to a list.\n \"\"\"\n return list(string)\n```\n\nThis function takes a string as input and returns a list of characters in the string." ]
[ 0 ]
119
Write a python function to find the element that appears only once in a sorted array.
def search(arr,n) : XOR = 0 for i in range(n) : XOR = XOR ^ arr[i] return (XOR)
[ "assert search([1,1,2,2,3],5) == 3", "assert search([1,1,3,3,4,4,5,5,7,7,8],11) == 8", "assert search([1,2,2,3,3,4,4],7) == 1" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef search(arr,n):\n \"\"\"\n Write a python function to find the element that appears only once in a sorted array.\n \"\"\"\n low = 0\n high = n-1\n\n while low <= high:\n mid = (low + high) // 2\n\n # If mid is even,...
[ 0 ]
120
Write a function to find the maximum product from the pairs of tuples within a given list.
def max_product_tuple(list1): result_max = max([abs(x * y) for x, y in list1] ) return result_max
[ "assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36", "assert max_product_tuple([(10,20), (15,2), (5,10)] )==200", "assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484" ]
[]
[ "Here is a Python solution for the problem:\n\n```python\ndef max_product_tuple(list1):\n # Initialize the maximum product to a very small number\n max_product = float('-inf')\n \n # Iterate through each tuple in the list\n for tuple1 in list1:\n # Iterate through each element in the tuple\n ...
[ 0 ]
121
Write a function to find the triplet with sum of the given array
def check_triplet(A, n, sum, count): if count == 3 and sum == 0: return True if count == 3 or n == 0 or sum < 0: return False return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\ check_triplet(A, n - 1, sum, count)
[ "assert check_triplet([2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0) == True", "assert check_triplet([1, 4, 5, 6, 7, 8, 5, 9], 8, 6, 0) == False", "assert check_triplet([10, 4, 2, 3, 5], 5, 15, 0) == True" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef check_triplet(A, n, sum, count):\n A.sort() # Sort the array in ascending order\n for i in range(n-2):\n left = i + 1\n right = n - 1\n while left < right:\n current_sum = A[i] + A[left] + A[right]\n ...
[ 0 ]
122
Write a function to find n’th smart number.
MAX = 3000 def smartNumber(n): primes = [0] * MAX result = [] for i in range(2, MAX): if (primes[i] == 0): primes[i] = 1 j = i * 2 while (j < MAX): primes[j] -= 1 if ( (primes[j] + 3) == 0): result.append(j) j = j + i result.sort() return result[n - 1]
[ "assert smartNumber(1) == 30", "assert smartNumber(50) == 273", "assert smartNumber(1000) == 2664" ]
[]
[ "Sure, I can help you solve the problem of finding the nth smart number using Python. A smart number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself). Here's a step-by-step approach to solve this problem:\n\n1. **Define the function**: We need to define a function ...
[ 0 ]
123
Write a function to sum all amicable numbers from 1 to a specified number.
def amicable_numbers_sum(limit): if not isinstance(limit, int): return "Input is not an integer!" if limit < 1: return "Input must be bigger than 0!" amicables = set() for num in range(2, limit+1): if num in amicables: continue sum_fact = sum([fact fo...
[ "assert amicable_numbers_sum(999)==504", "assert amicable_numbers_sum(9999)==31626", "assert amicable_numbers_sum(99)==0" ]
[]
[ "Sure, here is a Python function that calculates the sum of all amicable numbers up to a given limit:\n\n```python\ndef amicable_numbers_sum(limit):\n def sum_of_divisors(n):\n \"\"\"Calculate the sum of all divisors of a number.\"\"\"\n return sum([i for i in range(1, n) if n % i == 0])\n\n ami...
[ 0 ]
124
Write a function to get the angle of a complex number.
import cmath def angle_complex(a,b): cn=complex(a,b) angle=cmath.phase(a+b) return angle
[ "assert angle_complex(0,1j)==1.5707963267948966 ", "assert angle_complex(2,1j)==0.4636476090008061", "assert angle_complex(0,2j)==1.5707963267948966" ]
[]
[ "Sure, here is a Python function that calculates the angle of a complex number:\n\n```python\nimport cmath\n\ndef angle_complex(a, b):\n \"\"\"\n Write a function to get the angle of a complex number.\n \"\"\"\n return cmath.phase(a + b)\n```\n\nThis function uses the `cmath.phase()` function to calcula...
[ 1 ]
125
Write 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.
def find_length(string, n): current_sum = 0 max_sum = 0 for i in range(n): current_sum += (1 if string[i] == '0' else -1) if current_sum < 0: current_sum = 0 max_sum = max(current_sum, max_sum) return max_sum if max_sum else 0
[ "assert find_length(\"11000010001\", 11) == 6", "assert find_length(\"10111\", 5) == 1", "assert find_length(\"11011101100101\", 14) == 2 " ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef find_length(string, n):\n max_diff = 0\n count_0 = 0\n count_1 = 0\n for i in range(n):\n if string[i] == '0':\n count_0 += 1\n else:\n count_1 += 1\n max_diff = max(max_diff, count_0 - count...
[ 0 ]
126
Write a python function to find the sum of common divisors of two given numbers.
def sum(a,b): sum = 0 for i in range (1,min(a,b)): if (a % i == 0 and b % i == 0): sum += i return sum
[ "assert sum(10,15) == 6", "assert sum(100,150) == 93", "assert sum(4,6) == 3" ]
[]
[ "Here is the Python function to find the sum of common divisors of two given numbers:\n\n```python\ndef sum(a,b):\n \"\"\"\n Write a python function to find the sum of common divisors of two given numbers.\n \"\"\"\n sum = 0\n for i in range(1, min(a, b) + 1):\n if a % i == 0 and b % i == 0:\n...
[ 1 ]
127
Write a function to multiply two integers without using the * operator in python.
def multiply_int(x, y): if y < 0: return -multiply_int(x, -y) elif y == 0: return 0 elif y == 1: return x else: return x + multiply_int(x, y - 1)
[ "assert multiply_int(10,20)==200", "assert multiply_int(5,10)==50", "assert multiply_int(4,8)==32" ]
[]
[ "Here is the Python function to multiply two integers without using the * operator:\n\n```python\ndef multiply_int(x, y):\n result = 0\n for _ in range(y):\n result += x\n return result\n```\n\nThis function works by adding the integer `x` to itself `y` times. The result is then returned." ]
[ 1 ]
128
Write a function to shortlist words that are longer than n from a given list of words.
def long_words(n, str): word_len = [] txt = str.split(" ") for x in txt: if len(x) > n: word_len.append(x) return word_len
[ "assert long_words(3,\"python is a programming language\")==['python','programming','language']", "assert long_words(2,\"writing a program\")==['writing','program']", "assert long_words(5,\"sorting list\")==['sorting']" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef long_words(n, str):\n \"\"\"\n Write a function to shortlist words that are longer than n from a given list of words.\n \"\"\"\n return [word for word in str.split() if len(word) > n]\n```\n\nThis function takes two parameters: `n` (an...
[ 1 ]
129
Write a function to calculate magic square.
def magic_square_test(my_matrix): iSize = len(my_matrix[0]) sum_list = [] sum_list.extend([sum (lines) for lines in my_matrix]) for col in range(iSize): sum_list.append(sum(row[col] for row in my_matrix)) result1 = 0 for i in range(0,iSize): result1 +=my_matrix[i][i] ...
[ "assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True", "assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True", "assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False" ]
[]
[ "Sure, I can help you solve the problem of calculating a magic square in Python. A magic square is a square grid filled with distinct positive integers such that the sum of the numbers in each row, each column, and both main diagonals are the same.\n\nHere's a Python function to calculate a magic square:\n\n```pyth...
[ 0 ]
130
Write a function to find the item with maximum frequency in a given list.
from collections import defaultdict def max_occurrences(nums): dict = defaultdict(int) for i in nums: dict[i] += 1 result = max(dict.items(), key=lambda x: x[1]) return result
[ "assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==(2, 5)", "assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18])==(8, 2)", "assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==(20, 3)" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef max_occurrences(nums):\n # Create a dictionary to store the frequency of each item\n freq_dict = {}\n \n # Iterate over the list and update the frequency dictionary\n for num in nums:\n if num in freq_dict:\n freq...
[ 0 ]
131
Write a python function to reverse only the vowels of a given string.
def reverse_vowels(str1): vowels = "" for char in str1: if char in "aeiouAEIOU": vowels += char result_string = "" for char in str1: if char in "aeiouAEIOU": result_string += vowels[-1] vowels = vowels[:-1] else: result_string += char return result_string
[ "assert reverse_vowels(\"Python\") == \"Python\"", "assert reverse_vowels(\"USA\") == \"ASU\"", "assert reverse_vowels(\"ab\") == \"ab\"" ]
[]
[ "Here is the Python function to reverse only the vowels of a given string:\n\n```python\ndef reverse_vowels(str1):\n vowels = 'aeiouAEIOU'\n str1 = list(str1)\n left, right = 0, len(str1) - 1\n \n while left < right:\n if str1[left] not in vowels:\n left += 1\n elif str1[righ...
[ 1 ]
132
Write a function to convert tuple to a string.
def tup_string(tup1): str = ''.join(tup1) return str
[ "assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")", "assert tup_string(('p','y','t','h','o','n'))==(\"python\")", "assert tup_string(('p','r','o','g','r','a','m'))==(\"program\")" ]
[]
[ "Here is the Python function to convert a tuple to a string:\n\n```python\ndef tup_string(tup1):\n \"\"\"\n Write a function to convert tuple to a string.\n \"\"\"\n return ''.join(map(str, tup1))\n```\n\nThis function uses the `join()` method to concatenate the elements of the tuple into a single strin...
[ 1 ]
133
Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.
def sum_negativenum(nums): sum_negativenum = list(filter(lambda nums:nums<0,nums)) return sum(sum_negativenum)
[ "assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32", "assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52", "assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894" ]
[]
[ "Here is the solution to the problem:\n\n```python\ndef sum_negativenum(nums):\n \"\"\"\n Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.\n \"\"\"\n return sum(filter(lambda x: x < 0, nums))\n```\n\nIn this solution, we use the `filter` fun...
[ 1 ]
134
Write a python function to check whether the last element of given array is even or odd after performing an operation p times.
def check_last (arr,n,p): _sum = 0 for i in range(n): _sum = _sum + arr[i] if p == 1: if _sum % 2 == 0: return "ODD" else: return "EVEN" return "EVEN"
[ "assert check_last([5,7,10],3,1) == \"ODD\"", "assert check_last([2,3],2,3) == \"EVEN\"", "assert check_last([1,2,3],3,1) == \"ODD\"" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef check_last(arr,n,p):\n \"\"\"\n Write a python function to check whether the last element of given array is even or odd after performing an operation p times.\n \"\"\"\n for i in range(p):\n if arr[n-1] % 2 == 0:\n ar...
[ 0 ]
135
Write a function to find the nth hexagonal number.
def hexagonal_num(n): return n*(2*n - 1)
[ "assert hexagonal_num(10) == 190", "assert hexagonal_num(5) == 45", "assert hexagonal_num(7) == 91" ]
[]
[ "Here is the Python function to find the nth hexagonal number:\n\n```python\ndef hexagonal_num(n):\n \"\"\"\n Write a function to find the nth hexagonal number.\n \"\"\"\n return 3*n*(n-1)//2\n```\n\nThis function uses the formula for the nth hexagonal number, which is 3n(n-1)/2." ]
[ 0 ]
136
Write a function to calculate electricity bill.
def cal_electbill(units): if(units < 50): amount = units * 2.60 surcharge = 25 elif(units <= 100): amount = 130 + ((units - 50) * 3.25) surcharge = 35 elif(units <= 200): amount = 130 + 162.50 + ((units - 100) * 5.26) surcharge = 45 else: amount = 130 + 162.50 + 526 + ((units ...
[ "assert cal_electbill(75)==246.25", "assert cal_electbill(265)==1442.75", "assert cal_electbill(100)==327.5" ]
[]
[ "Sure, here is a Python function to calculate the electricity bill based on the number of units consumed:\n\n```python\ndef cal_electbill(units):\n # Define the base rate and rate per unit\n base_rate = 0.50\n rate_per_unit = 0.10\n \n # Calculate the total bill\n total_bill = base_rate + (units *...
[ 0 ]
137
Write a function to find the ration of zeroes in an array of integers.
from array import array def zero_count(nums): n = len(nums) n1 = 0 for x in nums: if x == 0: n1 += 1 else: None return round(n1/n,2)
[ "assert zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.15", "assert zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.00", "assert zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.00" ]
[]
[ "Here is a Python function that calculates the ratio of zeroes in an array of integers:\n\n```python\ndef zero_count(nums):\n \"\"\"\n Write a function to find the ration of zeroes in an array of integers.\n \"\"\"\n zero_count = nums.count(0)\n total_count = len(nums)\n return zero_count / total_...
[ 0 ]
138
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
def is_Sum_Of_Powers_Of_Two(n): if (n % 2 == 1): return False else: return True
[ "assert is_Sum_Of_Powers_Of_Two(10) == True", "assert is_Sum_Of_Powers_Of_Two(7) == False", "assert is_Sum_Of_Powers_Of_Two(14) == True" ]
[]
[ "Sure, here is the Python function to check whether the given number can be represented as sum of non-zero powers of 2 or not:\n\n```python\ndef is_Sum_Of_Powers_Of_Two(n):\n \"\"\"\n Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.\n \"\"\...
[ 0 ]
139
Write a function to find the circumference of a circle.
def circle_circumference(r): perimeter=2*3.1415*r return perimeter
[ "assert circle_circumference(10)==62.830000000000005", "assert circle_circumference(5)==31.415000000000003", "assert circle_circumference(4)==25.132" ]
[]
[ "Sure, here is the Python function to find the circumference of a circle:\n\n```python\ndef circle_circumference(r):\n \"\"\"\n Write a function to find the circumference of a circle.\n \"\"\"\n return 2 * 3.14159 * r\n```\n\nThis function takes the radius of the circle as input and returns the circumfe...
[ 0 ]
140
Write a function to extract elements that occur singly in the given tuple list.
def extract_singly(test_list): res = [] temp = set() for inner in test_list: for ele in inner: if not ele in temp: temp.add(ele) res.append(ele) return (res)
[ "assert extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == [3, 4, 5, 7, 1]", "assert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == [1, 2, 3, 4, 7, 8]", "assert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == [7, 8, 9, 10, 11, 12]" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef extract_singly(test_list):\n \"\"\"\n Write a function to extract elements that occur singly in the given tuple list.\n \"\"\"\n # Create a dictionary to count the occurrences of each element\n count_dict = {}\n for item in test...
[ 0 ]
141
Write a function to sort a list of elements using pancake sort.
def pancake_sort(nums): arr_len = len(nums) while arr_len > 1: mi = nums.index(max(nums[0:arr_len])) nums = nums[mi::-1] + nums[mi+1:len(nums)] nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)] arr_len -= 1 return nums
[ "assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]", "assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]", "assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]" ]
[]
[ "Sure, here is a Python implementation of the pancake sort algorithm:\n\n```python\ndef pancake_sort(nums):\n n = len(nums)\n while n > 1:\n # Find the index of the maximum element\n max_index = nums.index(max(nums[:n]))\n \n # Flip the array from the start to the index of the maxi...
[ 0 ]
142
Write a function to count the same pair in three given lists.
def count_samepair(list1,list2,list3): result = sum(m == n == o for m, n, o in zip(list1,list2,list3)) return result
[ "assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3", "assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4", "assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5" ]
[]
[ "Here is a Python function that counts the same pair in three given lists:\n\n```python\ndef count_samepair(list1, list2, list3):\n count = 0\n for i in range(len(list1)):\n for j in range(len(list2)):\n for k in range(len(list3)):\n if list1[i] == list2[j] == list3[k]:\n ...
[ 0 ]
143
Write a function to find number of lists present in the given tuple.
def find_lists(Input): if isinstance(Input, list): return 1 else: return len(Input)
[ "assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2", "assert find_lists(([1, 2], [3, 4], [5, 6])) == 3", "assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef find_lists(Input):\n \"\"\"\n Write a function to find number of lists present in the given tuple.\n \"\"\"\n return len([i for i in Input if isinstance(i, list)])\n```\n\nThis function uses a list comprehension to iterate over each el...
[ 0 ]
144
Write a python function to find the sum of absolute differences in all pairs of the given array.
def sum_Pairs(arr,n): sum = 0 for i in range(n - 1,-1,-1): sum += i*arr[i] - (n-1-i) * arr[i] return sum
[ "assert sum_Pairs([1,8,9,15,16],5) == 74", "assert sum_Pairs([1,2,3,4],4) == 10", "assert sum_Pairs([1,2,3,4,5,7,9,11,14],9) == 188" ]
[]
[ "Here is a Python function that calculates the sum of absolute differences in all pairs of the given array:\n\n```python\ndef sum_Pairs(arr,n):\n arr.sort() # Sort the array in ascending order\n total_sum = 0\n for i in range(n):\n total_sum += (arr[i] * (2 * i + 1)) - (arr[i] * (2 * i))\n retur...
[ 0 ]
145
Write a python function to find the maximum difference between any two elements in a given array.
def max_Abs_Diff(arr,n): minEle = arr[0] maxEle = arr[0] for i in range(1, n): minEle = min(minEle,arr[i]) maxEle = max(maxEle,arr[i]) return (maxEle - minEle)
[ "assert max_Abs_Diff((2,1,5,3),4) == 4", "assert max_Abs_Diff((9,3,2,5,1),5) == 8", "assert max_Abs_Diff((3,2,1),3) == 2" ]
[]
[ "Here is the Python function to find the maximum difference between any two elements in a given array:\n\n```python\ndef max_Abs_Diff(arr,n):\n \"\"\"\n Write a python function to find the maximum difference between any two elements in a given array.\n \"\"\"\n if n <= 1:\n return 0\n min_val ...
[ 1 ]
146
Write a function to find the ascii value of total characters in a string.
def ascii_value_string(str1): for i in range(len(str1)): return ord(str1[i])
[ "assert ascii_value_string(\"python\")==112", "assert ascii_value_string(\"Program\")==80", "assert ascii_value_string(\"Language\")==76" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef ascii_value_string(str1):\n \"\"\"\n Write a function to find the ascii value of total characters in a string.\n \"\"\"\n return sum(ord(char) for char in str1)\n```\n\nThis function uses a generator expression to iterate over each cha...
[ 0 ]
147
Write a function to find the maximum total path sum in the given triangle.
def max_path_sum(tri, m, n): for i in range(m-1, -1, -1): for j in range(i+1): if (tri[i+1][j] > tri[i+1][j+1]): tri[i][j] += tri[i+1][j] else: tri[i][j] += tri[i+1][j+1] return tri[0][0]
[ "assert max_path_sum([[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2) == 14", "assert max_path_sum([[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2) == 24 ", "assert max_path_sum([[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2) == 53" ]
[]
[ "Here is a Python solution for the problem:\n\n```python\ndef max_path_sum(tri, m, n):\n for i in range(m-2, -1, -1):\n for j in range(i+1):\n tri[i][j] += max(tri[i+1][j], tri[i+1][j+1])\n return tri[0][0]\n```\n\nThis function works by starting from the second last row of the triangle and ...
[ 0 ]
148
Write a function to divide a number into two parts such that the sum of digits is maximum.
def sum_digits_single(x) : ans = 0 while x : ans += x % 10 x //= 10 return ans def closest(x) : ans = 0 while (ans * 10 + 9 <= x) : ans = ans * 10 + 9 return ans def sum_digits_twoparts(N) : A = closest(N) return sum_digits_single(A) + ...
[ "assert sum_digits_twoparts(35)==17", "assert sum_digits_twoparts(7)==7", "assert sum_digits_twoparts(100)==19" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef sum_digits_twoparts(N):\n # Convert the number to a string to easily access each digit\n num_str = str(N)\n \n # Initialize variables to store the maximum sum and the corresponding parts\n max_sum = 0\n part1 = 0\n part2 = 0\...
[ 0 ]
149
Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.
def longest_subseq_with_diff_one(arr, n): dp = [1 for i in range(n)] for i in range(n): for j in range(i): if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): dp[i] = max(dp[i], dp[j]+1) result = 1 for i in range(n): if (result < dp[i]): result = dp[i] return result
[ "assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6", "assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3", "assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) == 7" ]
[]
[ "Here is a Python solution for the problem:\n\n```python\ndef longest_subseq_with_diff_one(arr, n):\n dp = [1] * n\n for i in range(1, n):\n if abs(arr[i] - arr[i-1]) == 1:\n dp[i] = dp[i-1] + 1\n return max(dp)\n```\n\nThis function uses dynamic programming to solve the problem. It creat...
[ 0 ]
150
Write a python function to find whether the given number is present in the infinite sequence or not.
def does_Contain_B(a,b,c): if (a == b): return True if ((b - a) * c > 0 and (b - a) % c == 0): return True return False
[ "assert does_Contain_B(1,7,3) == True", "assert does_Contain_B(1,-3,5) == False", "assert does_Contain_B(3,2,5) == False" ]
[]
[ "Here is a Python function that checks whether a given number is present in the infinite sequence or not:\n\n```python\ndef does_Contain_B(a, b, c):\n \"\"\"\n Write a python function to find whether the given number is present in the infinite sequence or not.\n \"\"\"\n # The infinite sequence is defin...
[ 0 ]
151
Write a python function to check whether the given number is co-prime or not.
def gcd(p,q): while q != 0: p, q = q,p%q return p def is_coprime(x,y): return gcd(x,y) == 1
[ "assert is_coprime(17,13) == True", "assert is_coprime(15,21) == False", "assert is_coprime(25,45) == False" ]
[]
[ "Sure, here is the Python function to check whether the given number is co-prime or not:\n\n```python\ndef is_coprime(x,y):\n \"\"\"\n Write a python function to check whether the given number is co-prime or not.\n \"\"\"\n if x == 1 or y == 1:\n return True\n elif x == y:\n return Fals...
[ 1 ]
152
Write a function to sort the given array by using merge sort.
def merge(a,b): c = [] while len(a) != 0 and len(b) != 0: if a[0] < b[0]: c.append(a[0]) a.remove(a[0]) else: c.append(b[0]) b.remove(b[0]) if len(a) == 0: c += b else: c += a return c def merge_sort(x): ...
[ "assert merge_sort([3, 4, 2, 6, 5, 7, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 9]", "assert merge_sort([7, 25, 45, 78, 11, 33, 19]) == [7, 11, 19, 25, 33, 45, 78]", "assert merge_sort([3, 1, 4, 9, 8]) == [1, 3, 4, 8, 9]" ]
[]
[ "Sure, here is the Python code for the merge sort algorithm:\n\n```python\ndef merge_sort(x):\n if len(x) <= 1:\n return x\n else:\n mid = len(x) // 2\n left = merge_sort(x[:mid])\n right = merge_sort(x[mid:])\n return merge(left, right)\n\ndef merge(left, right):\n resul...
[ 1 ]
153
Write a function to find the vertex of a parabola.
def parabola_vertex(a, b, c): vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a)))) return vertex
[ "assert parabola_vertex(5,3,2)==(-0.3, 1.55)", "assert parabola_vertex(9,8,4)==(-0.4444444444444444, 2.2222222222222223)", "assert parabola_vertex(2,4,6)==(-1.0, 4.0)" ]
[]
[ "Sure, here is the Python function to find the vertex of a parabola:\n\n```python\ndef parabola_vertex(a, b, c):\n \"\"\"\n Write a function to find the vertex of a parabola.\n \"\"\"\n x = -b / (2 * a)\n y = a * x**2 + b * x + c\n return (x, y)\n```\n\nThis function takes three parameters: `a`, `...
[ 1 ]
154
Write a function to extract every specified element from a given two dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
[ "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],3)==[2,2,5]" ]
[]
[ "Here is a Python function that extracts every specified element from a given two dimensional list:\n\n```python\ndef specified_element(nums, N):\n \"\"\"\n Write a function to extract every specified element from a given two dimensional list.\n \"\"\"\n result = []\n for sublist in nums:\n fo...
[ 0 ]
155
Write a python function to toggle all even bits of a given number.
def even_bit_toggle_number(n) : res = 0; count = 0; temp = n while (temp > 0) : if (count % 2 == 1) : res = res | (1 << count) count = count + 1 temp >>= 1 return n ^ res
[ "assert even_bit_toggle_number(10) == 0", "assert even_bit_toggle_number(20) == 30", "assert even_bit_toggle_number(30) == 20" ]
[]
[ "Here is the Python function to toggle all even 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 all bits of the number\n for i in range(32):\n # Check if the current bit is even\n if i % 2 == 0:\n ...
[ 0 ]
156
Write a function to convert a tuple of string values to a tuple of integer values.
def tuple_int_str(tuple_str): result = tuple((int(x[0]), int(x[1])) for x in tuple_str) return result
[ "assert tuple_int_str((('333', '33'), ('1416', '55')))==((333, 33), (1416, 55))", "assert tuple_int_str((('999', '99'), ('1000', '500')))==((999, 99), (1000, 500))", "assert tuple_int_str((('666', '66'), ('1500', '555')))==((666, 66), (1500, 555))" ]
[]
[ "Here is the Python function to convert a tuple of string values to a tuple of integer values:\n\n```python\ndef tuple_int_str(tuple_str):\n return tuple(int(i) for i in tuple_str)\n```\n\nYou can use this function by passing a tuple of string values as an argument. For example:\n\n```python\nprint(tuple_int_str...
[ 0 ]
157
Write a function to reflect the run-length encoding from a list.
from itertools import groupby def encode_list(list1): return [[len(list(group)), key] for key, group in groupby(list1)]
[ "assert encode_list([1,1,2,3,4,4.3,5,1])==[[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]]", "assert encode_list('automatically')==[[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y']]", "assert encode_list('python')==[[1, 'p'], [1, 'y...
[]
[ "Here is a Python function that implements the run-length encoding algorithm:\n\n```python\ndef encode_list(list1):\n \"\"\"\n Write a function to reflect the run-length encoding from a list.\n \"\"\"\n encoded_list = []\n count = 1\n for i in range(1, len(list1)):\n if list1[i] == list1[i-...
[ 0 ]
158
Write a python function to find k number of operations required to make all elements equal.
def min_Ops(arr,n,k): max1 = max(arr) res = 0 for i in range(0,n): if ((max1 - arr[i]) % k != 0): return -1 else: res += (max1 - arr[i]) / k return int(res)
[ "assert min_Ops([2,2,2,2],4,3) == 0", "assert min_Ops([4,2,6,8],4,3) == -1", "assert min_Ops([21,33,9,45,63],5,6) == 24" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef min_Ops(arr,n,k):\n \"\"\"\n Write a python function to find k number of operations required to make all elements equal.\n \"\"\"\n # Find the minimum element in the array\n min_val = min(arr)\n \n # Calculate the number of o...
[ 0 ]
159
Write a function to print the season for the given month and day.
def month_season(month,days): if month in ('January', 'February', 'March'): season = 'winter' elif month in ('April', 'May', 'June'): season = 'spring' elif month in ('July', 'August', 'September'): season = 'summer' else: season = 'autumn' if (month == 'March') and (days > 19): season = 'sprin...
[ "assert month_season('January',4)==('winter')", "assert month_season('October',28)==('autumn')", "assert month_season('June',6)==('spring')" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef month_season(month, days):\n if month in [1, 2, 3]:\n return \"Winter\"\n elif month in [4, 5, 6]:\n return \"Spring\"\n elif month in [7, 8, 9]:\n return \"Summer\"\n elif month in [10, 11, 12]:\n return \...
[ 0 ]
160
Write a function to find x and y that satisfies ax + by = n.
def solution (a, b, n): i = 0 while i * a <= n: if (n - (i * a)) % b == 0: return ("x = ",i ,", y = ", int((n - (i * a)) / b)) return 0 i = i + 1 return ("No solution")
[ "assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)", "assert solution(4, 2, 7) == 'No solution'", "assert solution(1, 13, 17) == ('x = ', 4, ', y = ', 1)" ]
[]
[ "Here is a Python solution for the problem:\n\n```python\ndef solution(a, b, n):\n \"\"\"\n Write a function to find x and y that satisfies ax + by = n.\n \"\"\"\n for x in range(n + 1):\n for y in range(n + 1):\n if a * x + b * y == n:\n return x, y\n return None\n``...
[ 0 ]
161
Write a function to remove all elements from a given list present in another list.
def remove_elements(list1, list2): result = [x for x in list1 if x not in list2] return result
[ "assert remove_elements([1,2,3,4,5,6,7,8,9,10],[2,4,6,8])==[1, 3, 5, 7, 9, 10]", "assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[1, 3, 5, 7])==[2, 4, 6, 8, 9, 10]", "assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[5,7])==[1, 2, 3, 4, 6, 8, 9, 10]" ]
[]
[ "Here is the Python function to remove all elements from a given list present in another list:\n\n```python\ndef remove_elements(list1, list2):\n \"\"\"\n Write a function to remove all elements from a given list present in another list.\n \"\"\"\n for element in list2:\n if element in list1:\n ...
[ 0 ]
162
Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).
def sum_series(n): if n < 1: return 0 else: return n + sum_series(n - 2)
[ "assert sum_series(6)==12", "assert sum_series(10)==30", "assert sum_series(9)==25" ]
[]
[ "Here is the Python code to solve the problem:\n\n```python\ndef sum_series(n):\n \"\"\"\n Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).\n \"\"\"\n sum = 0\n while n > 0:\n sum += n\n n -= 2\n return sum\n```\n\nThis function wor...
[ 1 ]
163
Write a function to calculate the area of a regular polygon.
from math import tan, pi def area_polygon(s,l): area = s * (l ** 2) / (4 * tan(pi / s)) return area
[ "assert area_polygon(4,20)==400.00000000000006", "assert area_polygon(10,15)==1731.1969896610804", "assert area_polygon(9,7)==302.90938549487214" ]
[]
[ "Sure, here is the Python function to calculate the area of a regular polygon:\n\n```python\ndef area_polygon(s, l):\n \"\"\"\n Write a function to calculate the area of a regular polygon.\n \"\"\"\n return (s * l) / 2\n```\n\nThis function takes two parameters: `s` (the side length of the polygon) and ...
[ 0 ]
164
Write a python function to check whether the sum of divisors are same or not.
import math def divSum(n): sum = 1; i = 2; while(i * i <= n): if (n % i == 0): sum = (sum + i +math.floor(n / i)); i += 1; return sum; def areEquivalent(num1,num2): return divSum(num1) == divSum(num2);
[ "assert areEquivalent(36,57) == False", "assert areEquivalent(2,4) == False", "assert areEquivalent(23,47) == True" ]
[]
[ "Sure, here is the Python function to check whether the sum of divisors are same or not:\n\n```python\ndef areEquivalent(num1, num2):\n \"\"\"\n Write a python function to check whether the sum of divisors are same or not.\n \"\"\"\n def sum_of_divisors(n):\n return sum([i for i in range(1, n+1) ...
[ 0 ]
165
Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.
def count_char_position(str1): count_chars = 0 for i in range(len(str1)): if ((i == ord(str1[i]) - ord('A')) or (i == ord(str1[i]) - ord('a'))): count_chars += 1 return count_chars
[ "assert count_char_position(\"xbcefg\") == 2", "assert count_char_position(\"ABcED\") == 3", "assert count_char_position(\"AbgdeF\") == 5" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef count_char_position(str1):\n count = 0\n for i in range(len(str1)):\n if str1[i].lower() == chr(ord('a') + i):\n count += 1\n return count\n```\n\nThis function works by iterating over each character in the input string....
[ 1 ]
166
Write a python function to count the pairs with xor as an even number.
def find_even_Pair(A,N): evenPair = 0 for i in range(0,N): for j in range(i+1,N): if ((A[i] ^ A[j]) % 2 == 0): evenPair+=1 return evenPair;
[ "assert find_even_Pair([5,4,7,2,1],5) == 4", "assert find_even_Pair([7,2,8,1,0,5,11],7) == 9", "assert find_even_Pair([1,2,3],3) == 1" ]
[]
[ "Here is a Python function that counts the pairs with xor as an even number:\n\n```python\ndef find_even_Pair(A,N):\n even_count = 0\n for i in range(N):\n for j in range(i+1, N):\n if (A[i] ^ A[j]) % 2 == 0:\n even_count += 1\n return even_count\n```\n\nThis function works...
[ 1 ]
167
Write a python function to find smallest power of 2 greater than or equal to n.
def next_Power_Of_2(n): count = 0; if (n and not(n & (n - 1))): return n while( n != 0): n >>= 1 count += 1 return 1 << count;
[ "assert next_Power_Of_2(0) == 1", "assert next_Power_Of_2(5) == 8", "assert next_Power_Of_2(17) == 32" ]
[]
[ "Here is the Python function to find the smallest power of 2 greater than or equal to a given number `n`:\n\n```python\ndef next_Power_Of_2(n):\n \"\"\"\n Write a python function to find smallest power of 2 greater than or equal to n.\n \"\"\"\n if n <= 0:\n return 1\n return 2 ** (n - 1).bit_...
[ 1 ]
168
Write a python function to find the frequency of a number in a given array.
def frequency(a,x): count = 0 for i in a: if i == x: count += 1 return count
[ "assert frequency([1,2,3],4) == 0", "assert frequency([1,2,2,3,3,3,4],3) == 3", "assert frequency([0,1,2,3,1,2],1) == 2" ]
[]
[ "Here is the Python function to find the frequency of a number in a given array:\n\n```python\ndef frequency(a,x):\n count = 0\n for i in a:\n if i == x:\n count += 1\n return count\n```\n\nYou can use this function by passing an array and a number as arguments. For example:\n\n```python\...
[ 0 ]
169
Write a function to calculate the nth pell number.
def get_pell(n): if (n <= 2): return n a = 1 b = 2 for i in range(3, n+1): c = 2 * b + a a = b b = c return b
[ "assert get_pell(4) == 12", "assert get_pell(7) == 169", "assert get_pell(8) == 408" ]
[]
[ "Sure, here is the Python function to calculate the nth pell number:\n\n```python\ndef get_pell(n):\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n a, b = 0, 1\n for i in range(2, n+1):\n a, b = b, 2*b + a\n return b\n```\n\nThis function uses a loo...
[ 1 ]
170
Write a function to find sum of the numbers in a list between the indices of a specified range.
def sum_range_list(list1, m, n): sum_range = 0 ...
[ "assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],8,10)==29", "assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],5,7)==16", "assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],7,10)==38" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef sum_range_list(list1, m, n):\n \"\"\"\n Write a function to find sum of the numbers in a list between the indices of a specified range.\n \"\"\"\n return sum(list1[m:n+1])\n```\n\nThis function takes a list and two indices as input. It...
[ 1 ]
171
Write a function to find the perimeter of a pentagon.
import math def perimeter_pentagon(a): perimeter=(5*a) return perimeter
[ "assert perimeter_pentagon(5)==25", "assert perimeter_pentagon(10)==50", "assert perimeter_pentagon(15)==75" ]
[]
[ "Sure, here is the Python function to find the perimeter of a pentagon:\n\n```python\ndef perimeter_pentagon(a):\n \"\"\"\n Write a function to find the perimeter of a pentagon.\n \"\"\"\n return 5 * a\n```\n\nThis function takes one argument `a`, which represents the length of one side of the pentagon....
[ 1 ]
172
Write 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
def count_occurance(s): count=0 for i in range(len(s)): if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'): count = count + 1 return count
[ "assert count_occurance(\"letstdlenstdporstd\") == 3", "assert count_occurance(\"truststdsolensporsd\") == 1", "assert count_occurance(\"makestdsostdworthit\") == 2" ]
[]
[ "Here is the Python function to count the occurrence of characters 'std' in the given string:\n\n```python\ndef count_occurance(s):\n return s.count('std')\n```\n\nThis function uses the built-in `count()` method of Python strings to count the number of occurrences of the substring 'std' in the given string `s`....
[ 1 ]
173
Write a function to remove everything except alphanumeric characters from a string.
import re def remove_splchar(text): pattern = re.compile('[\W_]+') return (pattern.sub('', text))
[ "assert remove_splchar('python @#&^%$*program123')==('pythonprogram123')", "assert remove_splchar('python %^$@!^&*() programming24%$^^() language')==('pythonprogramming24language')", "assert remove_splchar('python ^%&^()(+_)(_^&67) program')==('python67program')" ]
[]
[ "Here is the Python function to remove everything except alphanumeric characters from a string:\n\n```python\ndef remove_splchar(text):\n return ''.join(char for char in text if char.isalnum())\n```\n\nThis function uses a generator expression to iterate over each character in the input string `text`. The `isaln...
[ 1 ]
174
Write a function to group a sequence of key-value pairs into a dictionary of lists.
def group_keyvalue(l): result = {} for k, v in l: result.setdefault(k, []).append(v) return result
[ "assert group_keyvalue([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])=={'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}", "assert group_keyvalue([('python', 1), ('python', 2), ('python', 3), ('python', 4), ('python', 5)])=={'python': [1,2,3,4,5]}", "assert group_keyvalue([('yellow',100), ('...
[]
[ "Here is a Python function that groups a sequence of key-value pairs into a dictionary of lists:\n\n```python\ndef group_keyvalue(l):\n result = {}\n for key, value in l:\n if key not in result:\n result[key] = []\n result[key].append(value)\n return result\n```\n\nYou can use this...
[ 0 ]
175
Write a function to verify validity of a string of parentheses.
def is_valid_parenthese( str1): stack, pchar = [], {"(": ")", "{": "}", "[": "]"} for parenthese in str1: if parenthese in pchar: stack.append(parenthese) elif len(stack) == 0 or pchar[stack.pop()] != parenthese: return False return ...
[ "assert is_valid_parenthese(\"(){}[]\")==True", "assert is_valid_parenthese(\"()[{)}\")==False", "assert is_valid_parenthese(\"()\")==True" ]
[]
[ "Here is a Python function that verifies the validity of a string of parentheses:\n\n```python\ndef is_valid_parenthese(str1):\n stack = []\n for char in str1:\n if char == '(':\n stack.append(char)\n elif char == ')':\n if not stack:\n return False\n ...
[ 1 ]
176
Write a function to find the perimeter of a triangle.
def perimeter_triangle(a,b,c): perimeter=a+b+c return perimeter
[ "assert perimeter_triangle(10,20,30)==60", "assert perimeter_triangle(3,4,5)==12", "assert perimeter_triangle(25,35,45)==105" ]
[]
[ "Sure, here is the Python function to find the perimeter of a triangle:\n\n```python\ndef perimeter_triangle(a, b, c):\n \"\"\"\n Write a function to find the perimeter of a triangle.\n \"\"\"\n return a + b + c\n```\n\nYou can call this function with the lengths of the three sides of the triangle as ar...
[ 0 ]
177
Write a python function to find two distinct numbers such that their lcm lies within the given range.
def answer(L,R): if (2 * L <= R): return (L ,2*L) else: return (-1)
[ "assert answer(3,8) == (3,6)", "assert answer(2,6) == (2,4)", "assert answer(1,3) == (1,2)" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef answer(L,R):\n for i in range(L, R+1):\n for j in range(i+1, R+1):\n if (i*j) % (i+j) == 0:\n return i, j\n return None\n```\n\nThis function iterates over all possible pairs of numbers within the given rang...
[ 0 ]
178
Write a function to search some literals strings in a string.
import re def string_literals(patterns,text): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')
[ "assert string_literals(['language'],'python language')==('Matched!')", "assert string_literals(['program'],'python language')==('Not Matched!')", "assert string_literals(['python'],'programming language')==('Not Matched!')" ]
[]
[ "Here is a Python function that searches for some literals strings in a string:\n\n```python\ndef string_literals(patterns, text):\n \"\"\"\n Write a function to search some literals strings in a string.\n \"\"\"\n for pattern in patterns:\n if pattern in text:\n return True\n retur...
[ 0 ]
179
Write a function to find if the given number is a keith number or not.
def is_num_keith(x): terms = [] temp = x n = 0 while (temp > 0): terms.append(temp % 10) temp = int(temp / 10) n+=1 terms.reverse() next_term = 0 i = n while (next_term < x): next_term = 0 for j in range(1,n+1): next_term += terms[i - j] terms.append(next_term) i...
[ "assert is_num_keith(14) == True", "assert is_num_keith(12) == False", "assert is_num_keith(197) == True" ]
[]
[ "Sure, here is a Python function to check if a number is a Keith number or not:\n\n```python\ndef is_num_keith(x):\n \"\"\"\n Write a function to find if the given number is a keith number or not.\n \"\"\"\n digits = [int(digit) for digit in str(x)]\n n = len(digits)\n while True:\n sum_of_...
[ 1 ]
180
Write a function to calculate distance between two points using latitude and longitude.
from math import radians, sin, cos, acos def distance_lat_long(slat,slon,elat,elon): dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon)) return dist
[ "assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429", "assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514", "assert distance_lat_long(10,20,30,40)==6783.751974994595" ]
[]
[ "Sure, here is the Python function to calculate the distance between two points using latitude and longitude:\n\n```python\nimport math\n\ndef distance_lat_long(slat, slon, elat, elon):\n \"\"\"\n Write a function to calculate distance between two points using latitude and longitude.\n \"\"\"\n # Conver...
[ 0 ]
181
Write a function to find the longest common prefix in the given set of strings.
def common_prefix_util(str1, str2): result = ""; n1 = len(str1) n2 = len(str2) i = 0 j = 0 while i <= n1 - 1 and j <= n2 - 1: if (str1[i] != str2[j]): break result += str1[i] i += 1 j += 1 return (result) def common_prefix (arr, n): prefix = arr[0] for i in range (1, n): ...
[ "assert common_prefix([\"tablets\", \"tables\", \"taxi\", \"tamarind\"], 4) == 'ta'", "assert common_prefix([\"apples\", \"ape\", \"april\"], 3) == 'ap'", "assert common_prefix([\"teens\", \"teenager\", \"teenmar\"], 3) == 'teen'" ]
[]
[ "Here is a Python function that finds the longest common prefix in a set of strings:\n\n```python\ndef common_prefix(arr, n):\n if n == 0:\n return \"\"\n prefix = arr[0]\n for i in range(1, n):\n while arr[i].find(prefix) != 0:\n prefix = prefix[:-1]\n if prefix == \"\"...
[ 1 ]
182
Write a function to find uppercase, lowercase, special character and numeric values using regex.
import re def find_character(string): uppercase_characters = re.findall(r"[A-Z]", string) lowercase_characters = re.findall(r"[a-z]", string) numerical_characters = re.findall(r"[0-9]", string) special_characters = re.findall(r"[, .!?]", string) return uppercase_characters, lowercase_characters, num...
[ "assert find_character(\"ThisIsGeeksforGeeks\") == (['T', 'I', 'G', 'G'], ['h', 'i', 's', 's', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'e', 'e', 'k', 's'], [], [])", "assert find_character(\"Hithere2\") == (['H'], ['i', 't', 'h', 'e', 'r', 'e'], ['2'], [])", "assert find_character(\"HeyFolks32\") == (['H', 'F'], ['e...
[]
[ "Here is a Python solution for the problem:\n\n```python\nimport re\n\ndef find_character(string):\n uppercase = re.findall(r'[A-Z]', string)\n lowercase = re.findall(r'[a-z]', string)\n special = re.findall(r'[^A-Za-z0-9]', string)\n numeric = re.findall(r'[0-9]', string)\n \n return uppercase, l...
[ 0 ]
183
Write a function to count all the distinct pairs having a difference of k in any array.
def count_pairs(arr, n, k): count=0; for i in range(0,n): for j in range(i+1, n): if arr[i] - arr[j] == k or arr[j] - arr[i] == k: count += 1 return count
[ "assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2", "assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5", "assert count_pairs([2, 4, 1, 3, 4], 5, 2) == 3" ]
[]
[ "Here is a Python function that counts all the distinct pairs having a difference of k in any array:\n\n```python\ndef count_pairs(arr, n, k):\n # Create a dictionary to store the frequency of each element in the array\n freq = {}\n for i in range(n):\n if arr[i] in freq:\n freq[arr[i]] +...
[ 0 ]
184
Write a function to find all the values in a list that are greater than a specified number.
def greater_specificnum(list,num): greater_specificnum=all(x >= num for x in list) return greater_specificnum
[ "assert greater_specificnum([220, 330, 500],200)==True", "assert greater_specificnum([12, 17, 21],20)==False", "assert greater_specificnum([1,2,3,4],10)==False" ]
[]
[ "Here is the solution to the problem:\n\n```python\ndef greater_specificnum(list,num):\n \"\"\"\n Write a function to find all the values in a list that are greater than a specified number.\n \"\"\"\n return [x for x in list if x > num]\n```\n\nThis function uses a list comprehension to iterate over eac...
[ 0 ]
185
Write a function to find the focus of a parabola.
def parabola_focus(a, b, c): focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a)))) return focus
[ "assert parabola_focus(5,3,2)==(-0.3, 1.6)", "assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)", "assert parabola_focus(2,4,6)==(-1.0, 4.125)" ]
[]
[ "Sure, here is the Python function to find the focus of a parabola given the coefficients \\(a\\), \\(b\\), and \\(c\\):\n\n```python\ndef parabola_focus(a, b, c):\n \"\"\"\n Write a function to find the focus of a parabola.\n \"\"\"\n # The focus of a parabola given by the equation y = ax^2 + bx + c is...
[ 0 ]
186
Write a function to search some literals strings in a string by using regex.
import re def check_literals(text, patterns): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')
[ "assert check_literals('The quick brown fox jumps over the lazy dog.',['fox']) == 'Matched!'", "assert check_literals('The quick brown fox jumps over the lazy dog.',['horse']) == 'Not Matched!'", "assert check_literals('The quick brown fox jumps over the lazy dog.',['lazy']) == 'Matched!'" ]
[]
[ "Here is a Python function that uses regular expressions to search for some literals strings in a string:\n\n```python\nimport re\n\ndef check_literals(text, patterns):\n \"\"\"\n Write a function to search some literals strings in a string by using regex.\n \"\"\"\n for pattern in patterns:\n if...
[ 0 ]
187
Write a function to find the longest common subsequence for the given two sequences.
def longest_common_subsequence(X, Y, m, n): if m == 0 or n == 0: return 0 elif X[m-1] == Y[n-1]: return 1 + longest_common_subsequence(X, Y, m-1, n-1) else: return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))
[ "assert longest_common_subsequence(\"AGGTAB\" , \"GXTXAYB\", 6, 7) == 4", "assert longest_common_subsequence(\"ABCDGH\" , \"AEDFHR\", 6, 6) == 3", "assert longest_common_subsequence(\"AXYT\" , \"AYZX\", 4, 4) == 2" ]
[]
[ "Here is a Python function to find the longest common subsequence for two sequences:\n\n```python\ndef longest_common_subsequence(X, Y, m, n):\n # Create a 2D array to store lengths of longest common subsequences\n L = [[0 for x in range(n+1)] for y in range(m+1)]\n \n # Build the L[m+1][n+1] table in b...
[ 0 ]
188
Write a python function to check whether the given number can be represented by product of two squares or not.
def prod_Square(n): for i in range(2,(n) + 1): if (i*i < (n+1)): for j in range(2,n + 1): if ((i*i*j*j) == n): return True; return False;
[ "assert prod_Square(25) == False", "assert prod_Square(30) == False", "assert prod_Square(16) == True" ]
[]
[ "Here is the Python function to check whether the given number can be represented by product of two squares or not:\n\n```python\ndef prod_Square(n):\n if n < 0:\n return False\n for i in range(1, int(n**0.5) + 1):\n if n % i == 0:\n j = n // i\n if i * i == j * j:\n ...
[ 0 ]
189
Write a python function to find the first missing positive number.
def first_Missing_Positive(arr,n): ptr = 0 for i in range(n): if arr[i] == 1: ptr = 1 break if ptr == 0: return(1) for i in range(n): if arr[i] <= 0 or arr[i] > n: arr[i] = 1 for i in range(n): arr[(arr[i] - 1) % n] += ...
[ "assert first_Missing_Positive([1,2,3,-1,5],5) == 4", "assert first_Missing_Positive([0,-1,-2,1,5,8],6) == 2", "assert first_Missing_Positive([0,1,2,5,-8],5) == 3" ]
[]
[ "Here is a Python function to find the first missing positive number:\n\n```python\ndef first_Missing_Positive(arr,n):\n \"\"\"\n Write a python function to find the first missing positive number.\n \"\"\"\n for i in range(n):\n if arr[i] <= 0 or arr[i] > n:\n arr[i] = 0\n for i in ...
[ 0 ]
190
Write a python function to count the number of integral co-ordinates that lie inside a square.
def count_Intgral_Points(x1,y1,x2,y2): return ((y2 - y1 - 1) * (x2 - x1 - 1))
[ "assert count_Intgral_Points(1,1,4,4) == 4", "assert count_Intgral_Points(1,2,1,2) == 1", "assert count_Intgral_Points(4,2,6,4) == 1" ]
[]
[ "Here is a Python function that counts the number of integral co-ordinates that lie inside a square:\n\n```python\ndef count_Integral_Points(x1,y1,x2,y2):\n \"\"\"\n Write a python function to count the number of integral co-ordinates that lie inside a square.\n \"\"\"\n # Calculate the side length of t...
[ 0 ]
191
Write a function to check whether the given month name contains 30 days or not.
def check_monthnumber(monthname3): if monthname3 =="April" or monthname3== "June" or monthname3== "September" or monthname3== "November": return True else: return False
[ "assert check_monthnumber(\"February\")==False", "assert check_monthnumber(\"June\")==True", "assert check_monthnumber(\"April\")==True" ]
[]
[ "Sure, here is the Python function to check whether the given month name contains 30 days or not:\n\n```python\ndef check_monthnumber(monthname3):\n # List of months with 30 days\n months_with_30_days = [\"April\", \"June\", \"September\", \"November\"]\n \n # Check if the given month name is in the lis...
[ 0 ]
192
Write a python function to check whether a string has atleast one letter and one number.
def check_String(str): flag_l = False flag_n = False for i in str: if i.isalpha(): flag_l = True if i.isdigit(): flag_n = True return flag_l and flag_n
[ "assert check_String('thishasboth29') == True", "assert check_String('python') == False", "assert check_String ('string') == False" ]
[]
[ "Here is the Python function to check whether a string has atleast one letter and one number:\n\n```python\ndef check_String(str):\n \"\"\"\n Write a python function to check whether a string has atleast one letter and one number.\n \"\"\"\n if any(char.isalpha() for char in str) and any(char.isdigit() ...
[ 1 ]
193
Write a function to remove the duplicates from the given tuple.
def remove_tuple(test_tup): res = tuple(set(test_tup)) return (res)
[ "assert remove_tuple((1, 3, 5, 2, 3, 5, 1, 1, 3)) == (1, 2, 3, 5)", "assert remove_tuple((2, 3, 4, 4, 5, 6, 6, 7, 8, 8)) == (2, 3, 4, 5, 6, 7, 8)", "assert remove_tuple((11, 12, 13, 11, 11, 12, 14, 13)) == (11, 12, 13, 14)" ]
[]
[ "Here is the solution to the problem:\n\n```python\ndef remove_tuple(test_tup):\n \"\"\"\n Write a function to remove the duplicates from the given tuple.\n \"\"\"\n return tuple(set(test_tup))\n```\n\nIn this solution, we use the built-in `set` function to remove duplicates from the tuple. The `set` fu...
[ 1 ]
194
Write a python function to convert octal number to decimal number.
def octal_To_Decimal(n): num = n; dec_value = 0; base = 1; temp = num; while (temp): last_digit = temp % 10; temp = int(temp / 10); dec_value += last_digit*base; base = base * 8; return dec_value;
[ "assert octal_To_Decimal(25) == 21", "assert octal_To_Decimal(30) == 24", "assert octal_To_Decimal(40) == 32" ]
[]
[ "Here is the Python function to convert an octal number to a decimal number:\n\n```python\ndef octal_to_decimal(n):\n decimal = 0\n power = 0\n while n > 0:\n remainder = n % 10\n decimal += remainder * (8 ** power)\n n //= 10\n power += 1\n return decimal\n```\n\nYou can use...
[ 0 ]
195
Write a python function to find the first position of an element in a sorted array.
def first(arr,x,n): low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid high = mid - 1 return res
[ "assert first([1,2,3,4,5,6,6],6,6) == 5", "assert first([1,2,2,2,3,2,2,4,2],2,9) == 1", "assert first([1,2,3],1,3) == 0" ]
[]
[ "Here is the Python function to find the first position of an element in a sorted array:\n\n```python\ndef first(arr, x, n):\n low = 0\n high = n - 1\n result = -1\n\n while low <= high:\n mid = (low + high) // 2\n\n if arr[mid] == x:\n result = mid\n high = mid - 1 ...
[ 1 ]
196
Write a function to remove all the tuples with length k.
def remove_tuples(test_list, K): res = [ele for ele in test_list if len(ele) != K] return (res)
[ "assert remove_tuples([(4, 5), (4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] , 1) == [(4, 5), (8, 6, 7), (3, 4, 6, 7)]", "assert remove_tuples([(4, 5), (4,5), (6, 7), (1, 2, 3), (3, 4, 6, 7)] ,2) == [(1, 2, 3), (3, 4, 6, 7)]", "assert remove_tuples([(1, 4, 4), (4, 3), (8, 6, 7), (1, ), (3, 6, 7)] , 3) == [(4, 3), (1,)...
[]
[ "Here is the Python function to remove all the tuples with length k:\n\n```python\ndef remove_tuples(test_list, K):\n return [t for t in test_list if len(t) != K]\n```\n\nThis function uses a list comprehension to iterate over each tuple in the input list `test_list`. It checks if the length of each tuple is not...
[ 1 ]
197
Write a function to perform the exponentiation of the given two tuples.
def find_exponentio(test_tup1, test_tup2): res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
[ "assert find_exponentio((10, 4, 5, 6), (5, 6, 7, 5)) == (100000, 4096, 78125, 7776)", "assert find_exponentio((11, 5, 6, 7), (6, 7, 8, 6)) == (1771561, 78125, 1679616, 117649)", "assert find_exponentio((12, 6, 7, 8), (7, 8, 9, 7)) == (35831808, 1679616, 40353607, 2097152)" ]
[]
[ "Here is the Python function to perform the exponentiation of the given two tuples:\n\n```python\ndef find_exponentio(test_tup1, test_tup2):\n \"\"\"\n Write a function to perform the exponentiation of the given two tuples.\n \"\"\"\n result = tuple(x**y for x, y in zip(test_tup1, test_tup2))\n retur...
[ 1 ]
198
Write a function to find the largest triangle that can be inscribed in an ellipse.
import math def largest_triangle(a,b): if (a < 0 or b < 0): return -1 area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b); return area
[ "assert largest_triangle(4,2)==10.392304845413264", "assert largest_triangle(5,7)==4.639421805988064", "assert largest_triangle(9,1)==105.2220865598093" ]
[]
[ "Sure, I can help you solve this problem. The largest triangle that can be inscribed in an ellipse is a right triangle with its hypotenuse along the major axis of the ellipse. The area of such a triangle is given by the formula:\n\nArea = (1/2) * base * height\n\nIn this case, the base and height of the triangle ar...
[ 0 ]
199
Write a python function to find highest power of 2 less than or equal to given number.
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 less than or equal to a given number:\n\n```python\ndef highest_Power_of_2(n):\n \"\"\"\n Write a python function to find highest power of 2 less than or equal to given number.\n \"\"\"\n if n == 0:\n return 0\n power = 1\n while p...
[ 1 ]
200
Write a function to find all index positions of the maximum values in a given list.
def position_max(list1): max_val = max(list1) max_result = [i for i, j in enumerate(list1) if j == max_val] return max_result
[ "assert position_max([12,33,23,10,67,89,45,667,23,12,11,10,54])==[7]", "assert position_max([1,2,2,2,4,4,4,5,5,5,5])==[7,8,9,10]", "assert position_max([2,1,5,6,8,3,4,9,10,11,8,12])==[11]" ]
[]
[ "Here is the Python function to solve the problem:\n\n```python\ndef position_max(list1):\n \"\"\"\n Write a function to find all index positions of the maximum values in a given list.\n \"\"\"\n max_value = max(list1)\n return [i for i, x in enumerate(list1) if x == max_value]\n```\n\nThis function ...
[ 1 ]
201
Write a python function to check whether the elements in a list are same or not.
def chkList(lst): return len(set(lst)) == 1
[ "assert chkList(['one','one','one']) == True", "assert chkList(['one','Two','Three']) == False", "assert chkList(['bigdata','python','Django']) == False" ]
[]
[ "Here is the Python function to check whether the elements in a list are same or not:\n\n```python\ndef chkList(lst):\n \"\"\"\n Write a python function to check whether the elements in a list are same or not.\n \"\"\"\n return len(set(lst)) == 1\n```\n\nThis function works by converting the list to a s...
[ 1 ]
202
Write a function to remove even characters in a string.
def remove_even(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 != 0): str2 = str2 + str1[i - 1] return str2
[ "assert remove_even(\"python\")==(\"pto\")", "assert remove_even(\"program\")==(\"porm\")", "assert remove_even(\"language\")==(\"lnug\")" ]
[]
[ "Here is the Python function to remove even characters in a string:\n\n```python\ndef remove_even(str1):\n \"\"\"\n Write a function to remove even characters in a string.\n \"\"\"\n return ''.join([char for char in str1 if int(char) % 2 != 0])\n```\n\nThis function uses a list comprehension to iterate ...
[ 0 ]
203
Write a python function to find the hamming distance between given two integers.
def hamming_Distance(n1,n2) : x = n1 ^ n2 setBits = 0 while (x > 0) : setBits += x & 1 x >>= 1 return setBits
[ "assert hamming_Distance(4,8) == 2", "assert hamming_Distance(2,4) == 2", "assert hamming_Distance(1,2) == 2" ]
[]
[ "Sure, here is the Python function to find the Hamming distance between two integers:\n\n```python\ndef hamming_Distance(n1, n2):\n \"\"\"\n Write a python function to find the hamming distance between given two integers.\n \"\"\"\n # XOR the two numbers\n xor_result = n1 ^ n2\n \n # Count the ...
[ 1 ]
204
Write a python function to count the occurrence of a given character in a string.
def count(s,c) : res = 0 for i in range(len(s)) : if (s[i] == c): res = res + 1 return res
[ "assert count(\"abcc\",\"c\") == 2", "assert count(\"ababca\",\"a\") == 3", "assert count(\"mnmm0pm\",\"m\") == 4" ]
[]
[ "Here is the Python function to count the occurrence of a given character in a string:\n\n```python\ndef count(s, c):\n \"\"\"\n Write a python function to count the occurrence of a given character in a string.\n \"\"\"\n return s.count(c)\n```\n\nThis function uses the built-in `count()` method of Pyth...
[ 1 ]
205
Write a function to find the inversions of tuple elements in the given tuple list.
def inversion_elements(test_tup): res = tuple(list(map(lambda x: ~x, list(test_tup)))) return (res)
[ "assert inversion_elements((7, 8, 9, 1, 10, 7)) == (-8, -9, -10, -2, -11, -8)", "assert inversion_elements((2, 4, 5, 6, 1, 7)) == (-3, -5, -6, -7, -2, -8)", "assert inversion_elements((8, 9, 11, 14, 12, 13)) == (-9, -10, -12, -15, -13, -14)" ]
[]
[ "Sure, here is a Python function that finds the inversions of tuple elements in the given tuple list:\n\n```python\ndef inversion_elements(test_tup):\n \"\"\"\n Write a function to find the inversions of tuple elements in the given tuple list.\n \"\"\"\n inversions = 0\n for i in range(len(test_tup))...
[ 0 ]
206
Write a function to perform the adjacent element concatenation in the given tuples.
def concatenate_elements(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return (res)
[ "assert concatenate_elements((\"DSP \", \"IS \", \"BEST \", \"FOR \", \"ALL \", \"UTS\")) == ('DSP IS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL UTS')", "assert concatenate_elements((\"RES \", \"IS \", \"BEST \", \"FOR \", \"ALL \", \"QESR\")) == ('RES IS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL QESR')", ...
[]
[ "Here is the Python function to perform the adjacent element concatenation in the given tuples:\n\n```python\ndef concatenate_elements(test_tup):\n result = []\n for i in range(len(test_tup) - 1):\n result.append(test_tup[i] + test_tup[i+1])\n return result\n```\n\nYou can use this function by passi...
[ 0 ]
207
Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions.
def find_longest_repeating_subseq(str): n = len(str) dp = [[0 for k in range(n+1)] for l in range(n+1)] for i in range(1, n+1): for j in range(1, n+1): if (str[i-1] == str[j-1] and i != j): dp[i][j] = 1 + dp[i-1][j-1] else: dp[i][j] = max(dp[i][j-1], dp[i-1][j]) return dp[n][n]
[ "assert find_longest_repeating_subseq(\"AABEBCDD\") == 3", "assert find_longest_repeating_subseq(\"aabb\") == 2", "assert find_longest_repeating_subseq(\"aab\") == 1" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef find_longest_repeating_subseq(str):\n n = len(str)\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 if str[i-1] == str[j-1] and i != j:\n dp...
[ 1 ]
208
Write a function to check the given decimal with a precision of 2 by using regex.
import re def is_decimal(num): num_fetch = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""") result = num_fetch.search(num) return bool(result)
[ "assert is_decimal('123.11') == True", "assert is_decimal('0.21') == True", "assert is_decimal('123.1214') == False" ]
[]
[ "Here is the Python code to solve the problem:\n\n```python\nimport re\n\ndef is_decimal(num):\n \"\"\"\n Write a function to check the given decimal with a precision of 2 by using regex.\n \"\"\"\n pattern = r'^\\d+(\\.\\d{2})?$'\n return bool(re.match(pattern, num))\n```\n\nThis function uses the `...
[ 1 ]
209
Write a function to delete the smallest element from the given heap and then insert a new item.
import heapq as hq def heap_replace(heap,a): hq.heapify(heap) hq.heapreplace(heap, a) return heap
[ "assert heap_replace( [25, 44, 68, 21, 39, 23, 89],21)==[21, 25, 23, 44, 39, 68, 89]", "assert heap_replace([25, 44, 68, 21, 39, 23, 89],110)== [23, 25, 68, 44, 39, 110, 89]", "assert heap_replace([25, 44, 68, 21, 39, 23, 89],500)==[23, 25, 68, 44, 39, 500, 89]" ]
[]
[ "Here is a Python function that solves the problem:\n\n```python\ndef heap_replace(heap, a):\n # Remove the smallest element from the heap\n heap.remove(min(heap))\n \n # Insert the new item into the heap\n heap.append(a)\n \n # Rebuild the heap\n heapify(heap)\n \n return heap\n```\n\...
[ 0 ]
210
Write 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.
import re def is_allowed_specific_char(string): get_char = re.compile(r'[^a-zA-Z0-9.]') string = get_char.search(string) return not bool(string)
[ "assert is_allowed_specific_char(\"ABCDEFabcdef123450\") == True", "assert is_allowed_specific_char(\"*&%@#!}{\") == False", "assert is_allowed_specific_char(\"HELLOhowareyou98765\") == True" ]
[]
[ "Here is the Python code to solve the problem:\n\n```python\nimport re\n\ndef is_allowed_specific_char(string):\n \"\"\"\n Write 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 pattern = re.compile('^[a-zA-Z0-9...
[ 1 ]