description
stringlengths
37
249
code
stringlengths
30
1.33k
normalized_code
stringlengths
19
1.01k
Write a python function to find common divisor between two numbers in a given pair.
def ngcd(x,y): i=1 while(i<=x and i<=y): if(x%i==0 and y%i == 0): gcd=i; i+=1 return gcd; def num_comm_div(x,y): n = ngcd(x,y) result = 0 z = int(n**0.5) i = 1 while(i <= z): if(n % i == 0): result += 2 if(i == n/i): result-=1 i+=1 return result
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Write a python function to find remainder of two numbers.
def find(n,m): r = n%m return (r)
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR
Write a function to add consecutive numbers of a given list.
def add_consecutive_nums(nums): result = [b+a for a, b in zip(nums[:-1], nums[1:])] return result
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR
Write a python function to find the cube sum of first n natural numbers.
def sum_Of_Series(n): sum = 0 for i in range(1,n + 1): sum += i * i*i return sum
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR
Write a function to move all zeroes to the end of the given array.
def re_order(A): k = 0 for i in A: if i: A[k] = i k = k + 1 for i in range(k, len(A)): A[i] = 0 return A
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR
Write a function to calculate the permutation coefficient of given p(n, k).
def permutation_coefficient(n, k): P = [[0 for i in range(k + 1)] for j in range(n + 1)] for i in range(n + 1): for j in range(min(i, k) + 1): if (j == 0): P[i][j] = 1 else: P[i][j] = P[i - 1][j] + ( j * P[i - 1][j - 1]) if (j < k): P[i][j + 1] = 0 return P[n][k]
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Write a function to remove specific words from a given list.
def remove_words(list1, removewords): for word in list(list1): if word in removewords: list1.remove(word) return list1
FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Write a function to check if the common elements between two given lists are in the same order or not.
def same_order(l1, l2): common_elements = set(l1) & set(l2) l1 = [e for e in l1 if e in common_elements] l2 = [e for e in l2 if e in common_elements] return l1 == l2
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR VAR
Write a python function to find the average of odd numbers till a given odd number.
def average_Odd(n) : if (n%2==0) : return ("Invalid Input") return -1 sm =0 count =0 while (n>=1) : count=count+1 sm = sm + n n = n-2 return sm//count
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR
Write a function to find the number of subsequences having product smaller than k for the given non negative array.
def no_of_subsequences(arr, k): n = len(arr) dp = [[0 for i in range(n + 1)] for j in range(k + 1)] for i in range(1, k + 1): for j in range(1, n + 1): dp[i][j] = dp[i][j - 1] if arr[j - 1] <= i and arr[j - 1] > 0: dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1 return dp[k][n]
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR VAR
Write a python function to find minimum sum of factors of a given number.
def find_Min_Sum(num): sum = 0 i = 2 while(i * i <= num): while(num % i == 0): sum += i num /= i i += 1 sum += num return sum
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR
Write a function to count the element frequency in the mixed nested tuple.
def flatten(test_tuple): for tup in test_tuple: if isinstance(tup, tuple): yield from flatten(tup) else: yield tup def count_element_freq(test_tuple): res = {} for ele in flatten(test_tuple): if ele not in res: res[ele] = 0 res[ele] += 1 return (res)
FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR VAR FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR
Write a function to convert tuple into list by adding the given string after every element.
def add_str(test_tup, K): res = [ele for sub in test_tup for ele in (sub, K)] return (res)
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR RETURN VAR
Write a function to find the summation of tuple elements in the given tuple list.
def sum_elements(test_tup): res = sum(list(test_tup)) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR
Write a function to check if there is a subset with sum divisible by m.
def modular_sum(arr, n, m): if (n > m): return True DP = [False for i in range(m)] for i in range(n): if (DP[0]): return True temp = [False for i in range(m)] for j in range(m): if (DP[j] == True): if (DP[(j + arr[i]) % m] == False): temp[(j + arr[i]) % m] = True for j in range(m): if (temp[j]): DP[j] = True DP[arr[i] % m] = True return DP[0]
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR NUMBER
Write a function to sort a list of elements using radix sort.
def radix_sort(nums): RADIX = 10 placement = 1 max_digit = max(nums) while placement < max_digit: buckets = [list() for _ in range( RADIX )] for i in nums: tmp = int((i / placement) % RADIX) buckets[tmp].append(i) a = 0 for b in range( RADIX ): buck = buckets[b] for i in buck: nums[a] = i a += 1 placement *= RADIX return nums
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR
Write a python function to find the largest postive number from the given list.
def largest_pos(list1): max = list1[0] for x in list1: if x > max : max = x return max
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR
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
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR
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)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER
Write a function to find the lcm of the given array elements.
def find_lcm(num1, num2): if(num1>num2): num = num1 den = num2 else: num = num2 den = num1 rem = num % den while (rem != 0): num = den den = rem rem = num % den gcd = den lcm = int(int(num1 * num2)/int(gcd)) return lcm def get_lcm(l): num1 = l[0] num2 = l[1] lcm = find_lcm(num1, num2) for i in range(2, len(l)): lcm = find_lcm(lcm, l[i]) return lcm
FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a function to print check if the triangle is scalene or not.
def check_isosceles(x,y,z): if x!=y & y!=z & z!=x: return True else: return False
FUNC_DEF IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to find the longest bitonic subsequence for the given array.
def lbs(arr): n = len(arr) lis = [1 for i in range(n+1)] for i in range(1 , n): for j in range(0 , i): if ((arr[i] > arr[j]) and (lis[i] < lis[j] +1)): lis[i] = lis[j] + 1 lds = [1 for i in range(n+1)] for i in reversed(range(n-1)): for j in reversed(range(i-1 ,n)): if(arr[i] > arr[j] and lds[i] < lds[j] + 1): lds[i] = lds[j] + 1 maximum = lis[0] + lds[0] - 1 for i in range(1 , n): maximum = max((lis[i] + lds[i]-1), maximum) return maximum
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR RETURN VAR
Write a function to check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda function.
def check_string(str1): messg = [ lambda str1: any(x.isupper() for x in str1) or 'String must have 1 upper case character.', lambda str1: any(x.islower() for x in str1) or 'String must have 1 lower case character.', lambda str1: any(x.isdigit() for x in str1) or 'String must have 1 number.', lambda str1: len(str1) >= 7 or 'String length should be atleast 8.',] result = [x for x in [i(str1) for i in messg] if x != True] if not result: result.append('Valid string.') return result
FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN VAR
Write a function to find the sum of maximum increasing subsequence of the given array.
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
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR
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]
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
Write a python function to capitalize first and last letters of each word of a given string.
def capitalize_first_last_letters(str1): str1 = result = str1.title() result = "" for word in str1.split(): result += word[:-1] + word[-1].upper() + " " return result[:-1]
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER STRING RETURN VAR NUMBER
Write a function to find all pairs in an integer array whose sum is equal to a given number.
def get_pairs_count(arr, n, sum): count = 0 for i in range(0, n): for j in range(i + 1, n): if arr[i] + arr[j] == sum: count += 1 return count
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR
Write a function to find the list of lists with minimum length.
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)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Write a function to find the nth jacobsthal-lucas number.
def jacobsthal_lucas(n): dp=[0] * (n + 1) dp[0] = 2 dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i - 1] + 2 * dp[i - 2]; return dp[n]
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR
Write a function to find the ration of negative numbers in an array of integers.
from array import array def negative_count(nums): n = len(nums) n1 = 0 for x in nums: if x < 0: n1 += 1 else: None return round(n1/n,2)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER EXPR NONE RETURN FUNC_CALL VAR BIN_OP VAR VAR NUMBER
Write a function to find minimum number of coins that make a given value.
import sys def min_coins(coins, m, V): if (V == 0): return 0 res = sys.maxsize for i in range(0, m): if (coins[i] <= V): sub_res = min_coins(coins, m, V-coins[i]) if (sub_res != sys.maxsize and sub_res + 1 < res): res = sub_res + 1 return res
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
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
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to remove particular data type elements from the given tuple.
def remove_datatype(test_tuple, data_type): res = [] for ele in test_tuple: if not isinstance(ele, data_type): res.append(ele) return (res)
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs.
import re def search_literal(pattern,text): match = re.search(pattern, text) s = match.start() e = match.end() return (s, e)
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR RETURN VAR VAR
Write a function to find the top or bottom surface area of a cylinder.
def topbottom_surfacearea(r): toporbottomarea=3.1415*r*r return toporbottomarea
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR
Write a function to select the nth items of a list.
def nth_items(list,n): return list[::n]
FUNC_DEF RETURN VAR VAR
Write a python function to find the first repeated word in a given string.
def first_repeated_word(str1): temp = set() for word in str1.split(): if word in temp: return word; else: temp.add(word) return 'None'
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR RETURN STRING
Write a python function to convert a given string list to a tuple.
def string_list_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR RETURN VAR
Write a function to create a list containing the power of said number in bases raised to the corresponding number in the index using map function.
def basesnum_coresspondingnum(bases_num,index): result = list(map(pow, bases_num, index)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a python function to find the difference between highest and least frequencies in a given array.
def find_Diff(arr,n): arr.sort() count = 0; max_count = 0; min_count = n for i in range(0,(n-1)): if arr[i] == arr[i + 1]: count += 1 continue else: max_count = max(max_count,count) min_count = min(min_count,count) count = 0 return max_count - min_count
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN BIN_OP VAR VAR
Write a function to find if the given number is abundant or not.
import math def get_sum(n): sum = 0 i = 1 while i <= (math.sqrt(n)): if n%i == 0: if n/i == i : sum = sum + i else: sum = sum + i sum = sum + (n / i ) i = i + 1 sum = sum - n return sum def check_abundant(n): if (get_sum(n) > n): return True else: return False
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to replace all occurrences of spaces, commas, or dots with a colon in the given string by using regex.
import re def fill_spaces(text): return (re.sub("[ ,.]", ":", text))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING STRING VAR
Write a function to add two numbers and print number of digits of sum.
def count_digits(num1,num2): number=num1+num2 count = 0 while(number > 0): number = number // 10 count = count + 1 return count
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Write a function to flatten the tuple list to a string.
def flatten_tuple(test_list): res = ' '.join([idx for tup in test_list for idx in tup]) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR VAR RETURN VAR
Write a python function to toggle only first and last bits of a given number.
def take_L_and_F_set_bits(n) : n = n | n >> 1 n = n | n >> 2 n = n | n >> 4 n = n | n >> 8 n = n | n >> 16 return ((n + 1) >> 1) + 1 def toggle_F_and_L_bits(n) : if (n == 1) : return 0 return n ^ take_L_and_F_set_bits(n)
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR
Write a function to find the last occurrence of a character in a string.
def last_occurence_char(string,char): flag = -1 for i in range(len(string)): if(string[i] == char): flag = i if(flag == -1): return None else: return flag + 1
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NONE RETURN BIN_OP VAR NUMBER
Write a python function to find the sum of hamming distances of all consecutive numbers from o to n.
def Total_Hamming_Distance(n): i = 1 sum = 0 while (n // i > 0): sum = sum + n // i i = i * 2 return sum
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Write a function to find the length of the longest increasing subsequence of the given sequence.
def longest_increasing_subsequence(arr): n = len(arr) longest_increasing_subsequence = [1]*n for i in range (1 , n): for j in range(0 , i): if arr[i] > arr[j] and longest_increasing_subsequence[i]< longest_increasing_subsequence[j] + 1 : longest_increasing_subsequence[i] = longest_increasing_subsequence[j]+1 maximum = 0 for i in range(n): maximum = max(maximum , longest_increasing_subsequence[i]) return maximum
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a python function to find the sum of fifth power of first n odd natural numbers.
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*j) return sm
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR
Write a python function to find the maximum element in a sorted and rotated array.
def find_Max(arr,low,high): if (high < low): return arr[0] if (high == low): return arr[low] mid = low + (high - low) // 2 if (mid < high and arr[mid + 1] < arr[mid]): return arr[mid] if (mid > low and arr[mid] < arr[mid - 1]): return arr[mid - 1] if (arr[low] > arr[mid]): return find_Max(arr,low,mid - 1) else: return find_Max(arr,mid + 1,high)
FUNC_DEF IF VAR VAR RETURN VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
Write a function to extract a specified column from a given nested list.
def extract_column(list1, n): result = [i.pop(n) for i in list1] return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a python function to check whether a given sequence is linear or not.
def Seq_Linear(seq_nums): seq_nums = [seq_nums[x] - seq_nums[x-1] for x in range(1, len(seq_nums))] if len(set(seq_nums)) == 1: return "Linear Sequence" else: return "Non Linear Sequence"
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING
Write a function to convert the given tuple to a floating-point number.
def tuple_to_float(test_tup): res = float('.'.join(str(ele) for ele in test_tup)) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a python function to find odd numbers from a mixed list.
def Split(list): od_li = [] for i in list: if (i % 2 != 0): od_li.append(i) return od_li
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Write a python function to find the difference between sum of cubes of first n natural numbers and the sum of first n natural numbers.
def difference(n) : S = (n*(n + 1))//2; res = S*(S-1); return res;
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR
Write a python function to count the pairs with xor as an odd number.
def find_Odd_Pair(A,N) : oddPair = 0 for i in range(0,N) : for j in range(i+1,N) : if ((A[i] ^ A[j]) % 2 != 0): oddPair+=1 return oddPair
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR
Write a function to toggle characters case in a string.
def toggle_string(string): string1 = string.swapcase() return string1
FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN VAR
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))))
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
Write a function to find the largest sum of contiguous subarray in the given array.
def max_sub_array_sum(a, size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if max_ending_here < 0: max_ending_here = 0 elif (max_so_far < max_ending_here): max_so_far = max_ending_here return max_so_far
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR
Write a function to find the union of elements of the given tuples.
def union_elements(test_tup1, test_tup2): res = tuple(set(test_tup1 + test_tup2)) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR
Write a function to assign with each element, its pair elements from other similar pairs in the given tuple.
def assign_elements(test_list): res = dict() for key, val in test_list: res.setdefault(val, []) res.setdefault(key, []).append(val) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR RETURN VAR
Write a python function to find the maximum length of sublist.
def Find_Max_Length(lst): maxLength = max(len(x) for x in lst ) return maxLength
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Write a function to extract values between quotation marks of a string.
import re def extract_values(text): return (re.findall(r'"(.*?)"', text))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING VAR
Write a python function to count unequal 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 python function to split a string into characters.
def split(word): return [char for char in word]
FUNC_DEF RETURN VAR VAR VAR
Write a function to get the sum of a non-negative integer.
def sum_digits(n): if n == 0: return 0 else: return n % 10 + sum_digits(int(n / 10))
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Write a function to check whether a specified list is sorted or not.
def issort_list(list1): result = all(list1[i] <= list1[i+1] for i in range(len(list1)-1)) return result
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR
Write a function to create a list of empty dictionaries.
def empty_list(length): empty_list = [{} for _ in range(length)] return empty_list
FUNC_DEF ASSIGN VAR DICT VAR FUNC_CALL VAR VAR RETURN VAR
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
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR
Write a function to remove words from a given list of strings containing a character or string.
def remove_words(list1, charlist): new_list = [] for line in list1: new_words = ' '.join([word for word in line.split() if not any([phrase in word for phrase in charlist])]) new_list.append(new_words) return new_list
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Write a function to find maximum possible sum of disjoint pairs for the given array of integers and a number k.
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]
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER
Write a python function to remove two duplicate numbers from a given number of lists.
def two_unique_nums(nums): return [i for i in nums if nums.count(i)==1]
FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR VAR NUMBER
Write a python function to calculate the product of the unique numbers of a given list.
def unique_product(list_data): temp = list(set(list_data)) p = 1 for i in temp: p *= i return p
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR
Write a function to find the surface area of a cylinder.
def surfacearea_cylinder(r,h): surfacearea=((2*3.1415*r*r) +(2*3.1415*r*h)) return surfacearea
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR VAR RETURN VAR
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)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR
Write a python function to check whether an array is subarray of another or not.
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;
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER RETURN NUMBER
Write a python function to find the last digit in factorial of a given number.
def last_Digit_Factorial(n): if (n == 0): return 1 elif (n <= 2): return n elif (n == 3): return 6 elif (n == 4): return 4 else: return 0
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER
Write a function to interleave lists of the same length.
def interleave_lists(list1,list2,list3): result = [el for pair in zip(list1, list2, list3) for el in pair] return result
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR
Write a function to find the dissimilar elements in the given two tuples.
def find_dissimilar(test_tup1, test_tup2): res = tuple(set(test_tup1) ^ set(test_tup2)) return (res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR
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)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR
Write a python function to find the surface area of the square pyramid.
def surface_Area(b,s): return 2 * b * s + pow(b,2)
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER
Write a function to check if a dictionary is empty or not.
def my_dict(dict1): if bool(dict1): return False else: return True
FUNC_DEF IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER
Write a function for nth catalan number.
def catalan_number(num): if num <=1: return 1 res_num = 0 for i in range(num): res_num += catalan_number(i) * catalan_number(num-i-1) return res_num
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Write a function to find all adverbs and their positions in a given sentence by using regex.
import re def find_adverbs(text): for m in re.finditer(r"\w+ly", text): return ('%d-%d: %s' % (m.start(), m.end(), m.group(0)))
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR STRING VAR RETURN BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER
Write a function to find the n - expensive price items from a given dataset using heap queue algorithm.
import heapq def expensive_items(items,n): expensive_items = heapq.nlargest(n, items, key=lambda s: s['price']) return expensive_items
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR STRING RETURN VAR
Write a python function to split the array and add the first part to the end.
def split_Arr(a,n,k): b = a[:k] return (a[k::]+b[::])
FUNC_DEF ASSIGN VAR VAR VAR RETURN BIN_OP VAR VAR VAR
Write a function to convert a list to a tuple.
def list_tuple(listx): tuplex = tuple(listx) return tuplex
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Write a python function to find the difference between largest and smallest value in a given array.
def big_diff(nums): diff= max(nums)-min(nums) return diff
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR
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
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Write a function to convert polar coordinates to rectangular coordinates.
import cmath def polar_rect(x,y): cn = complex(x,y) cn=cmath.polar(cn) cn1 = cmath.rect(2, cmath.pi) return (cn,cn1)
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR RETURN VAR VAR
Write a python function to interchange the first and last elements in a list.
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR RETURN VAR
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);
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER
Write a function to remove leading zeroes from an ip address.
import re def removezero_ip(ip): string = re.sub('\.[0]*', '.', ip) return string
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING STRING VAR RETURN VAR
Write a function to find the difference of first even and odd number of a given list.
def diff_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 python function to count minimum number of swaps required to convert one binary string to another.
def min_Swaps(str1,str2) : count = 0 for i in range(len(str1)) : if str1[i] != str2[i] : count += 1 if count % 2 == 0 : return (count // 2) else : return ("Not Possible")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN STRING
Write a function to find the size of the given tuple.
import sys def tuple_size(tuple_list): return (sys.getsizeof(tuple_list))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR
Write a function to find kth element from the given two sorted arrays.
def find_kth(arr1, arr2, m, n, k): sorted1 = [0] * (m + n) i = 0 j = 0 d = 0 while (i < m and j < n): if (arr1[i] < arr2[j]): sorted1[d] = arr1[i] i += 1 else: sorted1[d] = arr2[j] j += 1 d += 1 while (i < m): sorted1[d] = arr1[i] d += 1 i += 1 while (j < n): sorted1[d] = arr2[j] d += 1 j += 1 return sorted1[k - 1]
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER
Write a function to check whether the given number is armstrong or not.
def armstrong_number(number): sum = 0 times = 0 temp = number while temp > 0: times = times + 1 temp = temp // 10 temp = number while temp > 0: reminder = temp % 10 sum = sum + (reminder ** times) temp //= 10 if number == sum: return True else: return False
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
Write a function to find sum and average of first n natural numbers.
def sum_average(number): total = 0 for value in range(1, number + 1): total = total + value average = total / number return (total,average)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR
Write a python function to check whether the given number is even or not using bitwise operator.
def is_Even(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