common_id
stringlengths
5
5
image
stringlengths
24
24
code
stringlengths
43
914
11863
Validation/png/11863.png
def fun181(string, char): length = len(string) index = -1 i = 0 while i < length: ch = string[i] if ch == char: index = i i = i + 1 return index
11338
Validation/png/11338.png
# Write a function to extract all the adjacent coordinates of the given coordinate tuple. def adjac(ele, sub=[]): if not ele: yield sub else: yield from [ idx for j in range(ele[0] - 1, ele[0] + 2) for idx in adjac(ele[1:], sub + [j]) ] def get_coordinates(test_tup): res = list(adjac(test_tup)) return res
11457
Validation/png/11457.png
# Write a function to sort a given list of strings of numbers numerically. def sort_numeric_strings(nums_str): result = [int(x) for x in nums_str] result.sort() return result
11735
Validation/png/11735.png
def fun53(len1, len2, len3): if len1 + len2 > len3 and len2 + len3 > len1 and len1 + len3 > len2: return 'VALID TRIANGLE' else: return 'NOT A VALID TRIANGLE'
11871
Validation/png/11871.png
def fun189(string): length = len(string) new = '' for i in range(length - 1, -1, -1): new = new + string[i] if string == new: return 'Palindrome string' else: return 'Not a Palindrome string'
11454
Validation/png/11454.png
# Write a function to find area of a sector. def sector_area(r, a): pi = 22 / 7 if a >= 360: return None sectorarea = (pi * r**2) * (a / 360) return sectorarea
11821
Validation/png/11821.png
def fun139(num): if num == 0: return 'Tribonacci Number' elif num == 1: return 'Tribonacci Number' elif num == 2: return 'Tribonacci Number' else: a = 0 b = 1 c = 2 d = 0 while d < num: c = a + b + c a = b b = c c = d if d == num: return 'Fibonacci Number' else: return 'Not a Fibonacci Number'
11708
Validation/png/11708.png
def fun26(cm): m = cm / 100 return m
11655
Validation/png/11655.png
# Write a python function to find the length of the shortest word. def len_log(list1): min = len(list1[0]) for i in list1: if len(i) < min: min = len(i) return min
11686
Validation/png/11686.png
def fun4(p, q): s = (p - q) + (p + q) + (q + 1) * (p + 1) return s
11343
Validation/png/11343.png
# Write a function to push all values into a heap and then pop off the smallest values one at a time. import heapq as hq def heap_sort(iterable): h = [] for value in iterable: hq.heappush(h, value) return [hq.heappop(h) for i in range(len(h))]
11298
Validation/png/11298.png
# 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)
11732
Validation/png/11732.png
def fun50(year): if year % 100 == 0 and year % 400 == 0: return 'LEAP YEAR' elif year % 4 == 0: return 'LEAP YEAR' else: return 'NOT A LEAP YEAR'
11378
Validation/png/11378.png
# Write a python function to check whether a sequence of numbers has a decreasing trend or not. def decreasing_trend(nums): if sorted(nums) == nums: return True else: return False
11744
Validation/png/11744.png
def fun62(a, b, c): d = b * b - 4 * a * c if d > 0: return 'Roots are real and different' elif d < 0: return 'Roots are complex and different' else: return 'Roots are real and equal'
11830
Validation/png/11830.png
def fun148(num): flag = True while num != 0: digit = num % 10 if digit > 1: flag = False num = num // 10 if flag == True: return 'Valid' else: return 'Invalid'
11766
Validation/png/11766.png
def fun84(num): rev = 0 while num != 0: d = num % 10 rev = rev * 10 + d num = num // 10 return rev
11559
Validation/png/11559.png
# Write a python function to find sum of inverse of divisors. def Sum_of_Inverse_Divisors(N, Sum): ans = float(Sum) * 1.0 / float(N) return round(ans, 2)
11468
Validation/png/11468.png
# Write a python function to check whether an array contains only one distinct element or not. def unique_Element(arr, n): s = set(arr) if len(s) == 1: return "YES" else: return "NO"
11676
Validation/png/11676.png
# Write a python function to find maximum possible value for the given periodic function. def floor_Max(A, B, N): x = min(B - 1, N) return (A * x) // B
11438
Validation/png/11438.png
# Write a function to remove consecutive duplicates of a given list. from itertools import groupby def consecutive_duplicates(nums): return [key for key, group in groupby(nums)]
11369
Validation/png/11369.png
# Write a function to find the maximum sum that can be formed which has no three consecutive elements present. def max_sum_of_three_consecutive(arr, n): sum = [0 for k in range(n)] if n >= 1: sum[0] = arr[0] if n >= 2: sum[1] = arr[0] + arr[1] if n > 2: sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) for i in range(3, n): sum[i] = max( max(sum[i - 1], sum[i - 2] + arr[i]), arr[i] + arr[i - 1] + sum[i - 3] ) return sum[n - 1]
11825
Validation/png/11825.png
def fun143(num): count = 0 i = 1 while i <= num: if num % i == 0: count = count + 1 i = i + 1 if count == 2: return 'Prime Number' else: return 'Composite Number'
11423
Validation/png/11423.png
# Write a function to convert the given string of integers into a tuple. def str_to_tuple(test_str): res = tuple(map(int, test_str.split(", "))) return res
11798
Validation/png/11798.png
def fun116(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 lcm = num1 * num2 / hcf return lcm
11840
Validation/png/11840.png
def fun158(string): length = len(string) count = 0 for i in range(length): ascii = ord(string[i]) if ascii >= 65 and ascii <= 90: count = count + 1 return count
11748
Validation/png/11748.png
def fun66(ch): vowel = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] if ch in vowel: return 'Vowel' else: return 'Consonant'
11407
Validation/png/11407.png
# Write a python function to find the 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"
11335
Validation/png/11335.png
# Write a python function to find the smallest missing number from the given array. def find_First_Missing(array, start, end): if start > end: return end + 1 if start != array[start]: return start mid = int((start + end) / 2) if array[mid] == mid: return find_First_Missing(array, mid + 1, end) return find_First_Missing(array, start, mid)
11736
Validation/png/11736.png
def fun54(len1, len2, len3): if len1 == len2 == len3: return 'EQUILATERAL TRIANGLE' elif len1 == len2 or len2 == len3 or len3 == len1: return 'ISOSCELES TRIANGLE' else: return 'SCALENE TRIANGLE'
11359
Validation/png/11359.png
# Write a function to check if one tuple is a subset of another tuple. def check_subset(test_tup1, test_tup2): res = set(test_tup2).issubset(test_tup1) return res
11303
Validation/png/11303.png
# 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"
11831
Validation/png/11831.png
def fun149(num): flag = True while num != 0: digit = num % 10 if digit > 7: flag = False num = num // 10 if flag == True: return 'Valid' else: return 'Invalid'
11844
Validation/png/11844.png
def fun162(string): length = len(string) count = 0 for i in range(length): ascii = ord(string[i]) if ascii >= 48 and ascii <= 57: count = count + 1 return count
11575
Validation/png/11575.png
# Write a python function to add a minimum number such that the sum of array becomes even. def min_Num(arr, n): odd = 0 for i in range(n): if arr[i] % 2: odd += 1 if odd % 2: return 1 return 2
11558
Validation/png/11558.png
# Write a function to check if a triangle of positive area is possible with the given angles. def is_triangleexists(a, b, c): if a != 0 and b != 0 and c != 0 and (a + b + c) == 180: if (a + b) >= c or (b + c) >= a or (a + c) >= b: return True else: return False else: return False
11761
Validation/png/11761.png
def fun79(N): sum = 0 i = 1 while i <= N: if i % 2 == 0: sum = sum + i i = i + 1 return sum
11469
Validation/png/11469.png
# Write a function to caluclate arc length of an angle. def arc_length(d, a): pi = 22 / 7 if a >= 360: return None arclength = (pi * d) * (a / 360) return arclength
11671
Validation/png/11671.png
# Write a function to calculate the discriminant value. def discriminant_value(x, y, z): discriminant = (y**2) - (4 * x * z) if discriminant > 0: return ("Two solutions", discriminant) elif discriminant == 0: return ("one solution", discriminant) elif discriminant < 0: return ("no real solution", discriminant)
11408
Validation/png/11408.png
# Write a function to count the number of elements in a list which are within a specific range. def count_range_in_list(li, min, max): ctr = 0 for x in li: if min <= x <= max: ctr += 1 return ctr
11433
Validation/png/11433.png
# Write a function to extract values between quotation marks of the given string by using regex. import re def extract_quotation(text1): return re.findall(r'"(.*?)"', text1)
11713
Validation/png/11713.png
def fun31(mass, volume): density = mass / volume return density
11702
Validation/png/11702.png
def fun20(radius, height): sarea = 2 * 3.142 * radius * radius + 2 * 3.142 * radius * height return sarea
11493
Validation/png/11493.png
# Write a function to convert tuple string to integer tuple. def tuple_str_int(test_str): res = tuple( int(num) for num in test_str.replace("(", "") .replace(")", "") .replace("...", "") .split(", ") ) return res
11564
Validation/png/11564.png
# Write a python function to find minimum adjacent swaps required to sort binary array. def find_Min_Swaps(arr, n): noOfZeroes = [0] * n count = 0 noOfZeroes[n - 1] = 1 - arr[n - 1] for i in range(n - 2, -1, -1): noOfZeroes[i] = noOfZeroes[i + 1] if arr[i] == 0: noOfZeroes[i] = noOfZeroes[i] + 1 for i in range(0, n): if arr[i] == 1: count = count + noOfZeroes[i] return count
11467
Validation/png/11467.png
# Write a function to check a decimal with a precision of 2. def is_decimal(num): import re dnumre = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""") result = dnumre.search(num) return bool(result)
11781
Validation/png/11781.png
def fun99(N, k): sum = 0 for i in range(1, N+1): if i % k == 0: sum = sum + i return sum
11446
Validation/png/11446.png
# Write a function to calculate the geometric sum of n-1. def geometric_sum(n): if n < 0: return 0 else: return 1 / (pow(2, n)) + geometric_sum(n - 1)
11515
Validation/png/11515.png
# Write a python function to find the first odd number in a given list of numbers. def first_odd(nums): first_odd = next((el for el in nums if el % 2 != 0), -1) return first_odd
11693
Validation/png/11693.png
def fun11(length, breadth): area = length * breadth return area
11816
Validation/png/11816.png
def fun134(N): sum = 0 i = 1 while i <= N: sum = sum + i * i i = i + 1 return sum
11854
Validation/png/11854.png
def fun172(string): length = len(string) new = '' for i in range(length - 1, -1, -1): new = new + string[i] return new
11329
Validation/png/11329.png
# Write a function to increment the numeric values in the given strings by k. def increment_numerics(test_list, K): res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list] return res
11381
Validation/png/11381.png
# Write a python function to convert a list of multiple integers into a single integer. def convert(list): s = [str(i) for i in list] res = int("".join(s)) return res
11543
Validation/png/11543.png
# Write a python function to find the slope of a line. def slope(x1, y1, x2, y2): return (float)(y2 - y1) / (x2 - x1)
11869
Validation/png/11869.png
def fun187(P, R, T): SI = P * R * T / 100 return SI
11827
Validation/png/11827.png
def fun145(num): nums = num order = 0 while num != 0: order = order + 1 num = num // 10 num = nums sum = 0 while num != 0: digit = num % 10 sum = sum + digit ** order num = num // 10 if sum == nums: return 'Armstrong Number' else: return 'Not an Armstrong Number'
11685
Validation/png/11685.png
def fun3(x): z = x//2 + x % 2 return z
11773
Validation/png/11773.png
def fun91(a, b): sum = 0 for i in range(a, b+1): sum = sum + i return sum
11317
Validation/png/11317.png
# Write a python function to find minimum possible value for the given periodic function. def floor_Min(A, B, N): x = max(B - 1, N) return (A * x) // B
11566
Validation/png/11566.png
# Write a function to count number of lists in a given list of lists and square the count. def count_list(input_list): return (len(input_list)) ** 2
11524
Validation/png/11524.png
# Write a function to clear the values of the given tuples. def clear_tuple(test_tup): temp = list(test_tup) temp.clear() test_tup = tuple(temp) return test_tup
11762
Validation/png/11762.png
def fun80(N): sum = 0 for i in range(1, N+1, 2): sum = sum + i return sum
11866
Validation/png/11866.png
def fun184(a, d, N): apterm = a + (N - 1) * d term = 1 / apterm return term
11695
Validation/png/11695.png
def fun13(radius): perimeter = 2 * 3.142 * radius return perimeter
11292
Validation/png/11292.png
# 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))
11719
Validation/png/11719.png
def fun37(string): ch = string[0] return ch
11484
Validation/png/11484.png
# Write a function to count those characters which have vowels as their neighbors in the given string. def count_vowels(test_str): res = 0 vow_list = ["a", "e", "i", "o", "u"] for idx in range(1, len(test_str) - 1): if test_str[idx] not in vow_list and ( test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list ): res += 1 if test_str[0] not in vow_list and test_str[1] in vow_list: res += 1 if test_str[-1] not in vow_list and test_str[-2] in vow_list: res += 1 return res
11867
Validation/png/11867.png
def fun185(a, d, N): sum = N * (2 * a + (N - 1) * d) / 2 return sum
11328
Validation/png/11328.png
# Write a function to find the largest subset where each pair is divisible. def largest_subset(a, n): dp = [0 for i in range(n)] dp[n - 1] = 1 for i in range(n - 2, -1, -1): mxm = 0 for j in range(i + 1, n): if a[j] % a[i] == 0 or a[i] % a[j] == 0: mxm = max(mxm, dp[j]) dp[i] = 1 + mxm return max(dp)
11417
Validation/png/11417.png
# Write a function to count unique keys for each value present in the tuple. from collections import defaultdict def get_unique(test_list): res = defaultdict(list) for sub in test_list: res[sub[1]].append(sub[0]) res = dict(res) res_dict = dict() for key in res: res_dict[key] = len(list(set(res[key]))) return str(res_dict)
11800
Validation/png/11800.png
def fun118(N): a = 0 b = 1 c = 2 if N == 1: return a elif N == 2: return b elif N == 3: return c else: for i in range(4, N + 1): d = a + b + c a = b b = c c = d return d
11654
Validation/png/11654.png
# Write a function to find the most common elements and their counts of a specified text. from collections import Counter def most_common_elem(s, a): most_common_elem = Counter(s).most_common(a) return most_common_elem
11789
Validation/png/11789.png
def fun107(num): pos = 1 nums = num while num != 0: pos = pos * 10 num = num // 10 pos = pos // 10 sum = nums // pos + nums % 10 return sum
11383
Validation/png/11383.png
# Write a function to add two integers. however, if the sum is between the given range it will return 20. def sum_nums(x, y, m, n): sum_nums = x + y if sum_nums in range(m, n): return 20 else: return sum_nums
11675
Validation/png/11675.png
# Write a python function to accept the strings which contains all vowels. def check(string): if len(set(string).intersection("AEIOUaeiou")) >= 5: return "accepted" else: return "not accepted"
11398
Validation/png/11398.png
# Write a function to multiply consecutive numbers of a given list. def mul_consecutive_nums(nums): result = [b * a for a, b in zip(nums[:-1], nums[1:])] return result
11698
Validation/png/11698.png
def fun16(radius, height): volume = 3.142 * radius * radius * height return volume
11397
Validation/png/11397.png
# ## write a function to find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block def min_jumps(arr, n): jumps = [0 for i in range(n)] if (n == 0) or (arr[0] == 0): return float("inf") jumps[0] = 0 for i in range(1, n): jumps[i] = float("inf") for j in range(i): if (i <= j + arr[j]) and (jumps[j] != float("inf")): jumps[i] = min(jumps[i], jumps[j] + 1) break return jumps[n - 1]
11322
Validation/png/11322.png
# Write a function to find the cumulative sum of all the values that are present in the given tuple list. def cummulative_sum(test_list): res = sum(map(sum, test_list)) return res
11691
Validation/png/11691.png
def fun9(side): area = side * side return area
11453
Validation/png/11453.png
# Write a function to find numbers within a given range where every number is divisible by every digit it contains. def divisible_by_digits(startnum, endnum): return [ n for n in range(startnum, endnum + 1) if not any(map(lambda x: int(x) == 0 or n % int(x) != 0, str(n))) ]
11572
Validation/png/11572.png
# Write a function to find palindromes in a given list of strings using lambda function. def palindrome_lambda(texts): result = list(filter(lambda x: (x == "".join(reversed(x))), texts)) return result
11792
Validation/png/11792.png
def fun110(base, exp): ans = 1 for i in range(exp+1): ans = ans * base return ans
11637
Validation/png/11637.png
# Write a function to count repeated items of a tuple. def count_tuplex(tuplex, value): count = tuplex.count(value) return count
11765
Validation/png/11765.png
def fun83(N): sum = 0 i = 1 while i <= N: if i % 2 != 0: sum = sum + i i = i + 1 return sum
11721
Validation/png/11721.png
def fun39(string, index): ch = string[index] return ch
11623
Validation/png/11623.png
# Write a function to rearrange positive and negative numbers in a given array using lambda function. def rearrange_numbs(array_nums): result = sorted(array_nums, key=lambda i: 0 if i == 0 else -1 / i) return result
11421
Validation/png/11421.png
# Write a function to check if the given tuple contains all valid values or not. def check_valid(test_tup): res = not any(map(lambda ele: not ele, test_tup)) return res
11376
Validation/png/11376.png
# Write a python function to replace multiple occurence of character by single. import re def replace(string, char): pattern = char + "{2,}" string = re.sub(pattern, char, string) return string
11644
Validation/png/11644.png
# Write a function to re-arrange the given tuples based on the given ordered list. def re_arrange_tuples(test_list, ord_list): temp = dict(test_list) res = [(key, temp[key]) for key in ord_list] return res
11814
Validation/png/11814.png
def fun132(N, k): term = 1 sum = 0 i = 1 while i < N: sum = sum + term term = 1 / i * k i = i + 1 return sum
11786
Validation/png/11786.png
def fun104(a, r, N): sum = 0 term = a i = 1 while i <= N: sum = sum + term term = term * r i = i + 1 return sum
11441
Validation/png/11441.png
# Write a function to find the index of the first occurrence of a given number in a sorted array. def find_first_occurrence(A, x): (left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid right = mid - 1 elif x < A[mid]: right = mid - 1 else: left = mid + 1 return result
11823
Validation/png/11823.png
def fun141(num): sum = 0 i = 1 while i < num: if num % i == 0: sum = sum + i i = i + 1 if sum == num: return 'Perfect Number' else: return 'Not a Perfect Number'
11880
Validation/png/11880.png
def fun198(string): length = len(string) new = '' i = 0 while i < length: ascii = ord(string[i]) if ascii >= 97 and ascii <= 122: new = new + string[i] i = i + 1 return new
11875
Validation/png/11875.png
def fun193(string): length = len(string) count = 0 for i in range(length): ascii = ord(string[i]) if ascii >= 48 and ascii <= 57: count = count + 1 if count > 0: return 'Present' else: return 'Not Present'
11434
Validation/png/11434.png
# Write a function to multiply the adjacent elements of the given tuple. def multiply_elements(test_tup): res = tuple(i * j for i, j in zip(test_tup, test_tup[1:])) return res
11553
Validation/png/11553.png
# Write a python function to count the number of digits in factorial of a given number. import math def find_Digits(n): if n < 0: return 0 if n <= 1: return 1 x = n * math.log10(n / math.e) + math.log10(2 * math.pi * n) / 2.0 return math.floor(x) + 1
11665
Validation/png/11665.png
# Write a python function to get the position of rightmost set bit. import math def get_First_Set_Bit_Pos(n): return math.log2(n & -n) + 1

Dataset Card for "FloCo_val"

More Information needed

Downloads last month
0
Edit dataset card