common_id
stringlengths
5
5
image
stringlengths
24
24
code
stringlengths
43
914
11833
Validation/png/11833.png
def fun151(num): count = 0 i = 1 while i <= num: if num % i == 0: count = count + 1 i = i + 1 return count
11448
Validation/png/11448.png
# Write a function to convert the given tuple to a key-value dictionary using adjacent elements. def tuple_to_dict(test_tup): res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2)) return res
11555
Validation/png/11555.png
# Write a python function to copy a list from a singleton tuple. def lcopy(xs): return xs[:]
11342
Validation/png/11342.png
# Write a python function to find the sum of fourth power of first n even natural numbers. def even_Power_Sum(n): sum = 0 for i in range(1, n + 1): j = 2 * i sum = sum + (j * j * j * j) return sum
11722
Validation/png/11722.png
def fun40(age): if age >= 18: return 'Can vote' else: return 'Cannot vote'
11643
Validation/png/11643.png
# Write a function to calculate the sum of series 1²+2²+3²+….+n². def series_sum(number): total = 0 total = (number * (number + 1) * (2 * number + 1)) / 6 return total
11799
Validation/png/11799.png
def fun117(N): a = 0 b = 1 if N == 1: return a elif N == 2: return b else: for i in range(3, N+1): c = a + b a = b b = c return c
11542
Validation/png/11542.png
# 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
11651
Validation/png/11651.png
# Write a function to combine two given sorted lists using heapq module. from heapq import merge def combine_lists(num1, num2): combine_lists = list(merge(num1, num2)) return combine_lists
11796
Validation/png/11796.png
def fun114(num1, num2): hcf = 0 limit = min(num1, num2) for i in range(1, limit+1): if num1 % i == 0 and num2 % i == 0: hcf = i return hcf
11380
Validation/png/11380.png
# Write a function to find maximum of three numbers. def max_of_three(num1, num2, num3): if (num1 >= num2) and (num1 >= num3): lnum = num1 elif (num2 >= num1) and (num2 >= num3): lnum = num2 else: lnum = num3 return lnum
11876
Validation/png/11876.png
def fun194(string): length = len(string) count = 0 i = 0 while i < length: ascii = ord(string[i]) if ascii >= 48 and ascii <= 57: count = count + 1 i = i + 1 if count > 0: return 'Present' else: return 'Not Present'
11312
Validation/png/11312.png
# Write a function to reverse words in a given string. def reverse_words(s): return " ".join(reversed(s.split()))
11815
Validation/png/11815.png
def fun133(N): sum = 0 for i in range(1, N+1): sum = sum + i * i return sum
11856
Validation/png/11856.png
def fun174(string, char): length = len(string) count = 0 for i in range(length): ch = string[i] if ch == char: count = count + 1 return count
11516
Validation/png/11516.png
# 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
11470
Validation/png/11470.png
# Write a function to check whether the given month number contains 30 days or not. def check_monthnumber_number(monthnum3): if monthnum3 == 4 or monthnum3 == 6 or monthnum3 == 9 or monthnum3 == 11: return True else: return False
11608
Validation/png/11608.png
# 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
11727
Validation/png/11727.png
def fun45(x): if x < 0: return 'Less than zero' else: return 'Greater than or equal to zero'
11612
Validation/png/11612.png
# Write a function to return true if the given number is even else return false. def even_num(x): if x % 2 == 0: return True else: return False
11763
Validation/png/11763.png
def fun81(N): sum = 0 i = 1 while i <= N: sum = sum + i i = i + 2 return sum
11857
Validation/png/11857.png
def fun175(string, char): length = len(string) count = 0 i = 0 while i < length: ch = string[i] if ch == char: count = count + 1 i = i + 1 return count
11536
Validation/png/11536.png
# 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)
11626
Validation/png/11626.png
# Write a function to count coin change. def coin_change(S, m, n): table = [[0 for x in range(m)] for x in range(n + 1)] for i in range(m): table[0][i] = 1 for i in range(1, n + 1): for j in range(m): x = table[i - S[j]][j] if i - S[j] >= 0 else 0 y = table[i][j - 1] if j >= 1 else 0 table[i][j] = x + y return table[n][m - 1]
11461
Validation/png/11461.png
# Write a function to find minimum k records from tuple list. def min_k(test_list, K): res = sorted(test_list, key=lambda x: x[1])[:K] return res
11355
Validation/png/11355.png
# Write a function to split a string at uppercase letters. import re def split_upperstring(text): return re.findall("[A-Z][^A-Z]*", text)
11406
Validation/png/11406.png
# Write a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys. def sort_dict_item(test_dict): res = { key: test_dict[key] for key in sorted(test_dict.keys(), key=lambda ele: ele[1] * ele[0]) } return res
11822
Validation/png/11822.png
def fun140(num): sum = 0 for i in range(1, num): if num % i == 0: sum = sum + i if sum == num: return 'Perfect Number' else: return 'Not a Perfect Number'
11835
Validation/png/11835.png
def fun153(string): length = len(string) new = '' i = 0 while i < length: ch = ord(string[i]) if ch >= 65 and ch <= 90: new = new + chr(ch + 32) else: new = new + chr(ch) i = i + 1 return new
11509
Validation/png/11509.png
# 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)
11791
Validation/png/11791.png
def fun109(num): sum = 0 i = 1 while i <= num: if num % i == 0: sum = sum + i i = i + 1 return sum
11537
Validation/png/11537.png
# 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
11659
Validation/png/11659.png
# Write a function to find the maximum of similar indices in two lists of tuples. def max_similar_indices(test_list1, test_list2): res = [(max(x[0], y[0]), max(x[1], y[1])) for x, y in zip(test_list1, test_list2)] return res
11535
Validation/png/11535.png
# 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
11873
Validation/png/11873.png
def fun191(string): length = len(string) count = 0 for i in range(length): ascii = ord(string[i]) if (ascii >= 65 and ascii <= 90) or (ascii >= 97 and ascii <= 122): count = count + 1 if count > 0: return 'Present' else: return 'Not Present'
11300
Validation/png/11300.png
# 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)
11595
Validation/png/11595.png
# 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
11425
Validation/png/11425.png
# Write a function to calculate the standard deviation. import math import sys def sd_calc(data): n = len(data) if n <= 1: return 0.0 mean, sd = avg_calc(data), 0.0 for el in data: sd += (float(el) - mean) ** 2 sd = math.sqrt(sd / float(n - 1)) return sd def avg_calc(ls): n, mean = len(ls), 0.0 if n <= 1: return ls[0] for el in ls: mean = mean + float(el) mean = mean / float(n) return mean
11492
Validation/png/11492.png
# Write a function to find the product of first even and odd number of a given list. def mul_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
11666
Validation/png/11666.png
# Write a function to convert an integer into a roman numeral. def int_to_roman(num): val = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] syb = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] roman_num = "" i = 0 while num > 0: for _ in range(num // val[i]): roman_num += syb[i] num -= val[i] i += 1 return roman_num
11624
Validation/png/11624.png
# Write a function to find if there is a triplet in the array whose sum is equal to a given value. def find_triplet_array(A, arr_size, sum): for i in range(0, arr_size - 2): for j in range(i + 1, arr_size - 1): for k in range(j + 1, arr_size): if A[i] + A[j] + A[k] == sum: return A[i], A[j], A[k] return True return False
11326
Validation/png/11326.png
# Write a function to divide two lists using map and lambda function. def div_list(nums1, nums2): result = map(lambda x, y: x / y, nums1, nums2) return list(result)
11449
Validation/png/11449.png
# Write a python function to check whether all the characters are same or not. def all_Characters_Same(s): n = len(s) for i in range(1, n): if s[i] != s[0]: return False return True
11788
Validation/png/11788.png
def fun106(a, d, N): sum = 0 term = a i = 1 while i <= N: sum = sum + 1 / term term = term + d i = i + 1 return sum
11617
Validation/png/11617.png
# Write a function to find the previous palindrome of a specified number. def previous_palindrome(num): for x in range(num - 1, 0, -1): if str(x) == str(x)[::-1]: return x
11466
Validation/png/11466.png
# Write a function to count number of unique lists within a list. def unique_sublists(list1): result = {} for l in list1: result.setdefault(tuple(l), list()).append(1) for a, b in result.items(): result[a] = sum(b) return result
11769
Validation/png/11769.png
def fun87(num): ceven = 0 while num != 0: d = num % 10 if d % 2 == 0: ceven = ceven + 1 num = num // 10 return ceven
11692
Validation/png/11692.png
def fun10(radius): area = 3.14 * radius * radius return area
11570
Validation/png/11570.png
# 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)
11527
Validation/png/11527.png
# 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
11500
Validation/png/11500.png
# Write a python function to count the number of lists in a given number of lists. def count_list(input_list): return len(input_list)
11319
Validation/png/11319.png
# Write a function to find the maximum of nth column from the given tuple list. def max_of_nth(test_list, N): res = max([sub[N] for sub in test_list]) return res
11841
Validation/png/11841.png
def fun159(string): length = len(string) count = 0 i = 0 while i < length: ascii = ord(string[i]) if ascii >= 65 and ascii <= 90: count = count + 1 i = i + 1 return count
11388
Validation/png/11388.png
# Write a python function to check whether a sequence of numbers has an increasing trend or not. def increasing_trend(nums): if sorted(nums) == nums: return True else: return False
11770
Validation/png/11770.png
def fun88(num, k): count = 0 while num != 0: d = num % 10 if d == k: count = count + 1 num = num // 10 return count
11375
Validation/png/11375.png
# Write a python function to count number of vowels in the string. def Check_Vow(string, vowels): final = [each for each in string if each in vowels] return len(final)
11855
Validation/png/11855.png
def fun173(string): length = len(string) new = '' i = length - 1 while i >= 0: new = new + string[i] i = i - 1 return new
11700
Validation/png/11700.png
def fun18(length, breadth, height): volume = length * breadth * height return volume
11849
Validation/png/11849.png
def fun167(string): length = len(string) count = 0 i = 0 while i < length: ascii = ord(string[i]) if ascii == 32: count = count + 1 i = i + 1 count = count + 1 return count
11596
Validation/png/11596.png
# 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
11701
Validation/png/11701.png
def fun19(radius, length): sarea = 3.142 * radius * length + 3.142 * radius * radius return sarea
11367
Validation/png/11367.png
# Write a python function to print duplicants from a list of integers. def Repeat(x): _size = len(x) repeated = [] for i in range(_size): k = i + 1 for j in range(k, _size): if x[i] == x[j] and x[i] not in repeated: repeated.append(x[i]) return repeated
11316
Validation/png/11316.png
# Write a python function to find nth bell number. def bell_Number(n): bell = [[0 for i in range(n + 1)] for j in range(n + 1)] bell[0][0] = 1 for i in range(1, n + 1): bell[i][0] = bell[i - 1][i - 1] for j in range(1, i + 1): bell[i][j] = bell[i - 1][j - 1] + bell[i][j - 1] return bell[n][0]
11641
Validation/png/11641.png
# Write a function to convert camel case string to snake case string by using regex. import re def camel_to_snake(text): str1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text) return re.sub("([a-z0-9])([A-Z])", r"\1_\2", str1).lower()
11412
Validation/png/11412.png
# Write a function to calculate the harmonic sum of n-1. def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))
11640
Validation/png/11640.png
# Write a function to remove duplicate words from a given list of strings. def remove_duplic_list(l): temp = [] for x in l: if x not in temp: temp.append(x) return temp
11402
Validation/png/11402.png
# Write a function to extract unique values from the given dictionary values. def extract_unique(test_dict): res = list(sorted({ele for val in test_dict.values() for ele in val})) return res
11793
Validation/png/11793.png
def fun111(base, exp): ans = 1 i = 1 while i <= exp: ans = ans * base i = i + 1 return ans
11507
Validation/png/11507.png
# Write a python function to left rotate the bits of a given number. INT_BITS = 32 def left_Rotate(n, d): return (n << d) | (n >> (INT_BITS - d))
11614
Validation/png/11614.png
# Write a function to extract year, month and date from a url by using regex. import re def extract_date(url): return re.findall(r"/(\d{4})/(\d{1,2})/(\d{1,2})/", url)
11442
Validation/png/11442.png
# Write a python function to find sum of products of all possible subarrays. def sum_Of_Subarray_Prod(arr, n): ans = 0 res = 0 i = n - 1 while i >= 0: incr = arr[i] * (1 + res) ans += incr res = incr i -= 1 return ans
11648
Validation/png/11648.png
# Write a function to sort the given array by using heap sort. def heap_sort(arr): heapify(arr) end = len(arr) - 1 while end > 0: arr[end], arr[0] = arr[0], arr[end] shift_down(arr, 0, end - 1) end -= 1 return arr def heapify(arr): start = len(arr) // 2 while start >= 0: shift_down(arr, start, len(arr) - 1) start -= 1 def shift_down(arr, start, end): root = start while root * 2 + 1 <= end: child = root * 2 + 1 if child + 1 <= end and arr[child] < arr[child + 1]: child += 1 if child <= end and arr[root] < arr[child]: arr[root], arr[child] = arr[child], arr[root] root = child else: return
11320
Validation/png/11320.png
# Write a python function to merge the first and last elements separately in a list of lists. def merge(lst): return [list(ele) for ele in list(zip(*lst))]
11741
Validation/png/11741.png
def fun59(x, y): if x >= 0 and y >= 0: return 'First Quadrant' elif x < 0 and y >= 0: return 'Second Quadrant' elif x < 0 and y < 0: return 'Third Quadrant' else: return 'Fourth Quadrant'
11571
Validation/png/11571.png
# 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
11657
Validation/png/11657.png
# Write a function to sort the given tuple list basis the total digits in tuple. def count_digs(tup): return sum([len(str(ele)) for ele in tup]) def sort_list(test_list): test_list.sort(key=count_digs) return str(test_list)
11620
Validation/png/11620.png
# Write a function to find ln, m lobb number. def binomial_coeff(n, k): C = [[0 for j in range(k + 1)] for i in range(n + 1)] for i in range(0, n + 1): for j in range(0, min(i, k) + 1): if j == 0 or j == i: C[i][j] = 1 else: C[i][j] = C[i - 1][j - 1] + C[i - 1][j] return C[n][k] def lobb_num(n, m): return ((2 * m + 1) * binomial_coeff(2 * n, m + n)) / (m + n + 1)
11389
Validation/png/11389.png
# Write a python function to find the smallest prime divisor of a number. def smallest_Divisor(n): if n % 2 == 0: return 2 i = 3 while i * i <= n: if n % i == 0: return i i += 2 return n
11439
Validation/png/11439.png
# Write a function to find the lateral surface area of a cone. import math def lateralsurface_cone(r, h): l = math.sqrt(r * r + h * h) LSA = math.pi * r * l return LSA
11720
Validation/png/11720.png
def fun38(string): ch = string[-1] return ch
11805
Validation/png/11805.png
def fun123(a, d, N): term = a for i in range(1, N): term = term + d term = 1 / term return term
11521
Validation/png/11521.png
# Write a function to find length of the string. def string_length(str1): count = 0 for char in str1: count += 1 return count
11749
Validation/png/11749.png
def fun67(ch): ascii = ord(ch) if (ascii >= 65 and ascii <= 90) or (ascii >= 97 and ascii <= 122): return 'Alphabet' else: return 'Not an alphabet'
11858
Validation/png/11858.png
def fun176(string, char): length = len(string) count = 0 for i in range(length): ch = string[i] if ch == char: count = count + 1 if count > 0: return 'Present' else: return 'Not Present'
11370
Validation/png/11370.png
# Write a function to sort a list in a dictionary. def sorted_dict(dict1): sorted_dict = {x: sorted(y) for x, y in dict1.items()} return sorted_dict
11427
Validation/png/11427.png
# Write a function that matches a string that has an a followed by zero or more b's. import re def text_match(text): patterns = "ab*?" if re.search(patterns, text): return "Found a match!" else: return "Not matched!"
11745
Validation/png/11745.png
def fun63(ch): ascii = ord(ch) if ascii >= 65 and ascii <= 90: return 'Upper case' else: return 'Lower case'
11829
Validation/png/11829.png
def fun147(num, k): count = 0 while num != 0: digit = num % 10 if digit == k: count = count + 1 num = num // 10 if count > 0: return 'Present' else: return 'Not Present'
11405
Validation/png/11405.png
# Write a function to find number of even elements in the given list using lambda function. def count_even(array_nums): count_even = len(list(filter(lambda x: (x % 2 == 0), array_nums))) return count_even
11514
Validation/png/11514.png
# 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
11458
Validation/png/11458.png
# Write a function to add the given tuple to the given list. def add_tuple(test_list, test_tup): test_list += test_tup return test_list
11432
Validation/png/11432.png
# Write a function to calculate the sum of all digits of the base to the specified power. def power_base_sum(base, power): return sum([int(i) for i in str(pow(base, power))])
11504
Validation/png/11504.png
# Write function to find the sum of all items in the given dictionary. def return_sum(dict): sum = 0 for i in dict.values(): sum = sum + i return sum
11731
Validation/png/11731.png
def fun49(num, k): if num % k == 0: return 'It is a factor' else: return 'It is not a factor'
11697
Validation/png/11697.png
def fun15(radius): volume = (4 * 3.142 * radius * radius * radius) / 3 return volume
11546
Validation/png/11546.png
# 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
11498
Validation/png/11498.png
# Write a python function to check whether every even index contains even numbers of a given list. def even_position(nums): return all(nums[i] % 2 == i % 2 for i in range(len(nums)))
11511
Validation/png/11511.png
# 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
11777
Validation/png/11777.png
def fun95(a, b): sum = 0 for i in range(a, b+1): if i % 2 != 0: sum = sum + i return sum
11552
Validation/png/11552.png
# 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]