INSTRUCTION
stringlengths
78
1.13k
RESPONSE
stringlengths
36
906
SOURCE
stringclasses
2 values
Write a Python function which follows this instruction: Write a function that takes in a list and an integer L and splits the given list into two parts where the length of the first part of the list is L, and returns the resulting lists in a tuple.
def split_two_parts(list1, L): return list1[:L], list1[L:]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to calculate a dog's age in dog's years.
def dog_age(h_age): if h_age < 0: exit() elif h_age <= 2: d_age = h_age * 10.5 else: d_age = 21 + (h_age - 2)*4 return d_age
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in a list and an integer n and splits a list for every nth element, returning a list of the resulting lists.
def list_split(S, step): return [S[i::step] for i in range(step)]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the lateral surface area of a cube given its side length.
def lateralsurface_cube(l): LSA = 4 * (l * l) return LSA
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.
def square_Sum(n): return int(n*(4*n*n-1)/3)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the n'th star number.
def find_star_num(n): return (6 * n * (n - 1) + 1)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the ascii value of a character.
def ascii_value(k): ch=k return ord(ch)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the sum of even numbers at even positions of a list.
def sum_even_and_even_index(arr): i = 0 sum = 0 for i in range(0, len(arr),2): if (arr[i] % 2 == 0) : sum += arr[i] return sum
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.
def even_Power_Sum(n): sum = 0; for i in range(1,n+1): j = 2*i; sum = sum + (j*j*j*j*j); return sum;
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in a list of tuples and returns a list containing the rear element of each tuple.
def rear_extract(test_list): res = [lis[-1] for lis in test_list] return (res)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index.
def substract_elements(test_tup1, test_tup2): res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2)) return (res)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function that takes in a positive integer n and finds the sum of even index binomial coefficients.
import math def even_binomial_Coeff_Sum( n): return (1 << (n - 1))
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in the radius and height of a cylinder and returns the the volume.
def volume_cylinder(r,h): volume=3.1415*r*r*h return volume
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in a dictionary and integer n and filters the dictionary to only include entries with values greater than or equal to n.
def dict_filter(dict,n): result = {key:value for (key, value) in dict.items() if value >=n} return result
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the number of elements that occurs before the tuple element in the given tuple.
def count_first_elements(test_tup): for count, ele in enumerate(test_tup): if isinstance(ele, tuple): break return (count)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the nth decagonal number.
def is_num_decagonal(n): return 4 * n * n - 3 * n
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in an array and element and returns a tuple containing a boolean that indicates if the element is in the array and the index position of the element (or -1 if the element is not found).
def sequential_search(dlist, item): pos = 0 found = False while pos < len(dlist) and not found: if dlist[pos] == item: found = True else: pos = pos + 1 return found, pos
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to check if the elements of a given list are unique or not.
def all_unique(test_list): if len(test_list) > len(set(test_list)): return False return True
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to subtract two lists element-wise.
def sub_list(nums1,nums2): result = map(lambda x, y: x - y, nums1, nums2) return list(result)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.
def validate(n): for i in range(10): temp = n; count = 0; while (temp): if (temp % 10 == i): count+=1; if (count > i): return False temp //= 10; return True
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes in a list and element and checks whether all items in the list are equal to the given element.
def check_element(list,element): check_element=all(v== element for v in list) return check_element
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that checks whether a string contains the 'a' character followed by two or three 'b' characters.
import re def text_match_two_three(text): patterns = 'ab{2,3}' if re.search(patterns, text): return True else: return False
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the largest sum of a contiguous array in the modified array which is formed by repeating the given array k times.
def max_sub_array_sum_repeated(a, n, k): max_so_far = -2147483648 max_ending_here = 0 for i in range(n*k): max_ending_here = max_ending_here + a[i%n] if (max_so_far < max_ending_here): max_so_far = max_ending_here if (max_ending_here < 0): max_ending_here = 0 return max_so_far
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers.
def square_Sum(n): return int(2*n*(n+1)*(2*n+1)/3)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the list of maximum length in a list of lists.
def max_length(list1): max_length = max(len(x) for x in list1 ) max_list = max((x) for x in list1) return(max_length, max_list)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.
def count_no_of_ways(n, k): dp = [0] * (n + 1) total = k mod = 1000000007 dp[1] = k dp[2] = k * k for i in range(3,n+1): dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod return dp[n]
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find quotient of two numbers (rounded down to the nearest integer).
def find(n,m): q = n//m return (q)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the third side of a right angled triangle.
import math def otherside_rightangle(w,h): s=math.sqrt((w*w)+(h*h)) return s
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the maximum value in a given heterogeneous list.
def max_val(listval): max_val = max(i for i in listval if isinstance(i, int)) return(max_val)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to return the sum of all divisors of a number.
def sum_div(number): divisors = [1] for i in range(2, number): if (number % i)==0: divisors.append(i) return sum(divisors)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to count inversions in an array.
def get_Inv_Count(arr): inv_count = 0 for i in range(len(arr)): for j in range(i + 1, len(arr)): if (arr[i] > arr[j]): inv_count += 1 return inv_count
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to flatten a given nested list structure.
def flatten_list(list1): result_list = [] if not list1: return result_list stack = [list(list1)] while stack: c_num = stack.pop() next = c_num.pop() if c_num: stack.append(c_num) if isinstance(next, list): if next: stack.append(list(next)) else: result_list.append(next) result_list.reverse() return result_list
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to calculate the maximum aggregate from the list of tuples.
from collections import defaultdict def max_aggregate(stdata): temp = defaultdict(int) for name, marks in stdata: temp[name] += marks return max(temp.items(), key=lambda x: x[1])
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.
def count_binary_seq(n): nCr = 1 res = 1 for r in range(1, n + 1): nCr = (nCr * (n + 1 - r)) / r res += nCr * nCr return res
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the depth of a dictionary.
def dict_depth(d): if isinstance(d, dict): return 1 + (max(map(dict_depth, d.values())) if d else 0) return 0
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find element at a given index after number of rotations.
def find_Element(arr,ranges,rotations,index) : for i in range(rotations - 1,-1,-1 ) : left = ranges[i][0] right = ranges[i][1] if (left <= index and right >= index) : if (index == left) : index = right else : index = index - 1 return arr[index]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to return two words from a list of words starting with letter 'p'.
import re def start_withp(words): for w in words: m = re.match("(P\w+)\W(P\w+)", w) if m: return m.groups()
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the maximum sum of increasing subsequence from prefix until ith index and also including a given kth element which is after i, i.e., k > i .
def max_sum_increasing_subseq(a, n, index, k): dp = [[0 for i in range(n)] for i in range(n)] for i in range(n): if a[i] > a[0]: dp[0][i] = a[i] + a[0] else: dp[0][i] = a[i] for i in range(1, n): for j in range(n): if a[j] > a[i] and j > i: if dp[i - 1][i] + a[j] > dp[i - 1][j]: dp[i][j] = dp[i - 1][i] + a[j] else: dp[i][j] = dp[i - 1][j] else: dp[i][j] = dp[i - 1][j] return dp[index][k]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to get a colon of a tuple.
from copy import deepcopy def colon_tuplex(tuplex,m,n): tuplex_colon = deepcopy(tuplex) tuplex_colon[m].append(n) return tuplex_colon
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the specified number of largest products from two given lists, selecting one factor from each list.
def large_product(nums1, nums2, N): result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N] return result
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the maximum of two numbers.
def maximum(a,b): if a >= b: return a else: return b
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to convert a given string to a tuple of characters.
def string_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result
mbpp_sanitized
Write a Python function which follows this instruction: 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)))
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: 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)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to apply a given format string to all of the elements in a list.
def add_string(list_, string): add_string=[string.format(i) for i in list_] return add_string
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: 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]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the list with maximum length.
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)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to check if given tuple contains no duplicates.
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
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to check whether the given string starts and ends with the same character or not.
import re regex = r'^[a-z]$|^([a-z]).*\1$' def check_char(string): if(re.search(regex, string)): return "Valid" else: return "Invalid"
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the median of three 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
mbpp_sanitized
Write a Python function which follows this instruction: 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())
mbpp_sanitized
Write a Python function which follows this instruction: 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)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to extract the number of unique tuples in the given list.
def extract_freq(test_list): res = len(list(set(tuple(sorted(sub)) for sub in test_list))) return (res)
mbpp_sanitized
Write a Python function which follows this instruction: 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)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the minimum of two numbers.
def minimum(a,b): if a <= b: return a else: return b
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find whether the parity of a given number is odd.
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 True return False
mbpp_sanitized
Write a Python function which follows this instruction: 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)) return False
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find k number of smallest 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.append([nums1[i], nums2[j]]) push(i, j + 1) if j == 0: push(i + 1, 0) return pairs
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: 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
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to convert the given snake case string to camel case string.
import re def snake_to_camel(word): return ''.join(x.capitalize() or '_' for x in word.split('_'))
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to remove odd numbers from a given list.
def remove_odd(l): for i in l: if i % 2 != 0: l.remove(i) return l
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to extract the nth element from a given list of tuples.
def extract_nth_element(list1, n): result = [x[n] for x in list1] return result
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to check whether any value in a sequence exists in a sequence or not.
def overlapping(list1,list2): for i in range(len(list1)): for j in range(len(list2)): if(list1[i]==list2[j]): return True return False
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find a pair with highest product from a given array of integers.
def max_Product(arr): arr_len = len(arr) if (arr_len < 2): return ("No pairs exists") x = arr[0]; y = arr[1] for i in range(0,arr_len): for j in range(i + 1,arr_len): if (arr[i] * arr[j] > x * y): x = arr[i]; y = arr[j] return x,y
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find common first element in given list of tuple.
def group_tuples(Input): out = {} for elem in Input: try: out[elem[0]].extend(elem[1:]) except KeyError: out[elem[0]] = list(elem) return [tuple(values) for values in out.values()]
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the element of a list having maximum length.
def Find_Max(lst): maxList = max((x) for x in lst) return maxList
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.
def round_and_sum(list1): lenght=len(list1) round_and_sum=sum(list(map(round,list1))* lenght) return round_and_sum
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the cube sum of first n even natural numbers.
def cube_Sum(n): sum = 0 for i in range(1,n + 1): sum += (2*i)*(2*i)*(2*i) return sum
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to concatenate each element of tuple by the delimiter.
def concatenate_tuple(test_tup): delim = "-" res = ''.join([str(ele) + delim for ele in test_tup]) res = res[ : len(res) - len(delim)] return (str(res))
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the average of cubes of first n natural numbers.
def find_Average_Of_Cube(n): sum = 0 for i in range(1, n + 1): sum += i * i * i return round(sum / n, 6)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to extract only the rear index element of each string in the given tuple.
def extract_rear(test_tuple): res = list(sub[len(sub) - 1] for sub in test_tuple) return (res)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to count the number of sublists containing a particular element.
def count_element_in_list(list1, x): ctr = 0 for i in range(len(list1)): if x in list1[i]: ctr+= 1 return ctr
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to filter odd numbers.
def filter_oddnumbers(nums): odd_nums = list(filter(lambda x: x%2 != 0, nums)) return odd_nums
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.
import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to sort the given array by using shell sort.
def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to extract the elementwise and tuples from the given two tuples.
def and_tuples(test_tup1, test_tup2): res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the directrix of a parabola.
def parabola_directrix(a, b, c): directrix=((int)(c - ((b * b) + 1) * 4 * a )) return directrix
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that takes two lists and returns true if they have at least one common element.
def common_element(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the median length of a trapezium.
def median_trapezium(base1,base2,height): median = 0.5 * (base1+ base2) return median
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to check whether the entered number is greater than the elements of the given array.
def check_greater(arr, number): arr.sort() return number > arr[-1]
mbpp_sanitized
Write a Python function which follows this instruction: Write a function that matches a string that has an a followed by one or more b's.
import re def text_match_one(text): patterns = 'ab+?' if re.search(patterns, text): return True else: return False
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the last digit of a given number.
def last_Digit(n) : return (n % 10)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to return the negative numbers in a list.
def neg_nos(list1): out = [] for num in list1: if num < 0: out.append(num) return out
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to remove odd characters in a string.
def remove_odd(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 == 0): str2 = str2 + str1[i - 1] return str2
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to count bidirectional tuple pairs.
def count_bidirectional(test_list): res = 0 for idx in range(0, len(test_list)): for iidx in range(idx + 1, len(test_list)): if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]: res += 1 return res
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to join a list of multiple integers into a single integer.
def multiple_to_single(L): x = int("".join(map(str, L))) return x
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the first adverb and their positions in a given sentence.
import re def find_adverb_position(text): for m in re.finditer(r"\w+ly", text): return (m.start(), m.end(), m.group(0))
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the surface area of a cube of a given size.
def surfacearea_cube(l): surfacearea= 6*l*l return surfacearea
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find the ration of positive numbers in an array of integers.
from array import array def positive_count(nums): n = len(nums) n1 = 0 for x in nums: if x > 0: n1 += 1 else: None return round(n1/n,2)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to find the largest negative number from the given list.
def largest_neg(list1): max = list1[0] for x in list1: if x < max : max = x return max
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to trim each tuple by k in the given tuple list.
def trim_tuple(test_list, K): res = [] for ele in test_list: N = len(ele) res.append(tuple(list(ele)[K: N - K])) return (str(res))
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to perform index wise multiplication of tuple elements in the given two tuples.
def index_multiplication(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)
mbpp_sanitized
Write a Python function which follows this instruction: Write a python function to count the occurence of all elements of list in a tuple.
from collections import Counter def count_Occurrence(tup, lst): count = 0 for item in tup: if item in lst: count+= 1 return count
mbpp_sanitized
Write a Python function which follows this instruction: Write a function to find cubes of individual elements in a list.
def cube_nums(nums): cube_nums = list(map(lambda x: x ** 3, nums)) return cube_nums
mbpp_sanitized