INSTRUCTION
stringlengths 78
1.13k
| RESPONSE
stringlengths 36
906
| SOURCE
stringclasses 2
values |
---|---|---|
Write a Python function which follows this instruction: Write a function to calculate the sum of perrin numbers.
|
def cal_sum(n):
a = 3
b = 0
c = 2
if (n == 0):
return 3
if (n == 1):
return 3
if (n == 2):
return 5
sum = 5
while (n > 2):
d = a + b
sum = sum + d
a = b
b = c
c = d
n = n-1
return sum
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to extract specified size of strings from a given list of string values.
|
def extract_string(str, l):
result = [e for e in str if len(e) == l]
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to remove all whitespaces from the given string.
|
import re
def remove_whitespaces(text1):
return (re.sub(r'\s+', '',text1))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function that gives loss amount on a sale if the given amount has loss else return 0.
|
def loss_amount(actual_cost,sale_amount):
if(sale_amount > actual_cost):
amount = sale_amount - actual_cost
return amount
else:
return 0
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sum of even factors of a number.
|
import math
def sumofFactors(n) :
if (n % 2 != 0) :
return 0
res = 1
for i in range(2, (int)(math.sqrt(n)) + 1) :
count = 0
curr_sum = 1
curr_term = 1
while (n % i == 0) :
count= count + 1
n = n // i
if (i == 2 and count == 1) :
curr_sum = 0
curr_term = curr_term * i
curr_sum = curr_sum + curr_term
res = res * curr_sum
if (n >= 2) :
res = res * (1 + n)
return res
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function that matches a word containing 'z'.
|
import re
def text_match_wordz(text):
patterns = '\w*z.\w*'
if re.search(patterns, text):
return True
else:
return False
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check whether the given month number contains 31 days or not.
|
def check_monthnumb_number(monthnum2):
if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12):
return True
else:
return False
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to reverse each string in a given list of string values.
|
def reverse_string_list(stringlist):
result = [x[::-1] for x in stringlist]
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sublist having minimum length.
|
def Find_Min(lst):
return min(lst, key=len)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the area of a rectangle.
|
def rectangle_area(l,b):
area=l*b
return area
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to remove uppercase substrings from a given string.
|
import re
def remove_uppercase(str1):
return re.sub('[A-Z]', '', str1)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to get the first element of each sublist.
|
def Extract(lst):
return [item[0] for item in lst]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to count the upper case characters in a given string.
|
def upper_ctr(str):
upper_ctr = 0
for i in range(len(str)):
if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1
return upper_ctr
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find all possible combinations of the elements of a given list.
|
def combinations_list(list1):
if len(list1) == 0:
return [[]]
result = []
for el in combinations_list(list1[1:]):
result += [el, el+[list1[0]]]
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the maximum product subarray of the given array.
|
def max_subarray_product(arr):
n = len(arr)
max_ending_here = 1
min_ending_here = 1
max_so_far = 0
flag = 0
for i in range(0, n):
if arr[i] > 0:
max_ending_here = max_ending_here * arr[i]
min_ending_here = min (min_ending_here * arr[i], 1)
flag = 1
elif arr[i] == 0:
max_ending_here = 1
min_ending_here = 1
else:
temp = max_ending_here
max_ending_here = max (min_ending_here * arr[i], 1)
min_ending_here = temp * arr[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if flag == 0 and max_so_far == 0:
return 0
return max_so_far
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check if all values are same in a dictionary.
|
def check_value(dict, n):
result = all(x == n for x in dict.values())
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to drop empty items from a given dictionary.
|
def drop_empty(dict1):
dict1 = {key:value for (key, value) in dict1.items() if value is not None}
return dict1
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.
|
def max_product(arr):
n = len(arr)
mpis = arr[:]
for i in range(n):
current_prod = arr[i]
j = i + 1
while j < n:
if arr[j-1] > arr[j]:
break
current_prod *= arr[j]
if current_prod > mpis[j]:
mpis[j] = current_prod
j = j + 1
return max(mpis)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the pairwise addition of the neighboring elements of the given tuple.
|
def add_pairwise(test_tup):
res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the product of the array multiplication modulo n.
|
def find_remainder(arr, n):
mul = 1
for i in range(len(arr)):
mul = (mul * (arr[i] % n)) % n
return mul % n
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to check whether the given list contains consecutive numbers or not.
|
def check_Consecutive(l):
return sorted(l) == list(range(min(l),max(l)+1))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.
|
def tuple_intersection(test_list1, test_list2):
res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to replace characters in a string.
|
def replace_char(str1,ch,newch):
str2 = str1.replace(ch, newch)
return str2
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to sort a dictionary by value.
|
from collections import Counter
def sort_counter(dict1):
x = Counter(dict1)
sort_counter=x.most_common()
return sort_counter
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sum of the largest and smallest value in a given array.
|
def big_sum(nums):
sum= max(nums)+min(nums)
return sum
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to convert the given string to lower case.
|
def is_lower(string):
return (string.lower())
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to remove lowercase substrings from a given string.
|
import re
def remove_lowercase(str1):
return re.sub('[a-z]', '', str1)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the first digit of a given number.
|
def first_Digit(n) :
while n >= 10:
n = n / 10
return int(n)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function which takes a list of integers and only returns the odd ones.
|
def Split(list):
od_li = []
for i in list:
if (i % 2 != 0):
od_li.append(i)
return od_li
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.
|
def difference(n) :
S = (n*(n + 1))//2;
res = S*(S-1);
return res;
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to count the number of pairs whose xor value is odd.
|
def find_Odd_Pair(A,N) :
oddPair = 0
for i in range(0,N) :
for j in range(i+1,N) :
if ((A[i] ^ A[j]) % 2 != 0):
oddPair+=1
return oddPair
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to toggle the case of all characters in a string.
|
def toggle_string(string):
string1 = string.swapcase()
return string1
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sum of the per-digit difference between two integers.
|
def digit_distance_nums(n1, n2):
return sum(map(int,str(abs(n1-n2))))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the sum of the largest contiguous sublist in the given list.
|
def max_sub_array_sum(a, size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_ending_here < 0:
max_ending_here = 0
elif (max_so_far < max_ending_here):
max_so_far = max_ending_here
return max_so_far
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the union of the elements of two given tuples and output them in sorted order.
|
def union_elements(test_tup1, test_tup2):
res = tuple(set(test_tup1 + test_tup2))
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the length of the longest sublists.
|
def Find_Max_Length(lst):
maxLength = max(len(x) for x in lst )
return maxLength
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to extract values between quotation marks from a string.
|
import re
def extract_values(text):
return (re.findall(r'"(.*?)"', text))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function which takes a list of integers and counts the number of possible unordered pairs where both elements are unequal.
|
def count_Pairs(arr,n):
cnt = 0;
for i in range(n):
for j in range(i + 1,n):
if (arr[i] != arr[j]):
cnt += 1;
return cnt;
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to split a string into characters.
|
def split(word):
return [char for char in word]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to get the sum of the digits of a non-negative integer.
|
def sum_digits(n):
if n == 0:
return 0
else:
return n % 10 + sum_digits(int(n / 10))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check whether a specified list is sorted or not.
|
def issort_list(list1):
result = all(list1[i] <= list1[i+1] for i in range(len(list1)-1))
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to create a list of N empty dictionaries.
|
def empty_list(length):
empty_list = [{} for _ in range(length)]
return empty_list
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to sort each sublist of strings in a given list of lists.
|
def sort_sublists(list1):
result = list(map(sorted,list1))
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to remove duplicate numbers from a given number of lists.
|
def two_unique_nums(nums):
return [i for i in nums if nums.count(i)==1]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to calculate the product of the unique numbers in a given list.
|
def unique_product(list_data):
temp = list(set(list_data))
p = 1
for i in temp:
p *= i
return p
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the surface area of a cylinder.
|
def surfacearea_cylinder(r,h):
surfacearea=((2*3.1415*r*r) +(2*3.1415*r*h))
return surfacearea
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to check whether a list is sublist of another or not.
|
def is_Sub_Array(A,B):
n = len(A)
m = len(B)
i = 0; j = 0;
while (i < n and j < m):
if (A[i] == B[j]):
i += 1;
j += 1;
if (j == m):
return True;
else:
i = i - j + 1;
j = 0;
return False;
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the last digit in factorial of a given number.
|
def last_Digit_Factorial(n):
if (n == 0): return 1
elif (n <= 2): return n
elif (n == 3): return 6
elif (n == 4): return 4
else:
return 0
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to interleave 3 lists of the same length into a single flat list.
|
def interleave_lists(list1,list2,list3):
result = [el for pair in zip(list1, list2, list3) for el in pair]
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the dissimilar elements in the given two tuples.
|
def find_dissimilar(test_tup1, test_tup2):
res = tuple(set(test_tup1) ^ set(test_tup2))
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to remove uneven elements in the nested mixed tuple.
|
def even_ele(test_tuple, even_fnc):
res = tuple()
for ele in test_tuple:
if isinstance(ele, tuple):
res += (even_ele(ele, even_fnc), )
elif even_fnc(ele):
res += (ele, )
return res
def extract_even(test_tuple):
res = even_ele(test_tuple, lambda x: x % 2 == 0)
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the surface area of a square pyramid with a given base edge and height.
|
def surface_Area(b,s):
return 2 * b * s + pow(b,2)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check if a dictionary is empty
|
def my_dict(dict1):
if bool(dict1):
return False
else:
return True
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function which returns nth catalan number.
|
def catalan_number(num):
if num <=1:
return 1
res_num = 0
for i in range(num):
res_num += catalan_number(i) * catalan_number(num-i-1)
return res_num
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the first adverb ending with ly and its positions in a given string.
|
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)))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the n most expensive items in a given dataset.
|
import heapq
def expensive_items(items,n):
expensive_items = heapq.nlargest(n, items, key=lambda s: s['price'])
return expensive_items
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to split a list at the nth eelment and add the first part to the end.
|
def split_Arr(l, n):
return l[n:] + l[:n]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to convert a list to a tuple.
|
def list_tuple(listx):
tuplex = tuple(listx)
return tuplex
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the difference between largest and smallest value in a given list.
|
def big_diff(nums):
diff= max(nums)-min(nums)
return diff
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to interchange the first and last elements in a list.
|
def swap_List(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sum of the product of consecutive 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);
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to remove leading zeroes from an ip address.
|
import re
def removezero_ip(ip):
string = re.sub('\.[0]*', '.', ip)
return string
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the difference of the first even and first odd number of a given list.
|
def diff_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even-first_odd)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to count minimum number of swaps required to convert one binary number represented as a 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")
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the size in bytes of the given tuple.
|
import sys
def tuple_size(tuple_list):
return (sys.getsizeof(tuple_list))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find kth element from the given two sorted arrays.
|
def find_kth(arr1, arr2, k):
m = len(arr1)
n = len(arr2)
sorted1 = [0] * (m + n)
i = 0
j = 0
d = 0
while (i < m and j < n):
if (arr1[i] < arr2[j]):
sorted1[d] = arr1[i]
i += 1
else:
sorted1[d] = arr2[j]
j += 1
d += 1
while (i < m):
sorted1[d] = arr1[i]
d += 1
i += 1
while (j < n):
sorted1[d] = arr2[j]
d += 1
j += 1
return sorted1[k - 1]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check whether the given number is armstrong or not.
|
def armstrong_number(number):
sum = 0
times = 0
temp = number
while temp > 0:
times = times + 1
temp = temp // 10
temp = number
while temp > 0:
reminder = temp % 10
sum = sum + (reminder ** times)
temp //= 10
if number == sum:
return True
else:
return False
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to check whether the given number is even or not.
|
def is_Even(n) :
if (n^1 == n+1) :
return True;
else :
return False;
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the first repeated character in a given string.
|
def first_repeated_char(str1):
for index,c in enumerate(str1):
if str1[:index+1].count(c) > 1:
return c
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to get all lucid numbers smaller than or equal to a given integer.
|
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
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to reverse words seperated by spaces in a given string.
|
def reverse_words(s):
return ' '.join(reversed(s.split()))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to convert degrees to radians.
|
import math
def radian_degree(degree):
radian = degree*(math.pi/180)
return radian
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to search a string for a regex pattern. The function should return the matching subtring, a start index and an end index.
|
import re
def find_literals(text, pattern):
match = re.search(pattern, text)
s = match.start()
e = match.end()
return (match.re.pattern, s, e)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function which takes a list and returns a list with the same elements, but the k'th element removed.
|
def remove_kth_element(list1, L):
return list1[:L-1] + list1[L:]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function which given a matrix represented as a list of lists returns the max of the n'th column.
|
def max_of_nth(test_list, N):
res = max([sub[N] for sub in test_list])
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function which takes a list of lists, where each sublist has two elements, and returns a list of two lists where the first list has the first element of each sublist and the second one has the second.
|
def merge(lst):
return [list(ele) for ele in list(zip(*lst))]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function which takes a tuple of tuples and returns the average value for each tuple as a list.
|
def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function which takes two tuples of the same length and performs the element wise modulo.
|
def tuple_modulo(test_tup1, test_tup2):
res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
|
def min_Jumps(steps, d):
(a, b) = steps
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to divide two lists element wise.
|
def div_list(nums1,nums2):
result = map(lambda x, y: x / y, nums1, nums2)
return list(result)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to move all the numbers to the end of 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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the size of the largest subset of a list of numbers so that every pair is divisible.
|
def largest_subset(a):
n = len(a)
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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to find the median of two sorted lists of same size.
|
def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2)/2
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to compute the n-th power of each number in a list.
|
def nth_nums(nums,n):
nth_nums = list(map(lambda x: x ** n, nums))
return nth_nums
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to convert a given string to uppercase.
|
def is_upper(string):
return (string.upper())
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to interchange the first and last element in a given list.
|
def swap_List(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.
|
def triangle_area(r) :
if r < 0 :
return None
return r * r
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the smallest missing number from a sorted list of natural numbers.
|
def find_First_Missing(array,start=0,end=None):
if end is None:
end = len(array) - 1
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)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to replace all spaces in the given string with '%20'.
|
def replace_spaces(string):
return string.replace(" ", "%20")
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find even numbers from a list of numbers.
|
def Split(list):
return [num for num in list if num % 2 == 0]
|
mbpp_sanitized
|
Write a Python function which follows this instruction: 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):
return list(adjac(test_tup))
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a function to replace whitespaces with an underscore and vice versa in a given string.
|
def replace_spaces(text):
return "".join(" " if c == "_" else ("_" if c == " " else c) for c in text)
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to move all zeroes to the end of the given list.
|
def move_zero(num_list):
a = [0 for i in range(num_list.count(0))]
x = [i for i in num_list if i != 0]
return x + a
|
mbpp_sanitized
|
Write a Python function which follows this instruction: Write a python function to find the sum of xor of all pairs of numbers in the given list.
|
def pair_xor_Sum(arr,n) :
ans = 0
for i in range(0,n) :
for j in range(i + 1,n) :
ans = ans + (arr[i] ^ arr[j])
return ans
|
mbpp_sanitized
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.