mr44/mbsearch huggingface dataset:
Task: Write a function to convert a roman numeral to an integer.

Solution:
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


Tests:
assert roman_to_int('MMMCMLXXXVI')==3986
assert roman_to_int('MMMM')==4000
assert roman_to_int('C')==100
Task: Write a python function to find the sum of all even natural numbers within the range l and r.

Solution:
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))) 


Tests:
assert sum_Even(2,5) == 6
assert sum_Even(3,8) == 18
assert sum_Even(4,6) == 10
Task: Write a function to calculate the discriminant value.

Solution:
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)


Tests:
assert discriminant_value(4,8,2)==("Two solutions",32)
assert discriminant_value(5,7,9)==("no real solution",-131)
assert discriminant_value(0,0,9)==("one solution",0)
Task: Write a python function to check whether the length of the word is even or not.

Solution:
def word_len(s): 
    s = s.split(' ')   
    for word in s:    
        if len(word)%2==0: 
            return True  
        else:
          return False


Tests:
assert word_len("program") == False
assert word_len("solution") == True
assert word_len("data") == True
Task: Write a function to convert camel case string to snake case string.

Solution:
def camel_to_snake(text):
        import re
        str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
        return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower()


Tests:
assert camel_to_snake('PythonProgram')==('python_program')
assert camel_to_snake('pythonLanguage')==('python_language')
assert camel_to_snake('ProgrammingLanguage')==('programming_language')
Task: Write a function to remove an empty tuple from a list of tuples.

Solution:
def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
   tuple1 = [t for t in tuple1 if t]
   return tuple1


Tests:
assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']  
assert remove_empty([(), (), ('',), ("python"), ("program")])==[('',), ("python"), ("program")]  
assert remove_empty([(), (), ('',), ("java")])==[('',),("java") ]
Task: Write a python function to accept the strings which contains all vowels.

Solution:
def check(string): 
  if len(set(string).intersection("AEIOUaeiou"))>=5: 
    return ('accepted') 
  else: 
    return ("not accepted") 


Tests:
assert check("SEEquoiaL") == 'accepted'
assert check('program') == "not accepted"
assert check('fine') == "not accepted"
Task: Write a python function to find maximum possible value for the given periodic function.

Solution:
def floor_Max(A,B,N):
    x = min(B - 1,N)
    return (A*x) // B


Tests:
assert floor_Max(11,10,9) == 9
assert floor_Max(5,7,4) == 2
assert floor_Max(2,2,1) == 1
Task: Write a function to join the tuples if they have similar initial elements.

Solution:
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) 


Tests:
assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]
assert join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]
assert join_tuples([(7, 8), (7, 9), (8, 10), (8, 12), (9, 15)] ) == [(7, 8, 9), (8, 10, 12), (9, 15)]
Task: Write a function to find minimum of two numbers.

Solution:
def min_of_two( x, y ):
    if x < y:
        return x
    return y


Tests:
assert min_of_two(10,20)==10
assert min_of_two(19,15)==15
assert min_of_two(-10,-20)==-20
Task: Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.

Solution:
def maximum_segments(n, a, b, c) : 
	dp = [-1] * (n + 10) 
	dp[0] = 0
	for i in range(0, n) : 
		if (dp[i] != -1) : 
			if(i + a <= n ): 
				dp[i + a] = max(dp[i] + 1, 
							dp[i + a]) 
			if(i + b <= n ): 
				dp[i + b] = max(dp[i] + 1, 
							dp[i + b]) 
			if(i + c <= n ): 
				dp[i + c] = max(dp[i] + 1, 
							dp[i + c]) 
	return dp[n]


Tests:
assert maximum_segments(7, 5, 2, 5) == 2
assert maximum_segments(17, 2, 1, 3) == 17
assert maximum_segments(18, 16, 3, 6) == 6
Task: Write a function to concatenate the given two tuples to a nested tuple.

Solution:
def concatenate_nested(test_tup1, test_tup2):
  res = test_tup1 + test_tup2
  return (res) 


Tests:
assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)
assert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)
assert concatenate_nested((4, 5), (6, 8)) == (4, 5, 6, 8)
Task: Write a python function to left rotate the string.

Solution:
def left_rotate(s,d):
    tmp = s[d : ] + s[0 : d]
    return tmp  


Tests:
assert left_rotate("python",2) == "thonpy"   
assert left_rotate("bigdata",3 ) == "databig" 
assert left_rotate("hadoop",1 ) == "adooph"
Task: Write a function to find the minimum total path sum in the given triangle.

Solution:
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]


Tests:
assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6
assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10 
assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9