common_id
stringlengths 5
5
| image
stringlengths 24
24
| code
stringlengths 43
914
|
---|---|---|
11808 | Validation/png/11808.png | def fun126(N):
term = 1
i = 1
while i < N:
term = term * 10 + 1
i = i + 1
return term |
11414 | Validation/png/11414.png | # Write a function to find whether an array is subset of another array.
def is_subset(arr1, m, arr2, n):
hashset = set()
for i in range(0, m):
hashset.add(arr1[i])
for i in range(0, n):
if arr2[i] in hashset:
continue
else:
return False
return True
|
11591 | Validation/png/11591.png | # Write a function to find numbers divisible by m and n from a list of numbers using lambda function.
def div_of_nums(nums, m, n):
result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums))
return result
|
11568 | Validation/png/11568.png | # Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.
import re
regex = "[a-zA-z0-9]$"
def check_alphanumeric(string):
if re.search(regex, string):
return "Accept"
else:
return "Discard"
|
11436 | Validation/png/11436.png | # Write a function to sum elements in two lists.
def sum_list(lst1, lst2):
res_list = [lst1[i] + lst2[i] for i in range(len(lst1))]
return res_list
|
11473 | Validation/png/11473.png | # Write a function to find nth polite number.
import math
def is_polite(n):
n = n + 1
return (int)(n + (math.log((n + math.log(n, 2)), 2)))
|
11331 | Validation/png/11331.png | # Write a function to find the n-th power of individual elements in a list using lambda function.
def nth_nums(nums, n):
nth_nums = list(map(lambda x: x**n, nums))
return nth_nums
|
11363 | Validation/png/11363.png | # Write a python function to find the sum of fifth power of n natural numbers.
def fifth_Power_Sum(n):
sm = 0
for i in range(1, n + 1):
sm = sm + (i * i * i * i * i)
return sm
|
11565 | Validation/png/11565.png | # Write a function to list out the list of given strings individually using map function.
def listify_list(list1):
result = list(map(list, list1))
return result
|
11806 | Validation/png/11806.png | def fun124(a, d, N):
term = a
i = 1
while i < N:
term = term + d
i = i + 1
term = 1 / term
return term |
11517 | Validation/png/11517.png | # Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
def check_smaller(test_tup1, test_tup2):
res = all(x > y for x, y in zip(test_tup1, test_tup2))
return res
|
11785 | Validation/png/11785.png | def fun103(a, r, N):
sum = 0
term = a
for i in range(1, N+1):
sum = sum + term
term = term * r
return sum |
11499 | Validation/png/11499.png | # Write a function to remove the nested record from the given tuple.
def remove_nested(test_tup):
res = tuple()
for count, ele in enumerate(test_tup):
if not isinstance(ele, tuple):
res = res + (ele,)
return res
|
11362 | Validation/png/11362.png | # Write a function to find the perimeter of a rectangle.
def rectangle_perimeter(l, b):
perimeter = 2 * (l + b)
return perimeter
|
11597 | Validation/png/11597.png | # Write a function to reverse each list in a given list of lists.
def reverse_list_lists(lists):
for l in lists:
l.sort(reverse=True)
return lists
|
11349 | Validation/png/11349.png | # Write a function to find the nth nonagonal number.
def is_nonagonal(n):
return int(n * (7 * n - 5) / 2)
|
11752 | Validation/png/11752.png | def fun70(num):
sum = 0
while num != 0:
d = num % 10
sum = sum + d
num = num // 10
return sum |
11334 | Validation/png/11334.png | # Write a python function to find the largest triangle that can be inscribed in the semicircle.
def triangle_area(r):
if r < 0:
return -1
return r * r
|
11311 | Validation/png/11311.png | # Write a function to get a lucid number smaller than or equal to n.
def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while index != len(ludics):
first_ludic = ludics[index]
remove_index = index + first_ludic
while remove_index < len(ludics):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
index += 1
return ludics
|
11547 | Validation/png/11547.png | # Write a function to sort the tuples alphabetically by the first item of each tuple.
def sort_tuple(tup):
n = len(tup)
for i in range(n):
for j in range(n - i - 1):
if tup[j][0] > tup[j + 1][0]:
tup[j], tup[j + 1] = tup[j + 1], tup[j]
return tup
|
11734 | Validation/png/11734.png | def fun52(angle1, angle2, angle3):
if angle1 + angle2 + angle3 == 180:
return 'Forms Valid Triangle'
else:
return 'Cannot form a Valid Triangle' |
11801 | Validation/png/11801.png | def fun119(a, d, N):
term = a
for i in range(1, N):
term = term + d
return term
|
11386 | Validation/png/11386.png | # Write a python function to remove spaces from a given string.
def remove_spaces(str1):
str1 = str1.replace(" ", "")
return str1
|
11622 | Validation/png/11622.png | # Write a python function to check whether the given string is made up of two alternating characters or not.
def is_Two_Alter(s):
for i in range(len(s) - 2):
if s[i] != s[i + 2]:
return False
if s[0] == s[1]:
return False
return True
|
11616 | Validation/png/11616.png | # Write a function to find the fixed point in the given array.
def find_fixed_point(arr, n):
for i in range(n):
if arr[i] is i:
return i
return -1
|
11861 | Validation/png/11861.png | def fun179(string, char):
length = len(string)
index = -1
i = length - 1
while i >= 0:
ch = string[i]
if ch == char:
index = i
i = i - 1
return index
|
11755 | Validation/png/11755.png | def fun73(N):
sum = 0
i = 1
while i <= N:
sum = sum + i
i = i + 1
return sum |
11307 | Validation/png/11307.png | # 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)
|
11868 | Validation/png/11868.png | def fun186(a, r, N):
sum = a (r ** N - 1) / (r - 1)
return sum |
11707 | Validation/png/11707.png | def fun25(m):
cm = m * 100
return cm |
11790 | Validation/png/11790.png | def fun108(num):
sum = 0
for i in range(1, num+1):
if num % i == 0:
sum = sum + i
return sum |
11677 | Validation/png/11677.png | # Write a function to join the tuples if they have similar initial elements.
def join_tuples(test_list):
res = []
for sub in test_list:
if res and res[-1][0] == sub[0]:
res[-1].extend(sub[1:])
else:
res.append([ele for ele in sub])
res = list(map(tuple, res))
return res
|
11431 | Validation/png/11431.png | # Write a function to count the same pair in two given lists using map function.
from operator import eq
def count_same_pair(nums1, nums2):
result = sum(map(eq, nums1, nums2))
return result
|
11485 | Validation/png/11485.png | # Write a python function to find the sum of non-repeated elements in a given array.
def find_Sum(arr, n):
arr.sort()
sum = arr[0]
for i in range(0, n - 1):
if arr[i] != arr[i + 1]:
sum = sum + arr[i + 1]
return sum
|
11602 | Validation/png/11602.png | # Write a function to convert the given string of float type into tuple.
def float_to_tuple(test_str):
res = tuple(map(float, test_str.split(", ")))
return res
|
11845 | Validation/png/11845.png | def fun163(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
return count |
11794 | Validation/png/11794.png | def fun112(N, M):
ans = 0
for i in range(N):
ans = ans + M
return ans |
11459 | Validation/png/11459.png | # Write a function to check if the given array represents min heap or not.
def check_min_heap(arr, i):
if 2 * i + 2 > len(arr):
return True
left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1)
right_child = (2 * i + 2 == len(arr)) or (
arr[i] <= arr[2 * i + 2] and check_min_heap(arr, 2 * i + 2)
)
return left_child and right_child
|
11784 | Validation/png/11784.png | def fun102(a, d, N):
sum = 0
term = a
i = 1
while i <= N:
sum = sum + term
term = term + d
i = i + 1
return sum |
11474 | Validation/png/11474.png | # Write a function to iterate over all pairs of consecutive items in a given list.
def pair_wise(l1):
temp = []
for i in range(len(l1) - 1):
current_element, next_element = l1[i], l1[i + 1]
x = (current_element, next_element)
temp.append(x)
return temp
|
11495 | Validation/png/11495.png | # Write a function that matches a string that has an a followed by three 'b'.
import re
def text_match_three(text):
patterns = "ab{3}?"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
11445 | Validation/png/11445.png | # Write a function to check whether the given string is starting with a vowel or not using regex.
import re
regex = "^[aeiouAEIOU][A-Za-z0-9_]*"
def check_str(string):
if re.search(regex, string):
return "Valid"
else:
return "Invalid"
|
11392 | Validation/png/11392.png | # Write a python function to count occurences of a character in a repeated string.
def count_Char(str, x):
count = 0
for i in range(len(str)):
if str[i] == x:
count += 1
n = 10
repititions = n // len(str)
count = count * repititions
l = n % len(str)
for i in range(l):
if str[i] == x:
count += 1
return count
|
11465 | Validation/png/11465.png | # Write a function to count the pairs of reverse strings in the given string list.
def count_reverse_pairs(test_list):
res = sum(
[
1
for idx in range(0, len(test_list))
for idxn in range(idx, len(test_list))
if test_list[idxn] == str("".join(list(reversed(test_list[idx]))))
]
)
return str(res)
|
11472 | Validation/png/11472.png | # Write a python function to count numeric values in a given string.
def number_ctr(str):
number_ctr = 0
for i in range(len(str)):
if str[i] >= "0" and str[i] <= "9":
number_ctr += 1
return number_ctr
|
11583 | Validation/png/11583.png | # Write a function to find the minimum difference in the tuple pairs of given tuples.
def min_difference(test_list):
temp = [abs(b - a) for a, b in test_list]
res = min(temp)
return res
|
11460 | Validation/png/11460.png | # Write a function to find the nth jacobsthal number.
def jacobsthal_num(n):
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = 1
for i in range(2, n + 1):
dp[i] = dp[i - 1] + 2 * dp[i - 2]
return dp[n]
|
11862 | Validation/png/11862.png | def fun180(string, char):
length = len(string)
index = -1
for i in range(length):
ch = string[i]
if ch == char:
index = i
return index
|
11584 | Validation/png/11584.png | # Write a python function to find lcm of two positive integers.
def lcm(x, y):
if x > y:
z = x
else:
z = y
while True:
if (z % x == 0) and (z % y == 0):
lcm = z
break
z += 1
return lcm
|
11297 | Validation/png/11297.png | # 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
|
11878 | Validation/png/11878.png | def fun196(string):
length = len(string)
new = ''
i = 0
while i < length:
ascii = ord(string[i])
if ascii >= 65 and ascii <= 90:
new = new + string[i]
i = i + 1
return new |
11802 | Validation/png/11802.png | def fun120(a, d, N):
term = a
i = 1
while i < N:
term = term + d
i = i + 1
return term |
11404 | Validation/png/11404.png | # Write a function to zip two given lists of lists.
def zip_list(list1, list2):
result = list(map(list.__add__, list1, list2))
return result
|
11462 | Validation/png/11462.png | # Write a function to find common index elements from three lists.
def extract_index_list(l1, l2, l3):
result = []
for m, n, o in zip(l1, l2, l3):
if m == n == o:
result.append(m)
return result
|
11424 | Validation/png/11424.png | # Write a function to find the perimeter of a rombus.
def rombus_perimeter(a):
perimeter = 4 * a
return perimeter
|
11357 | Validation/png/11357.png | # Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.
def sum_Range_list(nums, m, n):
sum_range = 0
for i in range(m, n + 1, 1):
sum_range += nums[i]
return sum_range
|
11464 | Validation/png/11464.png | # Write a function that matches a string that has an a followed by zero or one 'b'.
import re
def text_match_zero_one(text):
patterns = "ab?"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
11670 | Validation/png/11670.png | # Write a python function to find the sum of all even natural numbers within the range l and r.
def sum_Natural(n):
sum = n * (n + 1)
return int(sum)
def sum_Even(l, r):
return sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2))
|
11327 | Validation/png/11327.png | # Write a function to move all the numbers in it to the given string.
def move_num(test_str):
res = ""
dig = ""
for ele in test_str:
if ele.isdigit():
dig += ele
else:
res += ele
res += dig
return res
|
11838 | Validation/png/11838.png | def fun156(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
return count |
11494 | Validation/png/11494.png | # Write a function to locate the right insertion point for a specified value in sorted order.
import bisect
def right_insertion(a, x):
i = bisect.bisect_right(a, x)
return i
|
11483 | Validation/png/11483.png | # Write a python function to check whether every odd index contains odd numbers of a given list.
def odd_position(nums):
return all(nums[i] % 2 == i % 2 for i in range(len(nums)))
|
11532 | Validation/png/11532.png | # Write a python function to remove even numbers from a given list.
def remove_even(l):
for i in l:
if i % 2 == 0:
l.remove(i)
return l
|
11787 | Validation/png/11787.png | def fun105(a, d, N):
sum = 0
term = a
for i in range(1, N+1):
sum = sum + 1 / term
term = term + d
return sum |
11430 | Validation/png/11430.png | # Write a function to filter the height and width of students which are stored in a dictionary.
def filter_data(students, h, w):
result = {k: s for k, s in students.items() if s[0] >= h and s[1] >= w}
return result
|
11885 | Validation/png/11885.png | def fun203(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 |
11304 | Validation/png/11304.png | # Write a function to find the size of the given tuple.
import sys
def tuple_size(tuple_list):
return sys.getsizeof(tuple_list)
|
11638 | Validation/png/11638.png | # Write a function that matches a string that has an a followed by zero or more b's by using regex.
import re
def text_match(text):
patterns = "ab*?"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
11661 | Validation/png/11661.png | # Write a python function to find the minimun number of subsets with distinct elements.
def subset(ar, n):
res = 0
ar.sort()
for i in range(0, n):
count = 1
for i in range(n - 1):
if ar[i] == ar[i + 1]:
count += 1
else:
break
res = max(res, count)
return res
|
11428 | Validation/png/11428.png | # Write a function to add a dictionary to the tuple.
def add_dict_to_tuple(test_tup, test_dict):
test_tup = list(test_tup)
test_tup.append(test_dict)
test_tup = tuple(test_tup)
return test_tup
|
11682 | Validation/png/11682.png | # Write a function to find the minimum total path sum in the given triangle.
def min_sum_path(A):
memo = [None] * len(A)
n = len(A) - 1
for i in range(len(A[n])):
memo[i] = A[n][i]
for i in range(len(A) - 2, -1, -1):
for j in range(len(A[i])):
memo[j] = A[i][j] + min(memo[j], memo[j + 1])
return memo[0]
|
11522 | Validation/png/11522.png | # Write a function to find the area of a rombus.
def rombus_area(p, q):
area = (p * q) / 2
return area
|
11419 | Validation/png/11419.png | # Write a python function to check whether the product of digits of a number at even and odd places is equal or not.
def product_Equal(n):
if n < 10:
return False
prodOdd = 1
prodEven = 1
while n > 0:
digit = n % 10
prodOdd *= digit
n = n // 10
if n == 0:
break
digit = n % 10
prodEven *= digit
n = n // 10
if prodOdd == prodEven:
return True
return False
|
11390 | Validation/png/11390.png | # Write a function to multiply two lists using map and lambda function.
def mul_list(nums1, nums2):
result = map(lambda x, y: x * y, nums1, nums2)
return list(result)
|
11768 | Validation/png/11768.png | def fun86(num):
codd = 0
while num != 0:
d = num % 10
if d % 2 != 0:
codd = codd + 1
num = num // 10
return codd |
11313 | Validation/png/11313.png | # Write a function to check if the given integer is a prime number.
def prime_num(num):
if num >= 1:
for i in range(2, num // 2):
if (num % i) == 0:
return False
else:
return True
else:
return False
|
11365 | Validation/png/11365.png | # Write a python function to find the first digit in factorial of a given number.
import math
def first_Digit(n):
fact = 1
for i in range(2, n + 1):
fact = fact * i
while fact % 10 == 0:
fact = int(fact / 10)
while fact >= 10:
fact = int(fact / 10)
return math.floor(fact)
|
11491 | Validation/png/11491.png | # Write a function to convert rgb color to hsv color.
def rgb_to_hsv(r, g, b):
r, g, b = r / 255.0, g / 255.0, b / 255.0
mx = max(r, g, b)
mn = min(r, g, b)
df = mx - mn
if mx == mn:
h = 0
elif mx == r:
h = (60 * ((g - b) / df) + 360) % 360
elif mx == g:
h = (60 * ((b - r) / df) + 120) % 360
elif mx == b:
h = (60 * ((r - g) / df) + 240) % 360
if mx == 0:
s = 0
else:
s = (df / mx) * 100
v = mx * 100
return h, s, v
|
11544 | Validation/png/11544.png | # Write a function to find length of the subarray having maximum sum.
from sys import maxsize
def max_sub_array_sum(a, size):
max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0
for i in range(0, size):
max_ending_here += a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
start = s
end = i
if max_ending_here < 0:
max_ending_here = 0
s = i + 1
return end - start + 1
|
11488 | Validation/png/11488.png | # Write a function to find the combinations of sums with tuples in the given tuple list.
from itertools import combinations
def find_combinations(test_list):
res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)]
return res
|
11724 | Validation/png/11724.png | def fun42(x, y, z):
if x > y and x > z:
mx = x
elif y > x and y > z:
mx = y
else:
mx = z
return mx |
11403 | Validation/png/11403.png | # Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
def check_greater(test_tup1, test_tup2):
res = all(x < y for x, y in zip(test_tup1, test_tup2))
return res
|
11754 | Validation/png/11754.png | def fun72(N):
sum = 0
for i in range(1, N+1):
sum = sum + i
return sum |
11864 | Validation/png/11864.png | def fun182(a, d, N):
term = a + (N - 1) * d
return term |
11810 | Validation/png/11810.png | def fun128(N, k):
term = 1
i = 1
while i < N:
term = 1 / i * k
i = i + 1
return term |
11705 | Validation/png/11705.png | def fun23(x, y):
z = x * y
return z |
11717 | Validation/png/11717.png | def fun35(degree):
radian = degree * 0.0174533
return radian |
11669 | Validation/png/11669.png | # Write a function to convert a roman numeral to an integer.
def roman_to_int(s):
rom_val = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
int_val = 0
for i in range(len(s)):
if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
else:
int_val += rom_val[s[i]]
return int_val
|
11804 | Validation/png/11804.png | def fun122(a, r, N):
term = a
i = 1
while i < N:
term = term * r
i = i + 1
return term
|
11621 | Validation/png/11621.png | # Write a function to check for a number at the end of a string.
import re
def end_num(string):
text = re.compile(r".*[0-9]$")
if text.match(string):
return True
else:
return False
|
11836 | Validation/png/11836.png | def fun154(string):
length = len(string)
new = ''
for i in range(length):
ch = ord(string[i])
if ch >= 97 and ch <= 122:
new = new + chr(ch - 32)
else:
new = new + chr(ch)
return new
|
11545 | Validation/png/11545.png | # Write a python function to find the cube sum of first n odd natural numbers.
def cube_Sum(n):
sum = 0
for i in range(0, n):
sum += (2 * i + 1) * (2 * i + 1) * (2 * i + 1)
return sum
|
11662 | Validation/png/11662.png | # Write a function that gives profit amount if the given amount has profit else return none.
def profit_amount(actual_cost, sale_amount):
if actual_cost > sale_amount:
amount = actual_cost - sale_amount
return amount
else:
return None
|
11703 | Validation/png/11703.png | def fun21(x, y):
z = x + y
return z |