Dataset Viewer
Auto-converted to Parquet
anchor
stringclasses
672 values
positive
stringclasses
674 values
negative
stringclasses
674 values
Write a function to calculate the sum of series 1³+2³+3³+….+n³.
import math def sum_series(number): total = 0 total = math.pow((number * (number + 1)) /2, 2) return total
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
Write a function to check if the two given strings are permutations of each other.
def check_permutation(str1, str2): n1=len(str1) n2=len(str2) if(n1!=n2): return False a=sorted(str1) str1=" ".join(a) b=sorted(str2) str2=" ".join(b) for i in range(0, n1, 1): if(str1[i] != str2[i]): return False return True
def Sum_of_Inverse_Divisors(N,Sum): ans = float(Sum)*1.0 /float(N); return round(ans,2);
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]
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)
Write a python function to count the number of digits in factorial of a given number.
import math def find_Digits(n): if (n < 0): return 0; if (n <= 1): return 1; x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0)); return math.floor(x) + 1;
def count_digits(num1,num2): number=num1+num2 count = 0 while(number > 0): number = number // 10 count = count + 1 return count
Write a function to sort a list of tuples using lambda.
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
def series_sum(number): total = 0 total = (number * (number + 1) * (2 * number + 1)) / 6 return total
Write a function to check whether the given amount has no profit and no loss
def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False
def sort_dict_item(test_dict): res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])} return (res)
Write a function to round up a number to specific digits.
import math def round_up(a, digits): n = 10**-digits return round(math.ceil(a / n) * n, digits)
def sum_Of_Subarray_Prod(arr,n): ans = 0 res = 0 i = n - 1 while (i >= 0): incr = arr[i]*(1 + res) ans += incr res = incr i -= 1 return (ans)
Write a function to add a dictionary to the tuple.
def add_dict_to_tuple(test_tup, test_dict): test_tup = list(test_tup) test_tup.append(test_dict) test_tup = tuple(test_tup) return (test_tup)
def answer(L,R): if (2 * L <= R): return (L ,2*L) else: return (-1)
Write a python function to find the difference between sum of even and odd digits.
def is_Diff(n): return (n % 11 == 0)
def max_of_nth(test_list, N): res = max([sub[N] for sub in test_list]) return (res)
Write a function to remove consecutive duplicates of a given list.
from itertools import groupby def consecutive_duplicates(nums): return [key for key, group in groupby(nums)]
def jacobsthal_num(n): dp = [0] * (n + 1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i - 1] + 2 * dp[i - 2] return dp[n]
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
def find_Volume(l,b,h) : return ((l * b * h) / 2)
Write a function to find the nth nonagonal number.
def is_nonagonal(n): return int(n * (7 * n - 5) / 2)
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
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
def sort_dict_item(test_dict): res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])} return (res)
Write a python function to find the smallest missing number from the given array.
def find_First_Missing(array,start,end): if (start > end): return end + 1 if (start != array[start]): return start; mid = int((start + end) / 2) if (array[mid] == mid): return find_First_Missing(array,mid+1,end) return find_First_Missing(array,start,mid)
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+=1 return (next_term == x)
Write a python function to multiply all items in the list.
def multiply_list(items): tot = 1 for x in items: tot *= x return tot
def slope(x1,y1,x2,y2): return (float)(y2-y1)/(x2-x1)
Write a function to find average value of the numbers in a given tuple of tuples.
def average_tuple(nums): result = [sum(x) / len(x) for x in zip(*nums)] return result
def is_upper(string): return (string.upper())
Write a python function to split a string into characters.
def split(word): return [char for char in word]
import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list
Write a python function to find sum of products of all possible subarrays.
def sum_Of_Subarray_Prod(arr,n): ans = 0 res = 0 i = n - 1 while (i >= 0): incr = arr[i]*(1 + res) ans += incr res = incr i -= 1 return (ans)
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)
Write a function to get dictionary keys as a list.
def get_key(dict): list = [] for key in dict.keys(): list.append(key) return list
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
Write a python function to interchange first and last elements in a given list.
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
def count_Char(str,x): count = 0 for i in range(len(str)): if (str[i] == x) : count += 1 n = 10 repititions = n // len(str) count = count * repititions l = n % len(str) for i in range(l): if (str[i] == x): count += 1 return count
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
def find_fixed_point(arr, n): for i in range(n): if arr[i] is i: return i return -1
Write a function to toggle characters case in a string.
def toggle_string(string): string1 = string.swapcase() return string1
def sum_elements(test_tup): res = sum(list(test_tup)) return (res)
Write a function to zip two given lists of lists.
def zip_list(list1,list2): result = list(map(list.__add__, list1, list2)) return result
import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$''' def check_IP(Ip): if(re.search(regex, Ip)): return ("Valid IP address") else: return ("Invalid IP address")
Write a function to multiply two lists using map and lambda function.
def mul_list(nums1,nums2): result = map(lambda x, y: x * y, nums1, nums2) return list(result)
import sys def tuple_size(tuple_list): return (sys.getsizeof(tuple_list))
Write a function to find the nth hexagonal number.
def hexagonal_num(n): return n*(2*n - 1)
def div_of_nums(nums,m,n): result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums)) return result
Write a function to create a new tuple from the given string and list.
def new_tuple(test_list, test_str): res = tuple(test_list + [test_str]) return (res)
def max_run_uppercase(test_str): cnt = 0 res = 0 for idx in range(0, len(test_str)): if test_str[idx].isupper(): cnt += 1 else: res = cnt cnt = 0 if test_str[len(test_str) - 1].isupper(): res = cnt return (res)
Write a python function to find nth number in a sequence which is not a multiple of a given number.
def count_no (A,N,L,R): count = 0 for i in range (L,R + 1): if (i % A != 0): count += 1 if (count == N): break return (i)
def last_Two_Digits(N): if (N >= 10): return fac = 1 for i in range(1,N + 1): fac = (fac * i) % 100 return (fac)
Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.
import heapq def cheap_items(items,n): cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price']) return cheap_items
def count_Fac(n): m = n count = 0 i = 2 while((i * i) <= m): total = 0 while (n % i == 0): n /= i total += 1 temp = 0 j = 1 while((temp + j) <= total): temp += j count += 1 j += 1 i += 1 if (n != 1): count += 1 return count
Write a python function to check whether two given lines are parallel or not.
def parallel_lines(line1, line2): return line1[0]/line1[1] == line2[0]/line2[1]
def max_of_three(num1,num2,num3): if (num1 >= num2) and (num1 >= num3): lnum = num1 elif (num2 >= num1) and (num2 >= num3): lnum = num2 else: lnum = num3 return lnum
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
def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')] tuple1 = [t for t in tuple1 if t] return tuple1
Write a python function to find the digit distance between two integers.
def digit_distance_nums(n1, n2): return sum(map(int,str(abs(n1-n2))))
def check_tuples(test_tuple, K): res = all(ele in K for ele in test_tuple) return (res)
Write a function to calculate the sum of all digits of the base to the specified power.
def power_base_sum(base, power): return sum([int(i) for i in str(pow(base, power))])
from collections import Counter def anagram_lambda(texts,str): result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) return result
Write a function to convert an integer into a roman numeral.
def int_to_roman( num): val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1] syb = ["M", "CM", "D", "CD","C", "XC", "L", "XL","X", "IX", "V", "IV","I"] roman_num = '' i = 0 while num > 0: for _ in range(num // val[i]): roman_num += syb[i] num -= val[i] i += 1 return roman_num
def smallest_Divisor(n): if (n % 2 == 0): return 2; i = 3; while (i*i <= n): if (n % i == 0): return i; i += 2; return n;
Write a function to sort the given array by using counting sort.
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j]): my_list[i] = j i += 1 return my_list
import sys def tuple_size(tuple_list): return (sys.getsizeof(tuple_list))
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))
def list_tuple(listx): tuplex = tuple(listx) return tuplex
Write a python function to find the sum of all even natural numbers within the range l and r.
def sum_Natural(n): sum = (n * (n + 1)) return int(sum) def sum_Even(l,r): return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2)))
def sum_Range_list(nums, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += nums[i] return sum_range
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)
def sum_Range_list(nums, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += nums[i] return sum_range
Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.
def sum_positivenum(nums): sum_positivenum = list(filter(lambda nums:nums>0,nums)) return sum(sum_positivenum)
def check_monthnumber_number(monthnum3): if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11): return True else: return False
Write a function to split the given string with multiple delimiters by using regex.
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: return c return "None"
Write a function to convert tuple to a string.
def tup_string(tup1): str = ''.join(tup1) return str
def access_key(ditionary,key): return list(ditionary)[key]
Write a function to calculate the perimeter of a regular polygon.
from math import tan, pi def perimeter_polygon(s,l): perimeter = s*l return perimeter
from collections import Counter def anagram_lambda(texts,str): result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) return result
Write a function to extract the even elements in the nested mixed tuple.
def even_ele(test_tuple, even_fnc): res = tuple() for ele in test_tuple: if isinstance(ele, tuple): res += (even_ele(ele, even_fnc), ) elif even_fnc(ele): res += (ele, ) return res def extract_even(test_tuple): res = even_ele(test_tuple, lambda x: x % 2 == 0) return (res)
def get_key(dict): list = [] for key in dict.keys(): list.append(key) return list
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
def is_Sub_Array(A,B,n,m): i = 0; j = 0; while (i < n and j < m): if (A[i] == B[j]): i += 1; j += 1; if (j == m): return True; else: i = i - j + 1; j = 0; return False;
Write a function to calculate volume of a tetrahedron.
import math def volume_tetrahedron(num): volume = (num ** 3 / (6 * math.sqrt(2))) return round(volume, 2)
def move_num(test_str): res = '' dig = '' for ele in test_str: if ele.isdigit(): dig += ele else: res += ele res += dig return (res)
Write a function to find the circumference of a circle.
def circle_circumference(r): perimeter=2*3.1415*r return perimeter
def extract_column(list1, n): result = [i.pop(n) for i in list1] return result
Write a function to calculate the sum of series 1³+2³+3³+….+n³.
import math def sum_series(number): total = 0 total = math.pow((number * (number + 1)) /2, 2) return total
import math def count_Divisors(n) : count = 0 for i in range(1, (int)(math.sqrt(n)) + 2) : if (n % i == 0) : if( n // i == i) : count = count + 1 else : count = count + 2 if (count % 2 == 0) : return ("Even") else : return ("Odd")
Write a python function to accept the strings which contains all vowels.
def check(string): if len(set(string).intersection("AEIOUaeiou"))>=5: return ('accepted') else: return ("not accepted")
def list_tuple(listx): tuplex = tuple(listx) return tuplex
Write a python function to count number of substrings with the sum of digits equal to their length.
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
def float_to_tuple(test_str): res = tuple(map(float, test_str.split(', '))) return (res)
Write a function to find whether a given array of integers contains any duplicate element.
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
def is_Sub_Array(A,B,n,m): i = 0; j = 0; while (i < n and j < m): if (A[i] == B[j]): i += 1; j += 1; if (j == m): return True; else: i = i - j + 1; j = 0; return False;
Write a function to check whether the given month number contains 30 days or not.
def check_monthnumber_number(monthnum3): if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11): return True else: return False
def max_sum_pair_diff_lessthan_K(arr, N, K): arr.sort() dp = [0] * N dp[0] = 0 for i in range(1, N): dp[i] = dp[i-1] if (arr[i] - arr[i-1] < K): if (i >= 2): dp[i] = max(dp[i], dp[i-2] + arr[i] + arr[i-1]); else: dp[i] = max(dp[i], arr[i] + arr[i-1]); return dp[N - 1]
Write a function to extract every first or specified element from a given two-dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
def sum_nums(x, y,m,n): sum_nums= x + y if sum_nums in range(m, n): return 20 else: return sum_nums
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
def topbottom_surfacearea(r): toporbottomarea=3.1415*r*r return toporbottomarea
Write a function to extract year, month and date from a url by using regex.
import re def extract_date(url): return re.findall(r'/(\d{4})/(\d{1,2})/(\d{1,2})/', url)
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
Write a function to find the cumulative sum of all the values that are present in the given tuple list.
def cummulative_sum(test_list): res = sum(map(sum, test_list)) return (res)
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
Write a function to calculate volume of a tetrahedron.
import math def volume_tetrahedron(num): volume = (num ** 3 / (6 * math.sqrt(2))) return round(volume, 2)
def digit_distance_nums(n1, n2): return sum(map(int,str(abs(n1-n2))))
Write a function to find the closest smaller number than n.
def closest_num(N): return (N - 1)
def odd_Num_Sum(n) : j = 0 sm = 0 for i in range(1,n + 1) : j = (2*i-1) sm = sm + (j*j*j*j) return sm
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
from collections import defaultdict def grouping_dictionary(l): d = defaultdict(list) for k, v in l: d[k].append(v) return d
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")
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
Write a function to find the circumference of a circle.
def circle_circumference(r): perimeter=2*3.1415*r return perimeter
def min_length(list1): min_length = min(len(x) for x in list1 ) min_list = min((x) for x in list1) return(min_length, min_list)
Write a function to convert an integer into a roman numeral.
def int_to_roman( num): val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1] syb = ["M", "CM", "D", "CD","C", "XC", "L", "XL","X", "IX", "V", "IV","I"] roman_num = '' i = 0 while num > 0: for _ in range(num // val[i]): roman_num += syb[i] num -= val[i] i += 1 return roman_num
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: return False
Write a function to rotate a given list by specified number of items to the right direction.
def rotate_right(list1,m,n): result = list1[-(m):]+list1[:-(n)] return result
def remove_similar_row(test_list): res = set(sorted([tuple(sorted(set(sub))) for sub in test_list])) return (res)
Write a python function to find the largest triangle that can be inscribed in the semicircle.
def triangle_area(r) : if r < 0 : return -1 return r * r
def rombus_area(p,q): area=(p*q)/2 return area
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)
def check(string): if len(set(string).intersection("AEIOUaeiou"))>=5: return ('accepted') else: return ("not accepted")
Write a python function to find number of solutions in quadratic equation.
def Check_Solution(a,b,c) : if ((b*b) - (4*a*c)) > 0 : return ("2 solutions") elif ((b*b) - (4*a*c)) == 0 : return ("1 solution") else : return ("No solutions")
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]
Write a function to find the sequences of one upper case letter followed by lower case letters.
import re def text_uppercase_lowercase(text): patterns = '[A-Z]+[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return ('Not matched!')
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
Write a function to find the n-th rectangular number.
def find_rect_num(n): return n*(n + 1)
import re def text_match_zero_one(text): patterns = 'ab?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
Write a python function to print duplicants from a list of integers.
def Repeat(x): _size = len(x) repeated = [] for i in range(_size): k = i + 1 for j in range(k, _size): if x[i] == x[j] and x[i] not in repeated: repeated.append(x[i]) return repeated
def triangle_area(r) : if r < 0 : return -1 return r * r
Write a function to find perfect squares between two given numbers.
def perfect_squares(a, b): lists=[] for i in range (a,b+1): j = 1; while j*j <= i: if j*j == i: lists.append(i) j = j+1 i = i+1 return lists
import re def replace(string, char): pattern = char + '{2,}' string = re.sub(pattern, char, string) return string
Write a function to count the same pair in two given lists using map function.
from operator import eq def count_same_pair(nums1, nums2): result = sum(map(eq, nums1, nums2)) return result
def sort_by_dnf(arr, n): low=0 mid=0 high=n-1 while mid <= high: if arr[mid] == 0: arr[low], arr[mid] = arr[mid], arr[low] low = low + 1 mid = mid + 1 elif arr[mid] == 1: mid = mid + 1 else: arr[mid], arr[high] = arr[high], arr[mid] high = high - 1 return arr
Write a function to remove the nested record from the given tuple.
def remove_nested(test_tup): res = tuple() for count, ele in enumerate(test_tup): if not isinstance(ele, tuple): res = res + (ele, ) return (res)
def sum_average(number): total = 0 for value in range(1, number + 1): total = total + value average = total / number return (total,average)
Write a python function to shift first element to the end of given list.
def move_last(num_list): a = [num_list[0] for i in range(num_list.count(num_list[0]))] x = [ i for i in num_list if i != num_list[0]] x.extend(a) return (x)
import cmath def len_complex(a,b): cn=complex(a,b) length=abs(cn) return length
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;
def remove_tuple(test_list): res = [sub for sub in test_list if not all(ele == None for ele in sub)] return (str(res))
Write a function to find out the second most repeated (or frequent) string in the given sequence.
from collections import Counter def second_frequent(input): dict = Counter(input) value = sorted(dict.values(), reverse=True) second_large = value[1] for (key, val) in dict.items(): if val == second_large: return (key)
def add_list(nums1,nums2): result = map(lambda x, y: x + y, nums1, nums2) return list(result)
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
def count_Unset_Bits(n) : cnt = 0; for i in range(1,n + 1) : temp = i; while (temp) : if (temp % 2 == 0) : cnt += 1; temp = temp // 2; return cnt;
Write a function to find maximum run of uppercase characters in the given string.
def max_run_uppercase(test_str): cnt = 0 res = 0 for idx in range(0, len(test_str)): if test_str[idx].isupper(): cnt += 1 else: res = cnt cnt = 0 if test_str[len(test_str) - 1].isupper(): res = cnt return (res)
def super_seq(X, Y, m, n): if (not m): return n if (not n): return m if (X[m - 1] == Y[n - 1]): return 1 + super_seq(X, Y, m - 1, n - 1) return 1 + min(super_seq(X, Y, m - 1, n), super_seq(X, Y, m, n - 1))
Write a function to check if the two given strings are permutations of each other.
def check_permutation(str1, str2): n1=len(str1) n2=len(str2) if(n1!=n2): return False a=sorted(str1) str1=" ".join(a) b=sorted(str2) str2=" ".join(b) for i in range(0, n1, 1): if(str1[i] != str2[i]): return False return True
def sort_matrix(M): result = sorted(M, key=sum) return result
Write a function to sort each sublist of strings in a given list of lists.
def sort_sublists(list1): result = list(map(sorted,list1)) return result
def check_isosceles(x,y,z): if x!=y & y!=z & z!=x: return True else: return False
Write a function to find the square root of a perfect number.
import math def sqrt_root(num): sqrt_root = math.pow(num, 0.5) return sqrt_root
def str_to_tuple(test_str): res = tuple(map(int, test_str.split(', '))) return (res)
Write a function to pack consecutive duplicates of a given list elements into sublists.
from itertools import groupby def pack_consecutive_duplicates(list1): return [list(group) for key, group in groupby(list1)]
import cmath def polar_rect(x,y): cn = complex(x,y) cn=cmath.polar(cn) cn1 = cmath.rect(2, cmath.pi) return (cn,cn1)
Write a function to reverse words in a given string.
def reverse_words(s): return ' '.join(reversed(s.split()))
import cmath def angle_complex(a,b): cn=complex(a,b) angle=cmath.phase(a+b) return angle
Write a function to count the most common character in a given string.
from collections import Counter def max_char(str1): temp = Counter(str1) max_char = max(temp, key = temp.get) return max_char
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
Write a python function to find minimum number swaps required to make two binary strings equal.
def min_Swaps(s1,s2) : c0 = 0; c1 = 0; for i in range(len(s1)) : if (s1[i] == '0' and s2[i] == '1') : c0 += 1; elif (s1[i] == '1' and s2[i] == '0') : c1 += 1; result = c0 // 2 + c1 // 2; if (c0 % 2 == 0 and c1 % 2 == 0) : return result; elif ((c0 + c1) % 2 == 0) : return result + 2; else : return -1;
def alternate_elements(list1): result=[] for item in list1[::2]: result.append(item) return result
Write a python function to set the right most unset bit.
import math def get_Pos_Of_Right_most_Set_Bit(n): return int(math.log2(n&-n)+1) def set_Right_most_Unset_Bit(n): if (n == 0): return 1 if ((n & (n + 1)) == 0): return n pos = get_Pos_Of_Right_most_Set_Bit(~n) return ((1 << (pos - 1)) | n)
import re def text_match(text): patterns = 'ab*?' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
Write a function to count number of lists in a given list of lists and square the count.
def count_list(input_list): return (len(input_list))**2
from collections import deque def check_expression(exp): if len(exp) & 1: return False stack = deque() for ch in exp: if ch == '(' or ch == '{' or ch == '[': stack.append(ch) if ch == ')' or ch == '}' or ch == ']': if not stack: return False top = stack.pop() if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')): return False return not stack
Write a function to sort the given array by using heap sort.
def heap_sort(arr): heapify(arr) end = len(arr) - 1 while end > 0: arr[end], arr[0] = arr[0], arr[end] shift_down(arr, 0, end - 1) end -= 1 return arr def heapify(arr): start = len(arr) // 2 while start >= 0: shift_down(arr, start, len(arr) - 1) start -= 1 def shift_down(arr, start, end): root = start while root * 2 + 1 <= end: child = root * 2 + 1 if child + 1 <= end and arr[child] < arr[child + 1]: child += 1 if child <= end and arr[root] < arr[child]: arr[root], arr[child] = arr[child], arr[root] root = child else: return
import math def find_Digits(n): if (n < 0): return 0; if (n <= 1): return 1; x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0)); return math.floor(x) + 1;
Write a function to remove characters from the first string which are present in the second string.
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind+=1 return lst_to_string(str_list[0:res_ind])
def access_key(ditionary,key): return list(ditionary)[key]
Write a python function to find sum of product of binomial co-efficients.
def binomial_Coeff(n,k): C = [0] * (k + 1); C[0] = 1; # nC0 is 1 for i in range(1,n + 1): for j in range(min(i, k),0,-1): C[j] = C[j] + C[j - 1]; return C[k]; def sum_Of_product(n): return binomial_Coeff(2 * n,n - 1);
def is_Word_Present(sentence,word): s = sentence.split(" ") for i in s: if (i == word): return True return False
Write a function to zip the two given tuples.
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
def find_Points(l1,r1,l2,r2): x = min(l1,l2) if (l1 != l2) else -1 y = max(r1,r2) if (r1 != r2) else -1 return (x,y)
Write a function to solve the fibonacci sequence using recursion.
def fibonacci(n): if n == 1 or n == 2: return 1 else: return (fibonacci(n - 1) + (fibonacci(n - 2)))
import math def radian_degree(degree): radian = degree*(math.pi/180) return radian
Write a python function to find the last two digits in factorial of a given number.
def last_Two_Digits(N): if (N >= 10): return fac = 1 for i in range(1,N + 1): fac = (fac * i) % 100 return (fac)
def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate
Write a python function to find even numbers from a mixed list.
def Split(list): ev_li = [] for i in list: if (i % 2 == 0): ev_li.append(i) return ev_li
def discriminant_value(x,y,z): discriminant = (y**2) - (4*x*z) if discriminant > 0: return ("Two solutions",discriminant) elif discriminant == 0: return ("one solution",discriminant) elif discriminant < 0: return ("no real solution",discriminant)
Write a function to get a lucid number smaller than or equal to n.
def get_ludic(n): ludics = [] for i in range(1, n + 1): ludics.append(i) index = 1 while(index != len(ludics)): first_ludic = ludics[index] remove_index = index + first_ludic while(remove_index < len(ludics)): ludics.remove(ludics[remove_index]) remove_index = remove_index + first_ludic - 1 index += 1 return ludics
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
Write a python function to check whether the product of numbers is even or not.
def is_Product_Even(arr,n): for i in range(0,n): if ((arr[i] & 1) == 0): return True return False
def max_sum_pair_diff_lessthan_K(arr, N, K): arr.sort() dp = [0] * N dp[0] = 0 for i in range(1, N): dp[i] = dp[i-1] if (arr[i] - arr[i-1] < K): if (i >= 2): dp[i] = max(dp[i], dp[i-2] + arr[i] + arr[i-1]); else: dp[i] = max(dp[i], arr[i] + arr[i-1]); return dp[N - 1]
Write a function to find the number which occurs for odd number of times in the given array.
def get_odd_occurence(arr, arr_size): for i in range(0, arr_size): count = 0 for j in range(0, arr_size): if arr[i] == arr[j]: count += 1 if (count % 2 != 0): return arr[i] return -1
def max_sum_increasing_subsequence(arr, n): max = 0 msis = [0 for x in range(n)] for i in range(n): msis[i] = arr[i] for i in range(1, n): for j in range(i): if (arr[i] > arr[j] and msis[i] < msis[j] + arr[i]): msis[i] = msis[j] + arr[i] for i in range(n): if max < msis[i]: max = msis[i] return max
Write a python function to find the minimun number of subsets with distinct elements.
def subset(ar, n): res = 0 ar.sort() for i in range(0, n) : count = 1 for i in range(n - 1): if ar[i] == ar[i + 1]: count+=1 else: break res = max(res, count) return res
def area_trapezium(base1,base2,height): area = 0.5 * (base1 + base2) * height return area
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)
def previous_palindrome(num): for x in range(num-1,0,-1): if str(x) == str(x)[::-1]: return x
Write a function to zip two given lists of lists.
def zip_list(list1,list2): result = list(map(list.__add__, list1, list2)) return result
import math def get_First_Set_Bit_Pos(n): return math.log2(n&-n)+1
Write a function to find the fixed point in the given array.
def find_fixed_point(arr, n): for i in range(n): if arr[i] is i: return i return -1
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
Write a function to check if the given string starts with a substring using regex.
import re def check_substring(string, sample) : if (sample in string): y = "\A" + sample x = re.search(y, string) if x : return ("string starts with the given substring") else : return ("string doesnt start with the given substring") else : return ("entered string isnt a substring")
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+=1 return (next_term == x)
Write a python function to find the product of non-repeated elements in a given array.
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
def concatenate_strings(test_tup1, test_tup2): res = tuple(ele1 + ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
End of preview. Expand in Data Studio

Description

This dataset has been built from the MBPP dataset for fine tuning dense retrieval models. The dataset was created by using the first 70% points from the MBPP dataset. We created triplets corresponding to all negatives for a positive pair. Hence there are n * (n - 1) triplets for n pairs(since we have n-1 negative examples for every anchor-positive pair). Using a random seed of 10, we split these triplets into train and test subsest with a 70:30 ratio.

Fields

  1. anchor - The question corresponding to a code snippet
  2. positive - The ground truth answer for the corresponding question
  3. negative - Any other code snippet from the dataset not corresponding to the question
Downloads last month
4