description
stringlengths 37
249
| code
stringlengths 30
1.33k
| normalized_code
stringlengths 19
1.01k
|
---|---|---|
Write a function to find the depth of a dictionary. | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER RETURN NUMBER |
Write a python function to find the most significant bit number which is also a set bit. | def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(n / 2);
msb += 1;
return (1 << msb) | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR |
Write a python function to check whether the count of inversion of two types are same or not. | import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
return False
mx = max(mx,a[j - 1])
return True | IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER |
Write a python function to find element at a given index after number of rotations. | def find_Element(arr,ranges,rotations,index) :
for i in range(rotations - 1,-1,-1 ) :
left = ranges[i][0]
right = ranges[i][1]
if (left <= index and right >= index) :
if (index == left) :
index = right
else :
index = index - 1
return arr[index] | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Write a function to match two words from a list of words starting with letter 'p'. | import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups() | IMPORT FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR IF VAR RETURN FUNC_CALL VAR |
Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i . | def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)]
for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
dp[i][j] = dp[i - 1][i] + a[j]
else:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = dp[i - 1][j]
return dp[index][k] | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR |
Write a function to get a colon of a tuple. | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Write a function to find the specified number of largest products from two given lists. | def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR RETURN VAR |
Write a python function to find the maximum of two numbers. | def maximum(a,b):
if a >= b:
return a
else:
return b | FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR |
Write a function to convert a given string to a tuple. | def string_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 python function to set the left most unset bit. | def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos))) | FUNC_DEF IF BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR |
Write a function to find the volume of a cone. | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER VAR VAR VAR VAR RETURN VAR |
Write a python function to print positive numbers in a list. | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN VAR |
Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n. | def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR |
Write a python function to find the first maximum length of even word. | def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while (i < n):
if (str[i] == ' '):
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
currlen = 0
else :
currlen += 1
i += 1
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
if (st == -1):
return "-1"
return str[st: st + maxlen] | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN STRING RETURN VAR VAR BIN_OP VAR VAR |
Write a function to find the index of the last occurrence of a given number in a sorted array. | def find_last_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
left = mid + 1
elif x < A[mid]:
right = mid - 1
else:
left = mid + 1
return result | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Write a function to reflect the modified run-length encoding from a list. | from itertools import groupby
def modified_encode(alist):
def ctr_ele(el):
if len(el)>1: return [len(el), el[0]]
else: return el[0]
return [ctr_ele(list(group)) for key, group in groupby(alist)] | FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST FUNC_CALL VAR VAR VAR NUMBER RETURN VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR |
Write a python function to find the maximum volume of a cuboid with given sum of sides. | def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR |
Write a function to find all five characters long word in the given string by using regex. | import re
def find_long_word(text):
return (re.findall(r"\b\w{5}\b", text)) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING VAR |
Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers. | def sum_difference(n):
sumofsquares = 0
squareofsum = 0
for num in range(1, n+1):
sumofsquares += num * num
squareofsum += num
squareofsum = squareofsum ** 2
return squareofsum - sumofsquares | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR |
Write a function to find the demlo number for the given number. | def find_demlo(s):
l = len(s)
res = ""
for i in range(1,l+1):
res = res + str(i)
for i in range(l-1,0,-1):
res = res + str(i)
return res | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR |
Write a function to find all index positions of the minimum values in a given list. | def position_min(list1):
min_val = min(list1)
min_result = [i for i, j in enumerate(list1) if j == min_val]
return min_result | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Write a function to re-arrange the given array in alternating positive and negative items. | def right_rotate(arr, n, out_of_place, cur):
temp = arr[cur]
for i in range(cur, out_of_place, -1):
arr[i] = arr[i - 1]
arr[out_of_place] = temp
return arr
def re_arrange(arr, n):
out_of_place = -1
for index in range(n):
if (out_of_place >= 0):
if ((arr[index] >= 0 and arr[out_of_place] < 0) or
(arr[index] < 0 and arr[out_of_place] >= 0)):
arr = right_rotate(arr, n, out_of_place, index)
if (index-out_of_place > 2):
out_of_place += 2
else:
out_of_place = - 1
if (out_of_place == -1):
if ((arr[index] >= 0 and index % 2 == 0) or
(arr[index] < 0 and index % 2 == 1)):
out_of_place = index
return arr | FUNC_DEF ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN VAR |
Write a function to extract the sum of alternate chains of tuples. | def sum_of_alternates(test_tuple):
sum1 = 0
sum2 = 0
for idx, ele in enumerate(test_tuple):
if idx % 2:
sum1 += ele
else:
sum2 += ele
return ((sum1),(sum2)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR VAR |
Write a python function to find the minimum number of squares whose sum is equal to a given number. | def get_Min_Squares(n):
if n <= 3:
return n;
res = n
for x in range(1,n + 1):
temp = x * x;
if temp > n:
break
else:
res = min(res,1 + get_Min_Squares(n - temp))
return res; | FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR |
Write a function to get the word with most number of occurrences in the given strings list. | from collections import defaultdict
def most_occurrences(test_list):
temp = defaultdict(int)
for sub in test_list:
for wrd in sub.split():
temp[wrd] += 1
res = max(temp, key=temp.get)
return (str(res)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR |
Write a function to print check if the triangle is isosceles or not. | def check_isosceles(x,y,z):
if x==y or y==z or z==x:
return True
else:
return False | FUNC_DEF IF VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Write a function to rotate a given list by specified number of items to the left direction. | def rotate_left(list1,m,n):
result = list1[m:]+list1[:n]
return result | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR |
Write a python function to count negative numbers in a list. | def neg_count(list):
neg_count= 0
for num in list:
if num <= 0:
neg_count += 1
return neg_count | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR |
Write a function to find all three, four, five characters long words in the given string by using regex. | import re
def find_char(text):
return (re.findall(r"\b\w{3,5}\b", text)) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR STRING VAR |
Write a python function to count unset bits of a given number. | def count_unset_bits(n):
count = 0
x = 1
while(x < n + 1):
if ((x & n) == 0):
count += 1
x = x << 1
return count | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Write a function to count character frequency of a given string. | def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict | FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR |
Write a python function to sort a list according to the second element in sublist. | def Sort(sub_li):
sub_li.sort(key = lambda x: x[1])
return sub_li | FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR |
Write a python function to check whether the triangle is valid or not if sides are given. | def check_Validity(a,b,c):
if (a + b <= c) or (a + c <= b) or (b + c <= a) :
return False
else:
return True | FUNC_DEF IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Write a function to find the sum of arithmetic progression. | def ap_sum(a,n,d):
total = (n * (2 * a + (n - 1) * d)) / 2
return total | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Write a function to check whether the given month name contains 28 days or not. | def check_monthnum(monthname1):
if monthname1 == "February":
return True
else:
return False | FUNC_DEF IF VAR STRING RETURN NUMBER RETURN NUMBER |
Write a function that matches a word at the end of a string, with optional punctuation. | import re
def text_match_word(text):
patterns = '\w+\S*$'
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 count the number of substrings with same first and last characters. | def check_Equality(s):
return (ord(s[0]) == ord(s[len(s) - 1]));
def count_Substring_With_Equal_Ends(s):
result = 0;
n = len(s);
for i in range(n):
for j in range(1,n-i+1):
if (check_Equality(s[i:i+j])):
result+=1;
return result; | FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Write a python function to find the maximum occuring divisor in an interval. | def find_Divisor(x,y):
if (x==y):
return y
return 2 | FUNC_DEF IF VAR VAR RETURN VAR RETURN NUMBER |
Write a python function to find the sum of the three lowest positive numbers from a given list of numbers. | def sum_three_smallest_nums(lst):
return sum(sorted([x for x in lst if x > 0])[:3]) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER |
Write a function to convert the given set into ordered tuples. | def set_to_tuple(s):
t = tuple(sorted(s))
return (t) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Write a function to find the smallest range that includes at-least one element from each of the given arrays. | from heapq import heappop, heappush
class Node:
def __init__(self, value, list_num, index):
self.value = value
self.list_num = list_num
self.index = index
def __lt__(self, other):
return self.value < other.value
def find_minimum_range(list):
high = float('-inf')
p = (0, float('inf'))
pq = []
for i in range(len(list)):
heappush(pq, Node(list[i][0], i, 0))
high = max(high, list[i][0])
while True:
top = heappop(pq)
low = top.value
i = top.list_num
j = top.index
if high - low < p[1] - p[0]:
p = (low, high)
if j == len(list[i]) - 1:
return p
heappush(pq, Node(list[i][j + 1], i, j + 1))
high = max(high, list[i][j + 1]) | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER |
Write a function to calculate the number of digits and letters in a string. | def dig_let(s):
d=l=0
for c in s:
if c.isdigit():
d=d+1
elif c.isalpha():
l=l+1
else:
pass
return (l,d) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Write a python function to find number of elements with odd factors in a given range. | def count_Odd_Squares(n,m):
return int(m**0.5) - int((n-1)**0.5) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER |
Write a function to find the difference between two consecutive numbers in a given list. | def diff_consecutivenums(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 function to find entringer number e(n, k). | def zigzag(n, k):
if (n == 0 and k == 0):
return 1
if (k == 0):
return 0
return zigzag(n, k - 1) + zigzag(n - 1, n - k) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR |
Write a python function to count the number of squares in a rectangle. | def count_Squares(m,n):
if (n < m):
temp = m
m = n
n = temp
return n * (n + 1) * (3 * m - n + 1) // 6 | FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER |
Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values. | def bin_coff(n, r):
val = 1
if (r > (n - r)):
r = (n - r)
for i in range(0, r):
val *= (n - i)
val //= (i + 1)
return val
def find_ways(M):
n = M // 2
a = bin_coff(2 * n, n)
b = a // (n + 1)
return (b) | FUNC_DEF ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR |
Write a python function to check whether the given string is a binary string or not. | def check(string) :
p = set(string)
s = {'0', '1'}
if s == p or p == {'0'} or p == {'1'}:
return ("Yes")
else :
return ("No") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING STRING IF VAR VAR VAR STRING VAR STRING RETURN STRING RETURN STRING |
Write a python function to minimize the length of the string by removing occurrence of only one character. | def minimum_Length(s) :
maxOcc = 0
n = len(s)
arr = [0]*26
for i in range(n) :
arr[ord(s[i]) -ord('a')] += 1
for i in range(26) :
if arr[i] > maxOcc :
maxOcc = arr[i]
return n - maxOcc | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP VAR VAR |
Write a python function to find the first element occurring k times in a given array. | def first_Element(arr,n,k):
count_map = {};
for i in range(0, n):
if(arr[i] in count_map.keys()):
count_map[arr[i]] += 1
else:
count_map[arr[i]] = 1
i += 1
for i in range(0, n):
if (count_map[arr[i]] == k):
return arr[i]
i += 1
return -1 | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR NUMBER RETURN NUMBER |
Write a python function to check whether all the characters in a given string are unique. | def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1,len(str)):
if (str[i] == str[j]):
return False;
return True; | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Write a function to remove a specified column from a given nested list. | def remove_column(list1, n):
for i in list1:
del i[n]
return list1 | FUNC_DEF FOR VAR VAR VAR VAR RETURN VAR |
Write a function to find t-nth term of arithemetic progression. | def tn_ap(a,n,d):
tn = a + (n - 1) * d
return tn | FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR |
Write a python function to count the number of rectangles in a circle of radius r. | def count_Rectangles(radius):
rectangles = 0
diameter = 2 * radius
diameterSquare = diameter * diameter
for a in range(1, 2 * radius):
for b in range(1, 2 * radius):
diagnalLengthSquare = (a * a + b * b)
if (diagnalLengthSquare <= diameterSquare) :
rectangles += 1
return rectangles | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN VAR |
Write a function to find the third angle of a triangle using two angles. | def find_angle(a,b):
c = 180 - (a + b)
return c
| FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR |
Write a function to find the maximum element of all the given tuple records. | def find_max(test_list):
res = max(int(j) for i in test_list for j in i)
return (res) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR |
Write a function to find modulo division of two lists using map and lambda function. | def moddiv_list(nums1,nums2):
result = map(lambda x, y: x % y, nums1, nums2)
return list(result) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR |
Write a python function to check whether one root of the quadratic equation is twice of the other or not. | def Check_Solution(a,b,c):
if (2*b*b == 9*a*c):
return ("Yes");
else:
return ("No"); | FUNC_DEF IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN STRING RETURN STRING |
Write a function to find the n’th carol number. | def get_carol(n):
result = (2**n) - 1
return result * result - 2 | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER |
Write a function to remove empty lists from a given list of lists. | def remove_empty(list1):
remove_empty = [x for x in list1 if x]
return remove_empty | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR RETURN VAR |
Write a python function to find the item with maximum occurrences in a given list. | def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
occu = nums.count(i)
if occu > max_val:
max_val = occu
result = i
return result | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Write a function to add the k elements to each element in the tuple. | def add_K_element(test_list, K):
res = [tuple(j + K for j in sub ) for sub in test_list]
return (res) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR |
Write a function to find the number of flips required to make the given binary string a sequence of alternate characters. | def make_flip(ch):
return '1' if (ch == '0') else '0'
def get_flip_with_starting_charcter(str, expected):
flip_count = 0
for i in range(len( str)):
if (str[i] != expected):
flip_count += 1
expected = make_flip(expected)
return flip_count
def min_flip_to_make_string_alternate(str):
return min(get_flip_with_starting_charcter(str, '0'),get_flip_with_starting_charcter(str, '1')) | FUNC_DEF RETURN VAR STRING STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING |
Write a python function to count the number of digits of a given number. | def count_Digit(n):
count = 0
while n != 0:
n //= 10
count += 1
return count | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR |
Write a python function to find the largest product of the pair of adjacent elements from a given list of integers. | def adjacent_num_product(list_nums):
return max(a*b for a, b in zip(list_nums, list_nums[1:])) | FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER |
Write a function to check if a binary tree is balanced or not. | class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def get_height(root):
if root is None:
return 0
return max(get_height(root.left), get_height(root.right)) + 1
def is_tree_balanced(root):
if root is None:
return True
lh = get_height(root.left)
rh = get_height(root.right)
if (abs(lh - rh) <= 1) and is_tree_balanced(
root.left) is True and is_tree_balanced( root.right) is True:
return True
return False | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF IF VAR NONE RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER |
Write a function to repeat the given tuple n times. | def repeat_tuples(test_tup, N):
res = ((test_tup, ) * N)
return (res) | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Write a function to find the lateral surface area of cuboid | def lateralsurface_cuboid(l,w,h):
LSA = 2*h*(l+w)
return LSA | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR RETURN VAR |
Write a function to sort a tuple by its float element. | def float_sort(price):
float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True)
return float_sort | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR |
Write a function to find the smallest missing element in a sorted array. | def smallest_missing(A, left_element, right_element):
if left_element > right_element:
return left_element
mid = left_element + (right_element - left_element) // 2
if A[mid] == mid:
return smallest_missing(A, mid + 1, right_element)
else:
return smallest_missing(A, left_element, mid - 1) | FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER |
Write a function to sort a given list of elements in ascending order using heap queue algorithm. | import heapq as hq
def heap_assending(nums):
hq.heapify(nums)
s_result = [hq.heappop(nums) for i in range(len(nums))]
return s_result | IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Write a function to find the volume of a cuboid. | def volume_cuboid(l,w,h):
volume=l*w*h
return volume | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR |
Write a function to print all permutations of a given string including duplicates. | def permute_string(str):
if len(str) == 0:
return ['']
prev_list = permute_string(str[1:len(str)])
next_list = []
for i in range(0,len(prev_list)):
for j in range(0,len(str)):
new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]
if new_str not in next_list:
next_list.append(new_str)
return next_list | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Write a function to round the given number to the nearest multiple of a specific number. | def round_num(n,m):
a = (n //m) * m
b = a + m
return (b if n - a > b - n else a) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR |
Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value. | def remove_replica(test_tup):
temp = set()
res = tuple(ele if ele not in temp and not temp.add(ele)
else 'MSP' for ele in test_tup)
return (res) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR STRING VAR VAR RETURN VAR |
Write a python function to remove all occurrences of a character in a given string. | def remove_Char(s,c) :
counts = s.count(c)
s = list(s)
while counts :
s.remove(c)
counts -= 1
s = '' . join(s)
return (s) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR |
Write a python function to shift last element to first position in the given list. | def move_first(test_list):
test_list = test_list[-1:] + test_list[:-1]
return test_list | FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR |
Write a function to find the surface area of a cuboid. | def surfacearea_cuboid(l,w,h):
SA = 2*(l*w + l * h + w * h)
return SA | FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR |
Write a function to generate a two-dimensional array. | def multi_list(rownum,colnum):
multi_list = [[0 for col in range(colnum)] for row in range(rownum)]
for row in range(rownum):
for col in range(colnum):
multi_list[row][col]= row*col
return multi_list
| FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR |
Write a function to sort a list of lists by a given index of the inner list. | from operator import itemgetter
def index_on_inner_list(list_data, index_no):
result = sorted(list_data, key=itemgetter(index_no))
return result | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR |
Write a function to find the number of rotations in a circularly sorted array. | def find_rotation_count(A):
(left, right) = (0, len(A) - 1)
while left <= right:
if A[left] <= A[right]:
return left
mid = (left + right) // 2
next = (mid + 1) % len(A)
prev = (mid - 1 + len(A)) % len(A)
if A[mid] <= A[next] and A[mid] <= A[prev]:
return mid
elif A[mid] <= A[right]:
right = mid - 1
elif A[mid] >= A[left]:
left = mid + 1
return -1 | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER |
Write a python function to toggle all odd bits of a given number. | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while(temp > 0 ) :
if (count % 2 == 0) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR |
Write a python function to find the frequency of the smallest value in a given array. | def frequency_Of_Smallest(n,arr):
mn = arr[0]
freq = 1
for i in range(1,n):
if (arr[i] < mn):
mn = arr[i]
freq = 1
elif (arr[i] == mn):
freq += 1
return freq | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR |
Write a function to find the n'th perrin number using recursion. | def get_perrin(n):
if (n == 0):
return 3
if (n == 1):
return 0
if (n == 2):
return 2
return get_perrin(n - 2) + get_perrin(n - 3) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER |
Write a function to find out the minimum no of swaps required for bracket balancing in the given string. | def swap_count(s):
chars = s
count_left = 0
count_right = 0
swap = 0
imbalance = 0;
for i in range(len(chars)):
if chars[i] == '[':
count_left += 1
if imbalance > 0:
swap += imbalance
imbalance -= 1
elif chars[i] == ']':
count_right += 1
imbalance = (count_right - count_left)
return swap | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Write a python function to check whether the hexadecimal number is even or odd. | def even_or_odd(N):
l = len(N)
if (N[l-1] =='0'or N[l-1] =='2'or
N[l-1] =='4'or N[l-1] =='6'or
N[l-1] =='8'or N[l-1] =='A'or
N[l-1] =='C'or N[l-1] =='E'):
return ("Even")
else:
return ("Odd") | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING RETURN STRING RETURN STRING |
Write a python function to find the highest power of 2 that is less than or equal to n. | def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res; | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN VAR |
Write a function to find the n'th lucas number. | def find_lucas(n):
if (n == 0):
return 2
if (n == 1):
return 1
return find_lucas(n - 1) + find_lucas(n - 2) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER |
Write a function to insert a given string at the beginning of all items in a list. | def add_string(list,string):
add_string=[string.format(i) for i in list]
return add_string | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Write a function to convert more than one list to nested dictionary. | def convert_list_dictionary(l1, l2, l3):
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
return result | FUNC_DEF ASSIGN VAR DICT VAR DICT VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n). | def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.append(max(i, (res[int(i / 2)]
+ res[int(i / 3)] +
res[int(i / 4)]
+ res[int(i / 5)])))
i = i + 1
return res[n] | FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR |
Write a function to find the list with maximum length using lambda function. | def max_length_list(input_list):
max_length = max(len(x) for x in input_list )
max_list = max(input_list, key = lambda i: len(i))
return(max_length, max_list) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR |
Write a function to check if given tuple is distinct or not. | def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return (res) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Write a python function to find the first non-repeated character in a given string. | def first_non_repeating_character(str1):
char_order = []
ctr = {}
for c in str1:
if c in ctr:
ctr[c] += 1
else:
ctr[c] = 1
char_order.append(c)
for c in char_order:
if ctr[c] == 1:
return c
return None | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN NONE |
Write a function to check whether the given string starts and ends with the same character or not using regex. | import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
if(re.search(regex, string)):
return "Valid"
else:
return "Invalid" | IMPORT ASSIGN VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN STRING RETURN STRING |
Write a function to find the median of three specific numbers. | def median_numbers(a,b,c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
return median | FUNC_DEF IF VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR |
Write a function to compute the sum of digits of each number of a given list. | def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit()) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR |
Write a function to perform the mathematical bitwise xor operation across the given tuples. | def bitwise_xor(test_tup1, test_tup2):
res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Write a function to extract the frequency of unique tuples in the given list order irrespective. | def extract_freq(test_list):
res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
return (res) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Subsets and Splits