description
stringlengths
37
249
code
stringlengths
30
1.33k
normalized_code
stringlengths
19
1.01k
Write a python function to count the number of equal numbers from three given integers.
def test_three_equal(x,y,z): result= set([x,y,z]) if len(result)==3: return 0 else: return (4-len(result))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR
Write a python function to count the number of rotations required to generate a sorted array.
def count_Rotation(arr,n): for i in range (1,n): if (arr[i] < arr[i - 1]): return i return 0
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER
Write a python function to check whether the given number is a perfect square or not.
def is_Perfect_Square(n) : i = 1 while (i * i<= n): if ((n % i == 0) and (n / i == i)): return True i = i + 1 return False
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER
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
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Write a function to find the list in a list of lists whose sum of elements is the highest.
def max_sum_list(lists): return max(lists, key=sum)
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR
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)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR
Write a python function to find the first odd number in a given list of numbers.
def first_odd(nums): first_odd = next((el for el in nums if el%2!=0),-1) return first_odd
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN VAR
Write a function to check if the given tuples contain the k or not.
def check_K(test_tup, K): res = False for ele in test_tup: if ele == K: res = True break return (res)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER RETURN VAR
Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
def check_smaller(test_tup1, test_tup2): res = all(x > y for x, y in zip(test_tup1, test_tup2)) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to iterate over elements repeating each as many times as its count.
from collections import Counter def count_variable(a,b,c,d): c = Counter(p=a, q=b, r=c, s=d) return list(c.elements())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR
Write a function to check if two lists of tuples are identical or not.
def check_identical(test_list1, test_list2): res = test_list1 == test_list2 return (res)
FUNC_DEF ASSIGN VAR VAR VAR RETURN VAR
Write a function to abbreviate 'road' as 'rd.' in a given string.
import re def road_rd(street): return (re.sub('Road$', 'Rd.', street))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING STRING VAR
Write a function to find length of the string.
def string_length(str1): count = 0 for char in str1: count += 1 return count
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER RETURN VAR
Write a function to find the area of a rombus.
def rombus_area(p,q): area=(p*q)/2 return area
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.
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
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Write a function to clear the values of the given tuples.
def clear_tuple(test_tup): temp = list(test_tup) temp.clear() test_tup = tuple(temp) return (test_tup)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Write a function to find numbers divisible by m or n from a list of numbers using lambda function.
def div_of_nums(nums,m,n): result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR RETURN VAR
Write a python function to count lower case letters in a given string.
def lower_ctr(str): lower_ctr= 0 for i in range(len(str)): if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1 return lower_ctr
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER RETURN VAR
Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.
def count_duplic(lists): element = [] frequency = [] if not lists: return element running_count = 1 for i in range(len(lists)-1): if lists[i] == lists[i+1]: running_count += 1 else: frequency.append(running_count) element.append(lists[i]) running_count = 1 frequency.append(running_count) element.append(lists[i+1]) return element,frequency
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST IF VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
Write a function to check whether the given month number contains 28 days or not.
def check_monthnum_number(monthnum1): if monthnum1 == 2: return True else: return False
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a function to merge two dictionaries into a single expression.
import collections as ct def merge_dictionaries(dict1,dict2): merged_dict = dict(ct.ChainMap({}, dict1, dict2)) return merged_dict
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR DICT VAR VAR RETURN VAR
Write a function to return true if the password is valid.
import re def pass_validity(p): x = True while x: if (len(p)<6 or len(p)>12): break elif not re.search("[a-z]",p): break elif not re.search("[0-9]",p): break elif not re.search("[A-Z]",p): break elif not re.search("[$#@]",p): break elif re.search("\s",p): break else: return True x=False break if x: return False
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR RETURN NUMBER
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")
IMPORT FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN STRING RETURN STRING RETURN STRING
Write a python function to remove even numbers from a given list.
def remove_even(l): for i in l: if i % 2 == 0: l.remove(i) return l
FUNC_DEF FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Write a python function to access multiple elements of specified index from a given list.
def access_elements(nums, list_index): result = [nums[i] for i in list_index] return result
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR RETURN VAR
Write a python function to find the type of triangle from the given sides.
def check_Type_Of_Triangle(a,b,c): sqa = pow(a,2) sqb = pow(b,2) sqc = pow(c,2) if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb): return ("Right-angled Triangle") elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb): return ("Obtuse-angled Triangle") else: return ("Acute-angled Triangle")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN STRING IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN STRING RETURN STRING
Write a function to sum a specific column of a list in a given list of lists.
def sum_column(list1, C): result = sum(row[C] for row in list1) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR
Write a function to count alphabets,digits and special charactes in a given string.
def count_alpha_dig_spl(string): alphabets=digits = special = 0 for i in range(len(string)): if(string[i].isalpha()): alphabets = alphabets + 1 elif(string[i].isdigit()): digits = digits + 1 else: special = special + 1 return (alphabets,digits,special)
FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR
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)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR RETURN VAR
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)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
Write a python function to count equal element pairs from the given array.
def count_Pairs(arr,n): cnt = 0; for i in range(n): for j in range(i + 1,n): if (arr[i] == arr[j]): cnt += 1; return cnt;
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR
Write a function to extract the maximum numeric value from a string by using regex.
import re def extract_max(input): numbers = re.findall('\d+',input) numbers = map(int,numbers) return max(numbers)
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR
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
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.
def generate_matrix(n): if n<=0: return [] matrix=[row[:] for row in [[0]*n]*n] row_st=0 row_ed=n-1 col_st=0 col_ed=n-1 current=1 while (True): if current>n*n: break for c in range (col_st, col_ed+1): matrix[row_st][c]=current current+=1 row_st+=1 for r in range (row_st, row_ed+1): matrix[r][col_ed]=current current+=1 col_ed-=1 for c in range (col_ed, col_st-1, -1): matrix[row_ed][c]=current current+=1 row_ed-=1 for r in range (row_ed, row_st-1, -1): matrix[r][col_st]=current current+=1 col_st+=1 return matrix
FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR VAR VAR BIN_OP LIST BIN_OP LIST NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Write a python function to find the slope of a line.
def slope(x1,y1,x2,y2): return (float)(y2-y1)/(x2-x1)
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR
Write a function to find length of the subarray having maximum sum.
from sys import maxsize def max_sub_array_sum(a,size): max_so_far = -maxsize - 1 max_ending_here = 0 start = 0 end = 0 s = 0 for i in range(0,size): max_ending_here += a[i] if max_so_far < max_ending_here: max_so_far = max_ending_here start = s end = i if max_ending_here < 0: max_ending_here = 0 s = i+1 return (end - start + 1)
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER
Write a python function to find the cube sum of first n odd natural numbers.
def cube_Sum(n): sum = 0 for i in range(0,n) : sum += (2*i+1)*(2*i+1)*(2*i+1) return sum
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR
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;
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER
Write a function to sort the tuples alphabetically by the first item of each tuple.
def sort_tuple(tup): n = len(tup) for i in range(n): for j in range(n-i-1): if tup[j][0] > tup[j + 1][0]: tup[j], tup[j + 1] = tup[j + 1], tup[j] return tup
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR
Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.
def Check_Solution(a,b,c): if b == 0: return ("Yes") else: return ("No")
FUNC_DEF IF VAR NUMBER RETURN STRING RETURN STRING
Write a function to count the number of inversions in the given array.
def get_inv_count(arr, n): inv_count = 0 for i in range(n): for j in range(i + 1, n): if (arr[i] > arr[j]): inv_count += 1 return inv_count
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR
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
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR VAR RETURN NUMBER
Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
import heapq def nth_super_ugly_number(n, primes): uglies = [1] def gen(prime): for ugly in uglies: yield ugly * prime merged = heapq.merge(*map(gen, primes)) while len(uglies) < n: ugly = next(merged) if ugly != uglies[-1]: uglies.append(ugly) return uglies[-1]
IMPORT FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF FOR VAR VAR EXPR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER
Write a python function to find the kth element in an array containing odd elements first and then even elements.
def get_Number(n, k): arr = [0] * n; i = 0; odd = 1; while (odd <= n): arr[i] = odd; i += 1; odd += 2; even = 2; while (even <= n): arr[i] = even; i += 1; even += 2; return arr[k - 1];
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER
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;
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER
Write a function to find the minimum number of platforms required for a railway/bus station.
def find_platform(arr, dep, n): arr.sort() dep.sort() plat_needed = 1 result = 1 i = 1 j = 0 while (i < n and j < n): if (arr[i] <= dep[j]): plat_needed+= 1 i+= 1 elif (arr[i] > dep[j]): plat_needed-= 1 j+= 1 if (plat_needed > result): result = plat_needed return result
FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR
Write a python function to copy a list from a singleton tuple.
def lcopy(xs): return xs[:]
FUNC_DEF RETURN VAR
Write a function to find the area of a trapezium.
def area_trapezium(base1,base2,height): area = 0.5 * (base1 + base2) * height return area
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR RETURN VAR
Write a python function to find sum of all prime divisors of a given number.
def Sum(N): SumOfPrimeDivisors = [0]*(N + 1) for i in range(2,N + 1) : if (SumOfPrimeDivisors[i] == 0) : for j in range(i,N + 1,i) : SumOfPrimeDivisors[j] += i return SumOfPrimeDivisors[N]
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR VAR
Write a function to check if a triangle of positive area is possible with the given angles.
def is_triangleexists(a,b,c): if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180): if((a + b)>= c or (b + c)>= a or (a + c)>= b): return True else: return False else: return False
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER
Write a python function to find sum of inverse of divisors.
def Sum_of_Inverse_Divisors(N,Sum): ans = float(Sum)*1.0 /float(N); return round(ans,2);
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER
Write a python function to remove negative numbers from a list.
def remove_negs(num_list): for item in num_list: if item < 0: num_list.remove(item) return num_list
FUNC_DEF FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Write a python function to find sum of odd factors of a number.
import math def sum_of_odd_Factors(n): res = 1 while n % 2 == 0: n = n // 2 for i in range(3,int(math.sqrt(n) + 1)): count = 0 curr_sum = 1 curr_term = 1 while n % i == 0: count+=1 n = n // i curr_term *= i curr_sum += curr_term res *= curr_sum if n >= 2: res *= (1 + n) return res
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR
Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.
import heapq as hq def raw_heap(rawheap): hq.heapify(rawheap) return rawheap
IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR RETURN VAR
Write a python function to check for even parity of a given number.
def check_Even_Parity(x): parity = 0 while (x != 0): x = x & (x - 1) parity += 1 if (parity % 2 == 0): return True else: return False
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER
Write a python function to find minimum adjacent swaps required to sort binary array.
def find_Min_Swaps(arr,n) : noOfZeroes = [0] * n count = 0 noOfZeroes[n - 1] = 1 - arr[n - 1] for i in range(n-2,-1,-1) : noOfZeroes[i] = noOfZeroes[i + 1] if (arr[i] == 0) : noOfZeroes[i] = noOfZeroes[i] + 1 for i in range(0,n) : if (arr[i] == 1) : count = count + noOfZeroes[i] return count
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR
Write a function to list out the list of given strings individually using map function.
def listify_list(list1): result = list(map(list,list1)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR
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
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER
Write a function to generate all sublists of a given list.
from itertools import combinations def sub_lists(my_list): subs = [] for i in range(0, len(my_list)+1): temp = [list(x) for x in combinations(my_list, i)] if len(temp)>0: subs.extend(temp) return subs
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.
import re regex = '[a-zA-z0-9]$' def check_alphanumeric(string): if(re.search(regex, string)): return ("Accept") else: return ("Discard")
IMPORT ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN STRING RETURN STRING
Write a function to find all anagrams of a string in a given list of strings using lambda function.
from collections import Counter def anagram_lambda(texts,str): result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to find the occurrences of n most common words in a given text.
from collections import Counter import re def n_common_words(text,n): words = re.findall('\w+',text) n_common_words= Counter(words).most_common(n) return list(n_common_words)
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR
Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
def find_longest_conseq_subseq(arr, n): ans = 0 count = 0 arr.sort() v = [] v.append(arr[0]) for i in range(1, n): if (arr[i] != arr[i - 1]): v.append(arr[i]) for i in range(len(v)): if (i > 0 and v[i] == v[i - 1] + 1): count += 1 else: count = 1 ans = max(ans, count) return ans
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to find palindromes in a given list of strings using lambda function.
def palindrome_lambda(texts): result = list(filter(lambda x: (x == "".join(reversed(x))), texts)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to print n-times a list using map function.
def ntimes_list(nums,n): result = map(lambda x:n*x, nums) return list(result)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR
Write a function to check whether the given month name contains 31 days or not.
def check_monthnumb(monthname2): if(monthname2=="January" or monthname2=="March"or monthname2=="May" or monthname2=="July" or monthname2=="Augest" or monthname2=="October" or monthname2=="December"): return True else: return False
FUNC_DEF IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN NUMBER
Write a python function to add a minimum number such that the sum of array becomes even.
def min_Num(arr,n): odd = 0 for i in range(n): if (arr[i] % 2): odd += 1 if (odd % 2): return 1 return 2
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a python function to find the length of the last word in a given string.
def length_Of_Last_Word(a): l = 0 x = a.strip() for i in range(len(x)): if x[i] == " ": l = 0 else: l += 1 return l
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER RETURN VAR
Write a function to remove sublists from a given list of lists, which are outside a given range.
def remove_list_range(list1, leftrange, rigthrange): result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)] return result
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR
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)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR
Write a python function to check whether the given strings are rotations of each other or not.
def are_Rotations(string1,string2): size1 = len(string1) size2 = len(string2) temp = '' if size1 != size2: return False temp = string1 + string1 if (temp.count(string2)> 0): return True else: return False
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a function to check if a nested list is a subset of another nested list.
def check_subset(list1,list2): return all(map(list1.__contains__,list2))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR
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)))
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER
Write a python function to check if the string is a concatenation of another string.
def check_Concat(str1,str2): N = len(str1) M = len(str2) if (N % M != 0): return False for i in range(N): if (str1[i] != str2[i % M]): return False return True
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to find the minimum difference in the tuple pairs of given tuples.
def min_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = min(temp) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Write a python function to find lcm of two positive integers.
def lcm(x, y): if x > y: z = x else: z = y while(True): if((z % x == 0) and (z % y == 0)): lcm = z break z += 1 return lcm
FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR
Write a python function to sort the given string.
def sort_String(str) : str = ''.join(sorted(str)) return (str)
FUNC_DEF ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR RETURN VAR
Write a function to check if the given tuple contains only k elements.
def check_tuples(test_tuple, K): res = all(ele in K for ele in test_tuple) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR
Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
import re def text_match(text): patterns = 'a.*?b$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
IMPORT FUNC_DEF ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR RETURN STRING RETURN STRING
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")
FUNC_DEF IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN STRING IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN STRING RETURN STRING
Write a function to find the sum of first even and odd number of a given list.
def sum_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even+first_odd)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR VAR
Write a function to caluclate perimeter of a parallelogram.
def parallelogram_perimeter(b,h): perimeter=2*(b*h) return perimeter
FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR
Write a function to find numbers divisible by m and n from a list of numbers using lambda function.
def div_of_nums(nums,m,n): result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR RETURN VAR
Write a python function to check whether all the bits are within a given range or not.
def all_Bits_Set_In_The_Given_Range(n,l,r): num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) new_num = n & num if (num == new_num): return True return False
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Write a python function to check whether the two given strings are isomorphic to each other or not.
def is_Isomorphic(str1,str2): dict_str1 = {} dict_str2 = {} for i, value in enumerate(str1): dict_str1[value] = dict_str1.get(value,[]) + [i] for j, value in enumerate(str2): dict_str2[value] = dict_str2.get(value,[]) + [j] if sorted(dict_str1.values()) == sorted(dict_str2.values()): return True else: return False
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN NUMBER RETURN NUMBER
Write a function to add all the numbers in a list and divide it with the length of the list.
def sum_num(numbers): total = 0 for x in numbers: total += x return total/len(numbers)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR
Write a python function to check whether the given number is odd or not using bitwise operator.
def is_odd(n) : if (n^1 == n-1) : return True; else : return False;
FUNC_DEF IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a function to substract the elements of the given nested tuples.
def substract_elements(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)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to reverse each list in a given list of lists.
def reverse_list_lists(lists): for l in lists: l.sort(reverse = True) return lists
FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR
Write a python function to find the index of an extra element present in one sorted array.
def find_Extra(arr1,arr2,n) : for i in range(0, n) : if (arr1[i] != arr2[i]) : return i return n
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR RETURN VAR RETURN VAR
Write a python function to check whether the given two numbers have same number of digits or not.
def same_Length(A,B): while (A > 0 and B > 0): A = A / 10; B = B / 10; if (A == 0 and B == 0): return True; return False;
FUNC_DEF WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a function to remove multiple spaces in a string.
import re def remove_spaces(text): return (re.sub(' +',' ',text))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING STRING VAR
Write a python function to get the last element of each sublist.
def Extract(lst): return [item[-1] for item in lst]
FUNC_DEF RETURN VAR NUMBER VAR VAR
Write a function to convert the given string of float type into tuple.
def float_to_tuple(test_str): res = tuple(map(float, test_str.split(', '))) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR
Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
def max_sum_subseq(A): n = len(A) if n == 1: return A[0] look_up = [None] * n look_up[0] = A[0] look_up[1] = max(A[0], A[1]) for i in range(2, n): look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i]) look_up[i] = max(look_up[i], A[i]) return look_up[n - 1]
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER
Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.
def last(n): return n[-1] def sort_list_last(tuples): return sorted(tuples, key=last)
FUNC_DEF RETURN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR
Write a python function to check whether the word is present in a given sentence or not.
def is_Word_Present(sentence,word): s = sentence.split(" ") for i in s: if (i == word): return True return False
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to extract specified number of elements from a given list, which follow each other continuously.
from itertools import groupby def extract_elements(numbers, n): result = [i for i, j in groupby(numbers) if len(list(j)) == n] return result
FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a python function to check whether an array can be sorted or not by picking only the corner elements.
def check(arr,n): g = 0 for i in range(1,n): if (arr[i] - arr[i - 1] > 0 and g == 1): return False if (arr[i] - arr[i] < 0): g = 1 return True
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN NUMBER
Write a function where a string will start with a specific number.
import re def match_num(string): text = re.compile(r"^5") if text.match(string): return True else: return False
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER