neural-mesh-v2 / evaluation /code_eval /evalplus_results /mbpp /Qwen--Qwen2.5-7B_vllm_temp_0.0.jsonl
| {"task_id": "Mbpp/2", "solution": "def similar_elements(list1, list2):\n \"\"\"\n Find the shared elements from the given two lists.\n\n Args:\n list1 (list): The first list.\n list2 (list): The second list.\n\n Returns:\n set: A set containing the shared elements between the two lists.\n \"\"\"\n return set(list1) & set(list2)"} | |
| {"task_id": "Mbpp/3", "solution": "def is_not_prime(n):\n \"\"\"\n Check if a number is not prime.\n\n Args:\n n (int): The number to check.\n\n Returns:\n bool: True if the number is not prime, False otherwise.\n \"\"\"\n if n <= 1:\n return True\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return True\n return False"} | |
| {"task_id": "Mbpp/4", "solution": "import heapq\ndef heap_queue_largest(numbers, n):\n \"\"\"\n Find the n largest integers from a given list of numbers, returned in descending order.\n\n Args:\n numbers (list): A list of integers.\n n (int): The number of largest integers to find.\n\n Returns:\n list: A list of the n largest integers in descending order.\n\n Example:\n >>> heap_queue_largest([25, 35, 22, 85, 14, 65, 75, 22, 58], 3)\n [85, 75, 65]\n \"\"\"\n if n <= 0:\n return []\n if n >= len(numbers):\n return sorted(numbers, reverse=True)\n return heapq.nlargest(n, numbers)"} | |
| {"task_id": "Mbpp/6", "solution": "def differ_At_One_Bit_Pos(a, b):\n \"\"\"\n Check if two numbers differ at one bit position only.\n \n Args:\n a (int): First number.\n b (int): Second number.\n \n Returns:\n bool: True if the numbers differ at one bit position only, False otherwise.\n \"\"\"\n return a != b and (a ^ b) & (a ^ b - 1) == 0"} | |
| {"task_id": "Mbpp/7", "solution": "def find_char_long(text):\n \"\"\"\n Finds all words in the given text that are at least 4 characters long.\n\n Args:\n text (str): The input string.\n\n Returns:\n list: A list of words that are at least 4 characters long.\n \"\"\"\n return [word for word in text.split() if len(word) >= 4]"} | |
| {"task_id": "Mbpp/8", "solution": "def square_nums(nums):\n \"\"\"\n This function takes a list of numbers and returns a new list containing the squares of the original numbers.\n \n Args:\n nums (list): A list of numbers.\n \n Returns:\n list: A new list containing the squares of the original numbers.\n \"\"\"\n return [num ** 2 for num in nums]"} | |
| {"task_id": "Mbpp/9", "solution": "def find_Rotations(s):\n \"\"\"\n Find the minimum number of rotations (greater than 0) required to get the same string.\n \"\"\"\n if len(s) <= 1:\n return 0\n for i in range(1, len(s)):\n if s[i:] + s[:i] == s:\n return i\n return len(s)"} | |
| {"task_id": "Mbpp/11", "solution": "def remove_Occ(s, char):\n \"\"\"\n Remove the first and last occurrence of a given character from the string.\n\n Args:\n s (str): The input string.\n char (str): The character to be removed.\n\n Returns:\n str: The modified string with the first and last occurrence of the character removed.\n \"\"\"\n if char not in s:\n return s\n\n # Find the indices of the first and last occurrences of the character\n first_index = s.index(char)\n last_index = s.rindex(char)\n\n # Remove the first and last occurrences of the character\n return s[:first_index] + s[first_index + 1:last_index] + s[last_index + 1:]"} | |
| {"task_id": "Mbpp/12", "solution": "def sort_matrix(matrix):\n \"\"\"\n Sorts a given matrix in ascending order according to the sum of its rows.\n\n Args:\n matrix (list of lists): The input matrix.\n\n Returns:\n list of lists: The sorted matrix.\n \"\"\"\n return sorted(matrix, key=sum)"} | |
| {"task_id": "Mbpp/14", "solution": "def find_Volume(base, height, length):\n \"\"\"\n Calculate the volume of a triangular prism.\n\n Parameters:\n base (float): The base of the triangular face.\n height (float): The height of the triangular face.\n length (float): The length of the prism.\n\n Returns:\n float: The volume of the triangular prism.\n \"\"\"\n area_of_triangle = 0.5 * base * height\n volume = area_of_triangle * length\n return volume"} | |
| {"task_id": "Mbpp/16", "solution": "import re\ndef text_lowercase_underscore(s):\n \"\"\"\n Check if the input string contains sequences of lowercase letters joined with an underscore.\n \n Args:\n s (str): The input string to be checked.\n \n Returns:\n bool: True if the string contains sequences of lowercase letters joined with an underscore, False otherwise.\n \"\"\"\n pattern = re.compile(r'^[a-z]+_[a-z]+$')\n return bool(pattern.match(s))"} | |
| {"task_id": "Mbpp/17", "solution": "def square_perimeter(side_length):\n \"\"\"\n Returns the perimeter of a square given its side length as input.\n \"\"\"\n return 4 * side_length"} | |
| {"task_id": "Mbpp/18", "solution": "def remove_dirty_chars(s1, s2):\n \"\"\"\n Remove characters from the first string that are present in the second string.\n\n Parameters:\n s1 (str): The original string from which characters will be removed.\n s2 (str): The string containing characters to be removed from the first string.\n\n Returns:\n str: The modified string with characters removed.\n \"\"\"\n for char in s2:\n s1 = s1.replace(char, '')\n return s1"} | |
| {"task_id": "Mbpp/19", "solution": "def test_duplicate(arr):\n \"\"\"\n Check if the given array of integers contains any duplicate elements.\n\n Args:\n arr (list): A list of integers.\n\n Returns:\n bool: True if there are duplicate elements, False otherwise.\n \"\"\"\n seen = set()\n for num in arr:\n if num in seen:\n return True\n seen.add(num)\n return False"} | |
| {"task_id": "Mbpp/20", "solution": "def is_woodall(n):\n \"\"\"\n Check if the given number is a Woodall number or not.\n A Woodall number is of the form W(n) = n * 2^n - 1 for n >= 1.\n Args:\n n (int): The number to check.\n Returns:\n bool: True if the number is a Woodall number, False otherwise.\n \"\"\"\n if n < 1:\n return False\n x = 1\n for i in range(1, n + 1):\n x = x * 2 - 1\n if x == n:\n return True\n return False"} | |
| {"task_id": "Mbpp/56", "solution": "def check(num):\n \"\"\"\n Check if a given number is one less than twice its reverse.\n\n Args:\n num (int): The number to check.\n\n Returns:\n bool: True if the number is one less than twice its reverse, False otherwise.\n \"\"\"\n reverse_num = int(str(num)[::-1])\n return num == 2 * reverse_num - 1"} | |
| {"task_id": "Mbpp/57", "solution": "def find_Max_Num(digits):\n \"\"\"\n Write a python function to find the largest number that can be formed with the given list of digits.\n assert find_Max_Num([1,2,3]) == 321\n \"\"\"\n digits.sort(reverse=True)\n return int(''.join(map(str, digits)))"} | |
| {"task_id": "Mbpp/58", "solution": "def opposite_Signs(a, b):\n \"\"\"\n Check if two integers have opposite signs.\n\n Parameters:\n a (int): The first integer.\n b (int): The second integer.\n\n Returns:\n bool: True if the integers have opposite signs, False otherwise.\n \"\"\"\n return (a < 0) != (b < 0)"} | |
| {"task_id": "Mbpp/59", "solution": "def is_octagonal(n):\n \"\"\"\n Calculate the nth octagonal number.\n \n Args:\n n (int): The position of the octagonal number to calculate.\n \n Returns:\n int: The nth octagonal number.\n \"\"\"\n return n * (3 * n - 2)"} | |
| {"task_id": "Mbpp/61", "solution": "def count_Substrings(s):\n \"\"\"\n Write a python function to count the number of substrings with the sum of digits equal to their length.\n \"\"\"\n count = 0\n for i in range(len(s)):\n sum = 0\n for j in range(i, len(s)):\n sum += int(s[j])\n if sum == j - i + 1:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/62", "solution": "def smallest_num(lst):\n \"\"\"\n Find the smallest number in a list.\n\n Parameters:\n lst (list): A list of numbers.\n\n Returns:\n int: The smallest number in the list.\n \"\"\"\n return min(lst)"} | |
| {"task_id": "Mbpp/63", "solution": "def max_difference(pairs):\n \"\"\"\n Find the maximum difference between available pairs in the given tuple list.\n\n Args:\n pairs (list of tuples): A list of tuples, where each tuple contains two integers.\n\n Returns:\n int: The maximum difference between the second and first elements of the tuples.\n\n Examples:\n >>> max_difference([(3, 5), (1, 7), (10, 3), (1, 2)])\n 7\n \"\"\"\n return max(pair[1] - pair[0] for pair in pairs)"} | |
| {"task_id": "Mbpp/64", "solution": "def subject_marks(subjects):\n \"\"\"\n Sorts a list of tuples based on the second value of each tuple.\n\n Args:\n subjects (list): A list of tuples where each tuple contains a subject name and its corresponding marks.\n\n Returns:\n list: A sorted list of tuples based on the marks.\n \"\"\"\n return sorted(subjects, key=lambda x: x[1])"} | |
| {"task_id": "Mbpp/65", "solution": "def recursive_list_sum(lst):\n total = 0\n for item in lst:\n if isinstance(item, list):\n total += recursive_list_sum(item)\n else:\n total += item\n return total"} | |
| {"task_id": "Mbpp/66", "solution": "def pos_count(numbers):\n \"\"\"\n Count the number of positive numbers in a list.\n\n Args:\n numbers (list): A list of numbers.\n\n Returns:\n int: The count of positive numbers in the list.\n \"\"\"\n return sum(1 for num in numbers if num > 0)"} | |
| {"task_id": "Mbpp/67", "solution": "from math import factorial\ndef bell_number(n):\n bell = [0] * (n+1)\n bell[0] = 1\n for i in range(1, n+1):\n bell[i] = sum(bell[k] * (i-k) for k in range(i)) // i\n return bell[n]"} | |
| {"task_id": "Mbpp/68", "solution": "def is_Monotonic(arr):\n \"\"\"\n Check if the given array is monotonic or not.\n An array is monotonic if it is either entirely non-increasing or non-decreasing.\n\n Args:\n arr (list): The input list of integers.\n\n Returns:\n bool: True if the array is monotonic, False otherwise.\n \"\"\"\n increasing = decreasing = True\n\n for i in range(1, len(arr)):\n if arr[i] > arr[i - 1]:\n decreasing = False\n elif arr[i] < arr[i - 1]:\n increasing = False\n\n return increasing or decreasing"} | |
| {"task_id": "Mbpp/69", "solution": "def is_sublist(main_list, sub_list):\n \"\"\"\n Check if the main_list contains the sub_list.\n\n Args:\n main_list (list): The list to be checked.\n sub_list (list): The sublist to look for.\n\n Returns:\n bool: True if sub_list is found in main_list, False otherwise.\n \"\"\"\n # Iterate over the main list\n for i in range(len(main_list) - len(sub_list) + 1):\n # Check if the sublist matches the current slice of the main list\n if main_list[i:i+len(sub_list)] == sub_list:\n return True\n return False"} | |
| {"task_id": "Mbpp/70", "solution": "def get_equal(tuples):\n \"\"\"\n Check if all tuples in the list have equal length.\n\n Args:\n tuples (list): A list of tuples.\n\n Returns:\n bool: True if all tuples have equal length, False otherwise.\n \"\"\"\n if not tuples: # Check if the list is empty\n return True\n first_length = len(tuples[0])\n return all(len(t) == first_length for t in tuples)"} | |
| {"task_id": "Mbpp/71", "solution": "def comb_sort(lst):\n gap = len(lst)\n shrink_factor = 1.3\n sorted_flag = False\n\n while not sorted_flag:\n gap = int(gap / shrink_factor)\n if gap <= 1:\n gap = 1\n sorted_flag = True\n\n i = 0\n while i + gap < len(lst):\n if lst[i] > lst[i + gap]:\n lst[i], lst[i + gap] = lst[i + gap], lst[i]\n sorted_flag = False\n i += 1\n\n return lst"} | |
| {"task_id": "Mbpp/72", "solution": "def dif_Square(n):\n \"\"\"\n Check if the given number can be represented as the difference of two squares.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if the number can be represented as the difference of two squares, False otherwise.\n \"\"\"\n # A number can be represented as the difference of two squares if and only if it is not of the form 4k+2\n return n % 4 != 2"} | |
| {"task_id": "Mbpp/74", "solution": "def is_samepatterns(colors, patterns):\n \"\"\"\n Check if the colors follow the sequence given in the patterns array.\n\n Parameters:\n colors (list): A list of color strings.\n patterns (list): A list of pattern strings.\n\n Returns:\n bool: True if the colors follow the sequence, False otherwise.\n \"\"\"\n if len(colors) != len(patterns):\n return False\n color_to_pattern = {}\n for color, pattern in zip(colors, patterns):\n if color in color_to_pattern and color_to_pattern[color] != pattern:\n return False\n color_to_pattern[color] = pattern\n return True"} | |
| {"task_id": "Mbpp/75", "solution": "def find_tuples(tuples_list, k):\n \"\"\"\n Find tuples which have all elements divisible by k from the given list of tuples.\n\n Args:\n tuples_list (list): A list of tuples.\n k (int): The divisor.\n\n Returns:\n list: A list of tuples with all elements divisible by k.\n \"\"\"\n result = []\n for tup in tuples_list:\n if all(x % k == 0 for x in tup):\n result.append(tup)\n return result"} | |
| {"task_id": "Mbpp/77", "solution": "def is_Diff(num):\n \"\"\"\n Check if a number is divisible by 11.\n\n Args:\n num (int): The number to check.\n\n Returns:\n bool: True if the number is divisible by 11, False otherwise.\n \"\"\"\n return num % 11 == 0"} | |
| {"task_id": "Mbpp/79", "solution": "def word_len(word):\n \"\"\"\n Check if the length of the word is odd.\n\n Parameters:\n word (str): The word to check.\n\n Returns:\n bool: True if the length of the word is odd, False otherwise.\n \"\"\"\n return len(word) % 2 != 0"} | |
| {"task_id": "Mbpp/80", "solution": "def tetrahedral_number(n):\n \"\"\"\n Calculate the nth tetrahedral number.\n\n Args:\n n (int): The position of the tetrahedral number to calculate.\n\n Returns:\n int: The nth tetrahedral number.\n \"\"\"\n return int(n * (n + 1) * (n + 2) / 6)"} | |
| {"task_id": "Mbpp/82", "solution": "import math\ndef volume_sphere(radius):\n \"\"\"\n Calculate the volume of a sphere given its radius.\n\n Parameters:\n radius (float): The radius of the sphere.\n\n Returns:\n float: The volume of the sphere.\n \"\"\"\n return (4/3) * math.pi * radius**3"} | |
| {"task_id": "Mbpp/84", "solution": "def sequence(n):\n \"\"\"\n Find the nth number in the Newman-Conway sequence.\n\n Args:\n n (int): The position in the sequence to find.\n\n Returns:\n int: The nth number in the Newman-Conway sequence.\n \"\"\"\n if n == 1:\n return 1\n elif n == 2:\n return 1\n else:\n sequence = [0, 1, 1]\n for i in range(3, n + 1):\n sequence.append(sequence[sequence[i - 1]] + sequence[i - sequence[i - 1]])\n return sequence[n]"} | |
| {"task_id": "Mbpp/85", "solution": "import math\ndef surfacearea_sphere(radius):\n \"\"\"\n Calculate the surface area of a sphere given its radius.\n\n Parameters:\n radius (float): The radius of the sphere.\n\n Returns:\n float: The surface area of the sphere.\n \"\"\"\n return 4 * math.pi * radius ** 2"} | |
| {"task_id": "Mbpp/86", "solution": "def centered_hexagonal_number(n):\n \"\"\"\n Calculate the nth centered hexagonal number.\n \"\"\"\n return 3 * n * (n - 1) + 1"} | |
| {"task_id": "Mbpp/87", "solution": "def merge_dictionaries_three(dict1, dict2, dict3):\n \"\"\"\n Merge three dictionaries into a single dictionary.\n \n Parameters:\n dict1 (dict): First dictionary.\n dict2 (dict): Second dictionary.\n dict3 (dict): Third dictionary.\n \n Returns:\n dict: Merged dictionary.\n \"\"\"\n merged_dict = {**dict1, **dict2, **dict3}\n return merged_dict"} | |
| {"task_id": "Mbpp/88", "solution": "def freq_count(lst):\n \"\"\"\n Returns a dictionary with the frequency of all elements in the input list.\n\n Parameters:\n lst (list): The input list.\n\n Returns:\n dict: A dictionary with the frequency of all elements in the input list.\n \"\"\"\n freq_dict = {}\n for item in lst:\n if item in freq_dict:\n freq_dict[item] += 1\n else:\n freq_dict[item] = 1\n return freq_dict"} | |
| {"task_id": "Mbpp/89", "solution": "def closest_num(n):\n \"\"\"\n Find the closest smaller number than n.\n\n Args:\n n (int): The input number.\n\n Returns:\n int: The closest smaller number than n.\n \"\"\"\n return n - 1"} | |
| {"task_id": "Mbpp/90", "solution": "def len_log(words):\n \"\"\"\n Find the length of the longest word in a list of words.\n\n Args:\n words (list): A list of words.\n\n Returns:\n int: The length of the longest word.\n \"\"\"\n return max(len(word) for word in words)"} | |
| {"task_id": "Mbpp/91", "solution": "def find_substring(values, substring):\n \"\"\"\n Check if a string is present as a substring in a given list of string values.\n\n Parameters:\n values (list): A list of string values.\n substring (str): The substring to search for.\n\n Returns:\n bool: True if the substring is found, False otherwise.\n \"\"\"\n return any(substring in value for value in values)"} | |
| {"task_id": "Mbpp/92", "solution": "def is_undulating(number):\n \"\"\"\n Check if the given number is undulating.\n\n Args:\n number (int): The number to check.\n\n Returns:\n bool: True if the number is undulating, False otherwise.\n \"\"\"\n str_num = str(number)\n if len(str_num) < 3 or len(set(str_num)) != 2:\n return False\n for i in range(1, len(str_num) - 1):\n if str_num[i - 1] != str_num[i] != str_num[i + 1]:\n return False\n return True"} | |
| {"task_id": "Mbpp/93", "solution": "def power(a, b):\n \"\"\"\n Calculate the value of 'a' to the power 'b'.\n\n Args:\n a (int): The base number.\n b (int): The exponent.\n\n Returns:\n int: The result of 'a' raised to the power 'b'.\n \"\"\"\n return a ** b"} | |
| {"task_id": "Mbpp/94", "solution": "def index_minimum(lst):\n \"\"\"\n Given a list of tuples, returns the first value of the tuple with the smallest second value.\n \"\"\"\n return min(lst, key=lambda x: x[1])[0]"} | |
| {"task_id": "Mbpp/95", "solution": "def Find_Min_Length(lst_of_lsts):\n \"\"\"\n Finds the length of the smallest list within a list of lists.\n\n Parameters:\n lst_of_lsts (list): A list containing other lists.\n\n Returns:\n int: The length of the smallest list.\n \"\"\"\n if not lst_of_lsts: # Check if the input list is empty\n return 0\n min_length = len(lst_of_lsts[0]) # Initialize min_length with the length of the first list\n for lst in lst_of_lsts:\n if len(lst) < min_length:\n min_length = len(lst)\n return min_length"} | |
| {"task_id": "Mbpp/96", "solution": "def divisor(n):\n \"\"\"\n Returns the number of divisors of a given integer.\n\n Args:\n n (int): The integer to find the divisors for.\n\n Returns:\n int: The number of divisors of the given integer.\n \"\"\"\n count = 0\n for i in range(1, n + 1):\n if n % i == 0:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/97", "solution": "def frequency_lists(nested_list):\n \"\"\"\n Finds the frequency of each element in a flattened list of lists and returns a dictionary with the frequencies.\n \n Args:\n nested_list (list): A list of lists containing elements.\n \n Returns:\n dict: A dictionary with elements as keys and their frequencies as values.\n \"\"\"\n from collections import Counter\n flat_list = [item for sublist in nested_list for item in sublist]\n return dict(Counter(flat_list))"} | |
| {"task_id": "Mbpp/98", "solution": "def multiply_num(numbers):\n \"\"\"\n Multiplies all the numbers in a list and divides the result by the length of the list.\n\n Args:\n numbers (tuple): A tuple of numbers.\n\n Returns:\n float: The result of multiplying all numbers in the tuple and dividing by the length of the tuple.\n \"\"\"\n product = 1\n for num in numbers:\n product *= num\n return product / len(numbers)"} | |
| {"task_id": "Mbpp/99", "solution": "def decimal_to_binary(n):\n \"\"\"\n Convert a decimal number to its binary equivalent as a string.\n\n Args:\n n (int): The decimal number to convert.\n\n Returns:\n str: The binary equivalent of the decimal number as a string.\n \"\"\"\n return bin(n)[2:]"} | |
| {"task_id": "Mbpp/100", "solution": "def next_smallest_palindrome(n):\n \"\"\"\n Find the next smallest palindrome of a specified integer, returned as an integer.\n \"\"\"\n n += 1 # Increment the number to start searching for the next palindrome\n while not is_palindrome(n):\n n += 1\n return n\ndef is_palindrome(num):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]"} | |
| {"task_id": "Mbpp/101", "solution": "def kth_element(arr, k):\n \"\"\"\n Find the kth element in the given array using 1-based indexing.\n\n Parameters:\n arr (list): The input array.\n k (int): The kth element to find.\n\n Returns:\n int: The kth element in the array.\n \"\"\"\n return arr[k - 1]"} | |
| {"task_id": "Mbpp/102", "solution": "def snake_to_camel(snake_str):\n \"\"\"\n Convert a snake case string to camel case string.\n\n Parameters:\n snake_str (str): The snake case string to be converted.\n\n Returns:\n str: The converted camel case string.\n \"\"\"\n components = snake_str.split('_')\n # We capitalize the first letter of each component except the first one\n # with the 'title' method and join them together.\n return components[0] + ''.join(x.title() for x in components[1:])"} | |
| {"task_id": "Mbpp/103", "solution": "def eulerian_num(n, m):\n \"\"\"\n Calculate the Eulerian number a(n, m).\n \"\"\"\n if m == 0:\n return 1\n if m == n:\n return 1\n if n < m:\n return 0\n return (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)"} | |
| {"task_id": "Mbpp/104", "solution": "def sort_sublists(list_of_lists):\n \"\"\"\n Sorts each sublist of strings in a given list of lists.\n\n Args:\n list_of_lists (list): A list of lists containing strings.\n\n Returns:\n list: A new list of lists with each sublist sorted.\n \"\"\"\n return [sorted(sublist) for sublist in list_of_lists]"} | |
| {"task_id": "Mbpp/105", "solution": "def count_true_values(lst):\n \"\"\"\n Count the number of True values in the given list.\n\n Parameters:\n lst (list): A list of boolean values.\n\n Returns:\n int: The number of True values in the list.\n \"\"\"\n return sum(lst)\n\n# Test cases\nassert count_true_values([True, False, True]) == 2\nassert count_true_values([True, True, True, False, False]) == 3\nassert count_true_values([False, False, False]) == 0\nassert count_true_values([True]) == 1\nassert count_true_values([]) == 0"} | |
| {"task_id": "Mbpp/106", "solution": "def add_lists(lst, tup):\n \"\"\"\n Append the given list to the given tuple and return the result.\n\n Parameters:\n lst (list): The list to be appended.\n tup (tuple): The tuple to which the list will be appended.\n\n Returns:\n tuple: The resulting tuple after appending the list.\n \"\"\"\n return tup + tuple(lst)"} | |
| {"task_id": "Mbpp/108", "solution": "def merge_sorted_list(list1, list2, list3):\n \"\"\"\n Merge three sorted lists into a single sorted list.\n\n Args:\n list1 (list): The first sorted list.\n list2 (list): The second sorted list.\n list3 (list): The third sorted list.\n\n Returns:\n list: A single sorted list containing all elements from the input lists.\n \"\"\"\n merged_list = list1 + list2 + list3\n merged_list.sort()\n return merged_list"} | |
| {"task_id": "Mbpp/109", "solution": "def odd_Equivalent(binary_str, rotations):\n \"\"\"\n Calculate the number of binary numbers with an odd value after rotating the binary string a given number of times.\n\n Args:\n binary_str (str): The binary string to be rotated.\n rotations (int): The number of times to rotate the binary string.\n\n Returns:\n int: The number of binary numbers with an odd value after the rotations.\n \"\"\"\n odd_count = 0\n for i in range(rotations):\n binary_str = binary_str[-1] + binary_str[:-1]\n if int(binary_str, 2) % 2 != 0:\n odd_count += 1\n return odd_count"} | |
| {"task_id": "Mbpp/111", "solution": "def common_in_nested_lists(nested_lists):\n \"\"\"\n Find the common elements in given nested lists.\n\n Args:\n nested_lists (list): A list of lists containing integers.\n\n Returns:\n set: A set of common elements found in all the nested lists.\n \"\"\"\n if not nested_lists:\n return set()\n\n # Convert the first list to a set for efficient lookups\n common_elements = set(nested_lists[0])\n\n # Iterate over the remaining lists and update the set of common elements\n for lst in nested_lists[1:]:\n common_elements.intersection_update(lst)\n\n return common_elements"} | |
| {"task_id": "Mbpp/113", "solution": "def check_integer(s):\n \"\"\"\n Check if the given string represents an integer or not.\n\n Args:\n s (str): The string to be checked.\n\n Returns:\n bool: True if the string represents an integer, False otherwise.\n \"\"\"\n return s.isdigit() or (s.startswith('-') and s[1:].isdigit())"} | |
| {"task_id": "Mbpp/116", "solution": "def tuple_to_int(tup):\n \"\"\"\n Convert a tuple of positive integers into a single integer.\n \n Parameters:\n tup (tuple): A tuple of positive integers.\n \n Returns:\n int: The resulting integer after concatenating the tuple elements.\n \"\"\"\n return int(''.join(map(str, tup)))"} | |
| {"task_id": "Mbpp/118", "solution": "def string_to_list(input_string):\n \"\"\"\n Splits the input string on spaces and returns a list of the resulting substrings.\n\n Parameters:\n input_string (str): The string to be split.\n\n Returns:\n list: A list of substrings obtained by splitting the input string on spaces.\n \"\"\"\n return input_string.split()"} | |
| {"task_id": "Mbpp/119", "solution": "def search(arr):\n \"\"\"\n Finds the element that appears only once in a sorted array.\n \n Args:\n arr (list): A sorted list of integers where all elements appear twice except one.\n \n Returns:\n int: The element that appears only once.\n \"\"\"\n left, right = 0, len(arr) - 1\n while left < right:\n mid = (left + right) // 2\n if mid % 2 == 1:\n mid -= 1\n if arr[mid] == arr[mid + 1]:\n left = mid + 2\n else:\n right = mid\n return arr[left]"} | |
| {"task_id": "Mbpp/120", "solution": "def max_product_tuple(pairs):\n \"\"\"\n Finds the maximum absolute product between numbers in pairs of tuples within a given list.\n\n Args:\n pairs (list): A list of tuples containing two integers each.\n\n Returns:\n int: The maximum absolute product of the pairs.\n\n Examples:\n >>> max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)])\n 36\n \"\"\"\n return max(abs(a * b) for a, b in pairs)"} | |
| {"task_id": "Mbpp/123", "solution": "def amicable_numbers_sum(n):\n \"\"\"\n Calculate the sum of all amicable numbers from 1 to n.\n\n Args:\n n (int): The upper limit for finding amicable numbers.\n\n Returns:\n int: The sum of all amicable numbers from 1 to n.\n \"\"\"\n def sum_of_divisors(num):\n divisors_sum = 1\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n divisors_sum += i\n if i != num // i:\n divisors_sum += num // i\n return divisors_sum\n\n amicable_sum = 0\n for num in range(2, n + 1):\n partner = sum_of_divisors(num)\n if partner > num and sum_of_divisors(partner) == num:\n amicable_sum += num + partner\n\n return amicable_sum // 2"} | |
| {"task_id": "Mbpp/124", "solution": "import cmath\ndef angle_complex(real, imag):\n \"\"\"\n Calculate the angle of a complex number.\n\n Parameters:\n real (float): The real part of the complex number.\n imag (float): The imaginary part of the complex number.\n\n Returns:\n float: The angle of the complex number in radians.\n \"\"\"\n return cmath.phase(complex(real, imag))"} | |
| {"task_id": "Mbpp/125", "solution": "def find_max_diff_zeros_ones(binary_str):\n max_diff = 0\n current_diff = 0\n for char in binary_str:\n current_diff += 1 if char == '0' else -1\n max_diff = max(max_diff, current_diff)\n if current_diff < 0:\n current_diff = 0\n return max_diff\n\n# Test cases\nassert find_max_diff_zeros_ones(\"11000010001\") == 6\nassert find_max_diff_zeros_ones(\"10111\") == 0\nassert find_max_diff_zeros_ones(\"00011100011000\") == 9"} | |
| {"task_id": "Mbpp/126", "solution": "def sum_common_divisors(a, b):\n \"\"\"\n Calculate the sum of common divisors of two given numbers.\n\n Args:\n a (int): The first number.\n b (int): The second number.\n\n Returns:\n int: The sum of common divisors of a and b.\n \"\"\"\n def get_divisors(n):\n divisors = set()\n for i in range(1, int(n**0.5) + 1):\n if n % i == 0:\n divisors.add(i)\n divisors.add(n // i)\n return divisors\n\n divisors_a = get_divisors(a)\n divisors_b = get_divisors(b)\n common_divisors = divisors_a.intersection(divisors_b)\n return sum(common_divisors)\n\n# Test cases\nassert sum_common_divisors(10, 15) == 6\nassert sum_common_divisors(12, 18) == 13\nassert sum_common_divisors(100, 200) == 217"} | |
| {"task_id": "Mbpp/127", "solution": "def multiply_int(a, b):\n \"\"\"\n Multiply two integers.\n\n Parameters:\n a (int): The first integer.\n b (int): The second integer.\n\n Returns:\n int: The product of the two integers.\n \"\"\"\n return a * b"} | |
| {"task_id": "Mbpp/128", "solution": "def long_words(n, words):\n \"\"\"\n Write a function to find words that are longer than n characters from a given list of words.\n assert long_words(3,\"python is a programming language\")==['python','programming','language']\n \"\"\"\n return [word for word in words.split() if len(word) > n]"} | |
| {"task_id": "Mbpp/129", "solution": "def is_magic_square(matrix):\n \"\"\"\n Check if the given matrix is a magic square.\n \n Args:\n matrix (list of lists of int): The matrix to check.\n \n Returns:\n bool: True if the matrix is a magic square, False otherwise.\n \"\"\"\n n = len(matrix)\n if any(len(row) != n for row in matrix):\n return False # Not a square matrix\n \n magic_sum = sum(matrix[0])\n \n # Check rows and columns\n for i in range(n):\n if sum(matrix[i]) != magic_sum or sum(matrix[j][i] for j in range(n)) != magic_sum:\n return False\n \n # Check diagonals\n if sum(matrix[i][i] for i in range(n)) != magic_sum or sum(matrix[i][n-1-i] for i in range(n)) != magic_sum:\n return False\n \n return True\n\n# Test cases\nassert is_magic_square([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]]) == True\nassert is_magic_square([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == False\nassert is_magic_square([[2, 7, 6], [9, 5, 1], [4, 3, 8]]) == True\nassert is_magic_square([[1, 2], [3, 4]]) == False"} | |
| {"task_id": "Mbpp/130", "solution": "from collections import Counter\ndef max_occurrences(lst):\n \"\"\"\n Find the item with maximum frequency in a given list.\n\n Parameters:\n lst (list): The input list.\n\n Returns:\n int: The item with maximum frequency.\n \"\"\"\n counter = Counter(lst)\n max_item = counter.most_common(1)[0][0]\n return max_item"} | |
| {"task_id": "Mbpp/131", "solution": "def reverse_vowels(s: str) -> str:\n \"\"\"\n Reverse only the vowels of a given string (where y is not a vowel).\n \"\"\"\n vowels = \"aeiouAEIOU\"\n s_list = list(s)\n left, right = 0, len(s) - 1\n while left < right:\n if s_list[left] not in vowels:\n left += 1\n elif s_list[right] not in vowels:\n right -= 1\n else:\n s_list[left], s_list[right] = s_list[right], s_list[left]\n left += 1\n right -= 1\n return \"\".join(s_list)"} | |
| {"task_id": "Mbpp/132", "solution": "def tup_string(tup):\n \"\"\"\n Convert a tuple to a string.\n\n Parameters:\n tup (tuple): The tuple to be converted.\n\n Returns:\n str: The converted string.\n \"\"\"\n return ''.join(tup)"} | |
| {"task_id": "Mbpp/133", "solution": "def sum_negative_numbers(numbers):\n \"\"\"\n Calculate the sum of the negative numbers in a given list of numbers.\n\n Args:\n numbers (list): A list of numbers.\n\n Returns:\n int: The sum of the negative numbers in the list.\n \"\"\"\n return sum(num for num in numbers if num < 0)\n\n# Test cases\nassert sum_negative_numbers([2, 4, -6, -9, 11, -12, 14, -5, 17]) == -32\nassert sum_negative_numbers([1, 2, 3, 4, 5]) == 0\nassert sum_negative_numbers([-1, -2, -3, -4, -5]) == -15\nassert sum_negative_numbers([]) == 0"} | |
| {"task_id": "Mbpp/135", "solution": "def hexagonal_num(n):\n \"\"\"\n Calculate the nth hexagonal number.\n \n Args:\n n (int): The position of the hexagonal number to calculate.\n \n Returns:\n int: The nth hexagonal number.\n \"\"\"\n return n * (2 * n - 1)"} | |
| {"task_id": "Mbpp/137", "solution": "def zero_ratio(arr):\n \"\"\"\n Calculate the ratio of zeroes to non-zeroes in an array of integers.\n\n Parameters:\n arr (list): A list of integers.\n\n Returns:\n float: The ratio of zeroes to non-zeroes in the array.\n \"\"\"\n zero_count = arr.count(0)\n non_zero_count = len(arr) - zero_count\n if non_zero_count == 0:\n return 0.0\n return zero_count / non_zero_count\n\n# Test cases\nassert math.isclose(zero_ratio([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, rel_tol=0.001)\nassert math.isclose(zero_ratio([0, 0, 0, 0, 0]), 1.0)\nassert math.isclose(zero_ratio([1, 2, 3, 4, 5]), 0.0)"} | |
| {"task_id": "Mbpp/138", "solution": "def is_Sum_Of_Powers_Of_Two(n):\n \"\"\"\n Check if the given number can be represented as sum of non-zero powers of 2.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if the number can be represented as sum of non-zero powers of 2, False otherwise.\n \"\"\"\n # Check if the number is a power of 2\n if n & (n - 1) == 0:\n return True\n # Check if the number can be represented as sum of non-zero powers of 2\n while n > 0:\n # If the last bit is set, subtract 2^(number of trailing zeros) from the number\n if n & 1 == 1:\n n -= (1 << n.bit_length() - 1)\n # If the number becomes 0, it can be represented as sum of non-zero powers of 2\n if n == 0:\n return True\n # If the number becomes negative, it cannot be represented as sum of non-zero powers of 2\n if n < 0:\n return False\n # Right shift the number to check the next bit\n n >>= 1\n return False"} | |
| {"task_id": "Mbpp/139", "solution": "import math\ndef circle_circumference(radius):\n \"\"\"\n Calculate the circumference of a circle given its radius.\n\n Parameters:\n radius (float): The radius of the circle.\n\n Returns:\n float: The circumference of the circle.\n \"\"\"\n return 2 * math.pi * radius"} | |
| {"task_id": "Mbpp/140", "solution": "def extract_singly(list_of_lists):\n \"\"\"\n Flatten a list of lists into a single set of numbers.\n\n Args:\n list_of_lists (list): A list containing other lists of integers.\n\n Returns:\n set: A set containing all unique integers from the nested lists.\n \"\"\"\n return set(number for sublist in list_of_lists for number in sublist)"} | |
| {"task_id": "Mbpp/141", "solution": "def pancake_sort(arr):\n \"\"\"\n Sorts a list of elements using the pancake sort algorithm.\n\n Args:\n arr (list): The list of elements to be sorted.\n\n Returns:\n list: The sorted list of elements.\n \"\"\"\n n = len(arr)\n while n > 1:\n # Find the index of the maximum element in arr[0:n]\n max_idx = arr.index(max(arr[0:n]))\n # Reverse the array from 0 to max_idx\n arr[:max_idx+1] = reversed(arr[:max_idx+1])\n # Reverse the entire array\n arr[:n] = reversed(arr[:n])\n # Reduce the size of the array\n n -= 1\n return arr"} | |
| {"task_id": "Mbpp/142", "solution": "def count_samepair(list1, list2, list3):\n \"\"\"\n Count the number of items that are identical in the same position of three given lists.\n\n Args:\n list1, list2, list3: Three lists of integers.\n\n Returns:\n The count of identical items in the same position in the three lists.\n\n Example:\n >>> count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])\n 3\n \"\"\"\n return sum(1 for a, b, c in zip(list1, list2, list3) if a == b == c)"} | |
| {"task_id": "Mbpp/145", "solution": "def max_Abs_Diff(arr):\n \"\"\"\n Find the maximum absolute difference between any two elements in a given array.\n\n Parameters:\n arr (tuple): A tuple of integers.\n\n Returns:\n int: The maximum absolute difference between any two elements in the array.\n \"\"\"\n if not arr or len(arr) < 2:\n return 0\n\n min_element = arr[0]\n max_diff = 0\n\n for i in range(1, len(arr)):\n if arr[i] < min_element:\n min_element = arr[i]\n else:\n max_diff = max(max_diff, arr[i] - min_element)\n\n return max_diff"} | |
| {"task_id": "Mbpp/160", "solution": "def find_solution(a, b, n):\n \"\"\"\n Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.\n \"\"\"\n for x in range(n + 1):\n if (n - a * x) % b == 0:\n return (x, (n - a * x) // b)\n return None"} | |
| {"task_id": "Mbpp/161", "solution": "def remove_elements(original_list, elements_to_remove):\n \"\"\"\n Removes all elements from `original_list` that are present in `elements_to_remove`.\n\n Parameters:\n original_list (list): The list from which elements will be removed.\n elements_to_remove (list): The list containing elements to be removed from the original list.\n\n Returns:\n list: A new list with the elements removed.\n \"\"\"\n return [element for element in original_list if element not in elements_to_remove]"} | |
| {"task_id": "Mbpp/162", "solution": "def sum_series(n):\n \"\"\"\n Calculate the sum of the series (n - 2*i) from i=0 to n // 2.\n \n Args:\n n (int): The starting number of the series.\n \n Returns:\n int: The sum of the series.\n \"\"\"\n return sum(n - 2 * i for i in range(n // 2 + 1))"} | |
| {"task_id": "Mbpp/165", "solution": "def count_char_position(s):\n \"\"\"\n Count the number of characters in a string that occur at the same position as in the English alphabet (case insensitive).\n\n Args:\n s (str): The input string.\n\n Returns:\n int: The count of characters occurring at the same position as in the English alphabet.\n \"\"\"\n count = 0\n for i, char in enumerate(s, 1):\n if char.lower() == chr(ord('a') + i - 1):\n count += 1\n return count"} | |
| {"task_id": "Mbpp/166", "solution": "def find_even_pair(lst):\n \"\"\"\n Counts the number of pairs of integers in a list that xor to an even number.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n int: The number of pairs that xor to an even number.\n \"\"\"\n even_count = 0\n for i in range(len(lst)):\n for j in range(i + 1, len(lst)):\n if (lst[i] ^ lst[j]) % 2 == 0:\n even_count += 1\n return even_count"} | |
| {"task_id": "Mbpp/167", "solution": "def next_power_of_2(n):\n \"\"\"\n Find the smallest power of 2 greater than or equal to n.\n\n Args:\n n (int): The input number.\n\n Returns:\n int: The smallest power of 2 greater than or equal to n.\n \"\"\"\n if n == 0:\n return 1\n power = 1\n while power < n:\n power *= 2\n return power"} | |
| {"task_id": "Mbpp/168", "solution": "def frequency(lst, num):\n \"\"\"\n Count the number of occurrences of a number in a given list.\n\n Parameters:\n lst (list): The list of numbers.\n num (int): The number to count.\n\n Returns:\n int: The number of occurrences of the number in the list.\n \"\"\"\n return lst.count(num)"} | |
| {"task_id": "Mbpp/170", "solution": "def sum_range_list(lst, start_index, end_index):\n \"\"\"\n Calculate the sum of numbers in a list within a range specified by two indices.\n\n Args:\n lst (list): The input list of numbers.\n start_index (int): The starting index of the range.\n end_index (int): The ending index of the range.\n\n Returns:\n int: The sum of numbers within the specified range.\n\n Example:\n >>> sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10)\n 29\n \"\"\"\n return sum(lst[start_index:end_index+1])"} | |
| {"task_id": "Mbpp/171", "solution": "def perimeter_pentagon(side_length):\n \"\"\"\n Calculate the perimeter of a regular pentagon given the length of one side.\n\n Parameters:\n side_length (int): The length of one side of the pentagon.\n\n Returns:\n int: The perimeter of the pentagon.\n \"\"\"\n return 5 * side_length"} | |
| {"task_id": "Mbpp/172", "solution": "def count_occurrences(input_string):\n \"\"\"\n Counts the number of occurrences of the substring 'std' in the given input string.\n\n Args:\n input_string (str): The string in which to count occurrences of 'std'.\n\n Returns:\n int: The number of occurrences of 'std' in the input string.\n \"\"\"\n return input_string.count('std')\n\n# Test cases to verify the correctness of the function\nassert count_occurrences(\"letstdlenstdporstd\") == 3\nassert count_occurrences(\"stdstdstd\") == 3\nassert count_occurrences(\"no occurrences here\") == 0\nassert count_occurrences(\"std at the start std\") == 2\nassert count_occurrences(\"std at the end std\") == 2\nassert count_occurrences(\"std in the middle std\") == 2\nassert count_occurrences(\"stdstdstdstdstd\") == 5\nassert count_occurrences(\"std\") == 1\nassert count_occurrences(\"\") == 0"} | |
| {"task_id": "Mbpp/222", "solution": "def check_type(tup):\n \"\"\"\n Check if all elements in the tuple have the same data type.\n\n Args:\n tup (tuple): The input tuple.\n\n Returns:\n bool: True if all elements have the same data type, False otherwise.\n \"\"\"\n if not tup:\n return True\n first_type = type(tup[0])\n return all(isinstance(item, first_type) for item in tup)"} | |
| {"task_id": "Mbpp/223", "solution": "def is_majority(arr, n, x):\n \"\"\"\n Check if x is the majority element in the sorted array arr.\n \"\"\"\n # Find the first occurrence of x in arr\n first_occurrence = -1\n for i in range(n):\n if arr[i] == x:\n first_occurrence = i\n break\n\n # If x is not present in arr, return False\n if first_occurrence == -1:\n return False\n\n # Find the last occurrence of x in arr\n last_occurrence = -1\n for i in range(n - 1, -1, -1):\n if arr[i] == x:\n last_occurrence = i\n break\n\n # If the number of occurrences of x is greater than n/2, return True\n if (last_occurrence - first_occurrence + 1) > (n // 2):\n return True\n else:\n return False"} | |
| {"task_id": "Mbpp/224", "solution": "def count_Set_Bits(n):\n \"\"\"\n Count the number of set bits (binary digits with value 1) in a given number.\n\n Args:\n n (int): The number to count set bits in.\n\n Returns:\n int: The count of set bits in the given number.\n \"\"\"\n count = 0\n while n:\n count += n & 1\n n >>= 1\n return count"} | |
| {"task_id": "Mbpp/226", "solution": "def odd_values_string(input_string):\n \"\"\"\n Removes characters from the input string that have odd index values.\n\n Args:\n input_string (str): The string from which characters with odd index values will be removed.\n\n Returns:\n str: A new string with characters at odd index values removed.\n \"\"\"\n # Initialize an empty string to store the result\n result_string = \"\"\n\n # Iterate over the input string, starting from index 0, with a step of 2\n for index in range(0, len(input_string), 2):\n # Append the character at the current even index to the result string\n result_string += input_string[index]\n\n return result_string"} | |
| {"task_id": "Mbpp/227", "solution": "def min_of_three(num1, num2, num3):\n \"\"\"\n Returns the minimum of three numbers.\n\n Parameters:\n num1 (int): The first number.\n num2 (int): The second number.\n num3 (int): The third number.\n\n Returns:\n int: The minimum of the three numbers.\n \"\"\"\n return min(num1, num2, num3)"} | |
| {"task_id": "Mbpp/230", "solution": "def replace_blank(input_string, replacement_char):\n \"\"\"\n Replaces blank spaces in the input string with the replacement character.\n\n Parameters:\n input_string (str): The string to be processed.\n replacement_char (str): The character to replace blank spaces with.\n\n Returns:\n str: The processed string with blank spaces replaced by the replacement character.\n \"\"\"\n return input_string.replace(\" \", replacement_char)"} | |
| {"task_id": "Mbpp/232", "solution": "def larg_nnum(lst, n):\n \"\"\"\n Returns a list containing the n largest items from the given list.\n\n Args:\n lst (list): The input list.\n n (int): The number of largest items to return.\n\n Returns:\n list: A list containing the n largest items from the input list.\n \"\"\"\n if not lst or n <= 0:\n return []\n if n >= len(lst):\n return sorted(lst, reverse=True)\n return sorted(lst, reverse=True)[:n]"} | |
| {"task_id": "Mbpp/233", "solution": "import math\ndef lateralsuface_cylinder(radius, height):\n \"\"\"\n Calculate the lateral surface area of a cylinder.\n\n Parameters:\n radius (float): The radius of the cylinder.\n height (float): The height of the cylinder.\n\n Returns:\n float: The lateral surface area of the cylinder.\n \"\"\"\n return 2 * math.pi * radius * height"} | |
| {"task_id": "Mbpp/234", "solution": "def volume_cube(side_length):\n \"\"\"\n Calculate the volume of a cube given its side length.\n\n Parameters:\n side_length (float): The length of a side of the cube.\n\n Returns:\n float: The volume of the cube.\n \"\"\"\n return side_length ** 3"} | |
| {"task_id": "Mbpp/235", "solution": "def even_bit_set_number(num):\n \"\"\"\n Set all even bits of a given number.\n \"\"\"\n # Set all even bits by using the bitwise OR operation with a mask\n return num | 0xAAAAAAAA"} | |
| {"task_id": "Mbpp/237", "solution": "def check_occurrences(lst):\n \"\"\"\n Takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list.\n \"\"\"\n result = {}\n for item in lst:\n if item in result:\n result[item] += 1\n else:\n result[item] = 1\n return result\n\n# Test cases\nassert check_occurrences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)]) == {(3, 1): 1, (1, 3): 1, (2, 5): 1, (5, 2): 1, (6, 3): 1}\nassert check_occurrences([(1, 2), (2, 1), (1, 2), (2, 1)]) == {(1, 2): 2, (2, 1): 2}\nassert check_occurrences([(1, 1), (2, 2), (3, 3), (1, 1)]) == {(1, 1): 2, (2, 2): 1, (3, 3): 1}"} | |
| {"task_id": "Mbpp/238", "solution": "def number_of_substrings(s: str) -> int:\n \"\"\"\n Calculate the number of non-empty substrings of a given string.\n\n Args:\n s (str): The input string.\n\n Returns:\n int: The total number of non-empty substrings.\n \"\"\"\n n = len(s)\n return n * (n + 1) // 2"} | |
| {"task_id": "Mbpp/239", "solution": "def get_total_number_of_sequences(m, n):\n \"\"\"\n This function calculates the number of possible sequences of length n, where each element is a positive integer greater than or equal to twice the previous element but less than or equal to m.\n\n Args:\n m (int): The maximum value for each element in the sequence.\n n (int): The length of the sequence.\n\n Returns:\n int: The total number of possible sequences.\n \"\"\"\n # Create a 2D list to store the number of sequences for each length and maximum value\n dp = [[0] * (m + 1) for _ in range(n + 1)]\n\n # There is one sequence of length 0 for each maximum value\n for i in range(1, m + 1):\n dp[0][i] = 1\n\n # Calculate the number of sequences for each length and maximum value\n for i in range(1, n + 1):\n for j in range(1, m + 1):\n for k in range(1, j // 2 + 1):\n dp[i][j] += dp[i - 1][k]\n\n # The total number of sequences is the sum of sequences ending with each maximum value\n return sum(dp[n])"} | |
| {"task_id": "Mbpp/240", "solution": "def replace_list(lst1, lst2):\n \"\"\"\n Replaces the last element of the first list with the elements of the second list.\n\n Parameters:\n lst1 (list): The first list.\n lst2 (list): The second list.\n\n Returns:\n list: The modified first list with the last element replaced by the second list.\n \"\"\"\n lst1[-1:] = lst2\n return lst1"} | |
| {"task_id": "Mbpp/242", "solution": "def count_charac(s):\n \"\"\"\n Count the total number of characters in a string.\n\n Parameters:\n s (str): The input string.\n\n Returns:\n int: The total number of characters in the string.\n \"\"\"\n return len(s)"} | |
| {"task_id": "Mbpp/244", "solution": "import math\ndef next_Perfect_Square(n):\n \"\"\"\n Find the next perfect square greater than a given number.\n\n Args:\n n (int): The given number.\n\n Returns:\n int: The next perfect square greater than n.\n \"\"\"\n # Calculate the square root of the given number and round it up to the nearest integer\n sqrt_n = math.ceil(math.sqrt(n))\n \n # Calculate the next perfect square by squaring the rounded-up square root\n next_square = sqrt_n ** 2\n \n return next_square"} | |
| {"task_id": "Mbpp/245", "solution": "def max_sum(arr):\n n = len(arr)\n inc = [0] * n\n dec = [0] * n\n inc[0] = arr[0]\n dec[n - 1] = arr[n - 1]\n for i in range(1, n):\n inc[i] = max(inc[i - 1], arr[i])\n for i in range(n - 2, -1, -1):\n dec[i] = max(dec[i + 1], arr[i])\n max_bitonic_sum = 0\n for i in range(n):\n max_bitonic_sum = max(max_bitonic_sum, inc[i] + dec[i] - arr[i])\n return max_bitonic_sum"} | |
| {"task_id": "Mbpp/247", "solution": "def longest_palindromic_subsequence(s: str) -> int:\n \"\"\"\n Finds the length of the longest palindromic subsequence in the given string.\n\n Args:\n s (str): The input string.\n\n Returns:\n int: The length of the longest palindromic subsequence.\n\n Examples:\n >>> longest_palindromic_subsequence(\"TENS FOR TENS\")\n 5\n \"\"\"\n n = len(s)\n dp = [[0] * n for _ in range(n)]\n\n for i in range(n - 1, -1, -1):\n dp[i][i] = 1\n for j in range(i + 1, n):\n if s[i] == s[j]:\n dp[i][j] = 2 + dp[i + 1][j - 1]\n else:\n dp[i][j] = max(dp[i + 1][j], dp[i][j - 1])\n\n return dp[0][n - 1]\n\n# Test cases\nassert longest_palindromic_subsequence(\"TENS FOR TENS\") == 5\nassert longest_palindromic_subsequence(\"ABCCBA\") == 6\nassert longest_palindromic_subsequence(\"A\") == 1\nassert longest_palindromic_subsequence(\"AB\") == 1\nassert longest_palindromic_subsequence(\"ABC\") == 1\nassert longest_palindromic_subsequence(\"ABCD\") == 1\nassert longest_palindromic_subsequence(\"ABCDE\") == 1\nassert longest_palindromic_subsequence(\"ABCDEF\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFG\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGH\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHI\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJ\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJK\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKL\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLM\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMN\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNO\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOP\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQ\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQR\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRS\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRST\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRSTU\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRSTUV\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRSTUVW\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRSTUVWX\") == 1\nassert longest_palindromic_subsequence(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\") == 1"} | |
| {"task_id": "Mbpp/250", "solution": "def count_X(tup, element):\n \"\"\"\n Counts the occurrences of an element in a tuple.\n\n Parameters:\n tup (tuple): The input tuple.\n element: The element to count in the tuple.\n\n Returns:\n int: The number of occurrences of the element in the tuple.\n \"\"\"\n return tup.count(element)"} | |
| {"task_id": "Mbpp/251", "solution": "def insert_element(lst, element):\n \"\"\"\n Inserts an element before each element in the list and returns the resulting list.\n\n Parameters:\n lst (list): The input list.\n element: The element to be inserted before each element in the list.\n\n Returns:\n list: The resulting list after inserting the element before each element in the list.\n \"\"\"\n return [element] + lst"} | |
| {"task_id": "Mbpp/252", "solution": "import cmath"} | |
| {"task_id": "Mbpp/253", "solution": "def count_integer(lst):\n \"\"\"\n Returns the number of integer elements in a given list.\n\n Args:\n lst (list): A list containing elements of any type.\n\n Returns:\n int: The number of integer elements in the list.\n \"\"\"\n return sum(isinstance(item, int) for item in lst)"} | |
| {"task_id": "Mbpp/255", "solution": "from itertools import product\ndef combinations_colors(colors, n):\n \"\"\"\n Generates all combinations (with repetition) of the elements of the list and returns a list with a tuple for each combination.\n\n Parameters:\n colors (list): A list of colors.\n n (int): The length of each combination.\n\n Returns:\n list: A list of tuples, each representing a combination of colors.\n \"\"\"\n return list(product(colors, repeat=n))"} | |
| {"task_id": "Mbpp/256", "solution": "import math\ndef count_Primes_nums(n):\n \"\"\"\n Write a python function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.\n \"\"\"\n if n < 2:\n return 0\n count = 1 # Starting with 1 because 2 is a prime number\n for num in range(3, n, 2): # Only check odd numbers\n is_prime = True\n for i in range(3, int(math.sqrt(num)) + 1, 2):\n if num % i == 0:\n is_prime = False\n break\n if is_prime:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/257", "solution": "def swap_numbers(num1, num2):\n \"\"\"\n Takes in two numbers and returns a tuple with the second number and then the first number.\n\n Parameters:\n num1 (int): The first number.\n num2 (int): The second number.\n\n Returns:\n tuple: A tuple containing the second number followed by the first number.\n \"\"\"\n return (num2, num1)"} | |
| {"task_id": "Mbpp/259", "solution": "def maximize_elements(tuples1, tuples2):\n \"\"\"\n Write a function to maximize the given two tuples.\n assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))\n \"\"\"\n result = []\n for t1, t2 in zip(tuples1, tuples2):\n result.append((max(t1[0], t2[0]), max(t1[1], t2[1])))\n return tuple(result)"} | |
| {"task_id": "Mbpp/260", "solution": "def newman_prime(n):\n \"\"\"\n Find the nth newman\u2013shanks\u2013williams prime number.\n \"\"\"\n if n == 1:\n return 2\n elif n == 2:\n return 3\n else:\n count = 2\n num = 3\n while count < n:\n num += 2\n if all(num % i != 0 for i in range(2, int(num**0.5) + 1)):\n count += 1\n return num"} | |
| {"task_id": "Mbpp/261", "solution": "def division_elements(tuple1, tuple2):\n \"\"\"\n Perform element-wise division of two tuples.\n\n Args:\n tuple1 (tuple): The first tuple.\n tuple2 (tuple): The second tuple.\n\n Returns:\n tuple: A new tuple containing the result of the division of corresponding elements in the input tuples.\n \"\"\"\n return tuple(map(lambda x, y: x / y, tuple1, tuple2))"} | |
| {"task_id": "Mbpp/262", "solution": "def split_two_parts(lst, L):\n \"\"\"\n Splits the given list into two parts where the length of the first part of the list is L, and returns the resulting lists in a tuple.\n\n Parameters:\n lst (list): The list to be split.\n L (int): The length of the first part of the list.\n\n Returns:\n tuple: A tuple containing two lists, where the first list has length L and the second list contains the remaining elements of the original list.\n \"\"\"\n return (lst[:L], lst[L:])"} | |
| {"task_id": "Mbpp/264", "solution": "def dog_age(dog_years):\n \"\"\"\n Calculate a dog's age in dog's years.\n \"\"\"\n if dog_years < 0:\n raise ValueError(\"Dog's age cannot be negative.\")\n elif dog_years == 0:\n return 0\n elif dog_years == 1:\n return 15\n elif dog_years == 2:\n return 24\n else:\n return 24 + (dog_years - 2) * 4"} | |
| {"task_id": "Mbpp/265", "solution": "def list_split(lst, n):\n return [lst[i::n] for i in range(n)]"} | |
| {"task_id": "Mbpp/266", "solution": "def lateralsurface_cube(side_length):\n \"\"\"\n Calculate the lateral surface area of a cube given its side length.\n\n Parameters:\n side_length (float): The length of a side of the cube.\n\n Returns:\n float: The lateral surface area of the cube.\n \"\"\"\n return 4 * side_length ** 2"} | |
| {"task_id": "Mbpp/267", "solution": "def square_Sum(n):\n \"\"\"\n Returns the sum of the squares of the first n odd natural numbers.\n \"\"\"\n return sum([i**2 for i in range(1, 2*n, 2)])"} | |
| {"task_id": "Mbpp/268", "solution": "def find_star_num(n):\n \"\"\"\n Calculate the n'th star number.\n \n Args:\n n (int): The position of the star number to calculate.\n \n Returns:\n int: The n'th star number.\n \"\"\"\n return n * (6 * n - 5)"} | |
| {"task_id": "Mbpp/269", "solution": "def ascii_value(char):\n \"\"\"\n Returns the ASCII value of the given character.\n\n Args:\n char (str): A single character string.\n\n Returns:\n int: The ASCII value of the character.\n\n Raises:\n ValueError: If the input is not a single character string.\n \"\"\"\n if not isinstance(char, str) or len(char) != 1:\n raise ValueError(\"Input must be a single character string.\")\n return ord(char)"} | |
| {"task_id": "Mbpp/270", "solution": "def sum_even_and_even_index(lst):\n \"\"\"\n Returns the sum of even numbers at even positions in a list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n int: The sum of even numbers at even positions.\n\n Examples:\n >>> sum_even_and_even_index([5, 6, 12, 1, 18, 8])\n 30\n \"\"\"\n return sum(num for idx, num in enumerate(lst) if idx % 2 == 0 and num % 2 == 0)"} | |
| {"task_id": "Mbpp/271", "solution": "def even_Power_Sum(n):\n \"\"\"\n Write a python function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.\n\n :param n: int\n :return: int\n \"\"\"\n return sum([i**5 for i in range(2, 2*n+1, 2)])"} | |
| {"task_id": "Mbpp/272", "solution": "def rear_extract(tuples_list):\n \"\"\"\n Extracts the rear element from each tuple in the given list of tuples.\n\n Parameters:\n tuples_list (list): A list of tuples.\n\n Returns:\n list: A list containing the rear element of each tuple.\n \"\"\"\n return [item[-1] for item in tuples_list]"} | |
| {"task_id": "Mbpp/273", "solution": "def substract_elements(tuple1, tuple2):\n \"\"\"\n Subtracts the elements of the second tuple from the first tuple with the same index.\n\n Parameters:\n tuple1 (tuple): The first tuple.\n tuple2 (tuple): The second tuple.\n\n Returns:\n tuple: A new tuple with the result of the subtraction.\n \"\"\"\n return tuple(x - y for x, y in zip(tuple1, tuple2))"} | |
| {"task_id": "Mbpp/274", "solution": "from math import comb\ndef even_binomial_Coeff_Sum(n):\n \"\"\"\n Calculate the sum of even index binomial coefficients for a given positive integer n.\n \n Args:\n n (int): A positive integer\n \n Returns:\n int: The sum of even index binomial coefficients\n \n Examples:\n >>> even_binomial_Coeff_Sum(4)\n 8\n \"\"\"\n return 2 ** (n - 1)"} | |
| {"task_id": "Mbpp/276", "solution": "import math\ndef volume_cylinder(radius, height):\n \"\"\"\n Calculate the volume of a cylinder given its radius and height.\n\n Parameters:\n radius (float): The radius of the cylinder.\n height (float): The height of the cylinder.\n\n Returns:\n float: The volume of the cylinder.\n \"\"\"\n return math.pi * radius ** 2 * height"} | |
| {"task_id": "Mbpp/277", "solution": "def dict_filter(dictionary, threshold):\n \"\"\"\n Filters a dictionary to only include entries with values greater than or equal to a given threshold.\n\n Parameters:\n dictionary (dict): The input dictionary.\n threshold (int): The minimum value for the dictionary entries.\n\n Returns:\n dict: The filtered dictionary.\n \"\"\"\n return {key: value for key, value in dictionary.items() if value >= threshold}"} | |
| {"task_id": "Mbpp/278", "solution": "def count_first_elements(tpl):\n count = 0\n for element in tpl:\n if isinstance(element, tuple):\n break\n count += 1\n return count"} | |
| {"task_id": "Mbpp/279", "solution": "def is_num_decagonal(n):\n \"\"\"\n Calculate the nth decagonal number.\n Args:\n n (int): The position of the decagonal number in the sequence.\n\n Returns:\n int: The nth decagonal number.\n \"\"\"\n if n < 1:\n raise ValueError(\"n must be a positive integer\")\n return n * (7 * n - 5)"} | |
| {"task_id": "Mbpp/280", "solution": "def sequential_search(arr, target):\n \"\"\"\n Perform a sequential search on an array to find a target element.\n\n Parameters:\n arr (list): The list to search through.\n target: The element to search for.\n\n Returns:\n tuple: A tuple containing a boolean indicating if the element is in the array and the index position of the element (or -1 if not found).\n \"\"\"\n for index, element in enumerate(arr):\n if element == target:\n return True, index\n return False, -1"} | |
| {"task_id": "Mbpp/281", "solution": "def all_unique(lst):\n \"\"\"\n Check if the elements of a given list are unique or not.\n\n Args:\n lst (list): The list to check for uniqueness.\n\n Returns:\n bool: True if all elements are unique, False otherwise.\n \"\"\"\n return len(lst) == len(set(lst))"} | |
| {"task_id": "Mbpp/282", "solution": "def sub_list(list1, list2):\n \"\"\"\n Subtract two lists element-wise.\n\n Parameters:\n list1 (list): The first list.\n list2 (list): The second list.\n\n Returns:\n list: A new list containing the element-wise subtraction of list1 and list2.\n \"\"\"\n return [a - b for a, b in zip(list1, list2)]"} | |
| {"task_id": "Mbpp/283", "solution": "def validate(n):\n \"\"\"\n Check if the frequency of each digit in the integer is less than or equal to the digit itself.\n\n Args:\n n (int): The integer to be checked.\n\n Returns:\n bool: True if the frequency of each digit is less than or equal to the digit itself, False otherwise.\n \"\"\"\n for digit in str(n):\n if int(digit) > n // int(digit):\n return False\n return True"} | |
| {"task_id": "Mbpp/284", "solution": "def check_element(lst, element):\n \"\"\"\n Checks if all items in the list are equal to the given element.\n\n Parameters:\n lst (list): The list to check.\n element: The element to compare against.\n\n Returns:\n bool: True if all items are equal to the given element, False otherwise.\n \"\"\"\n return all(item == element for item in lst)"} | |
| {"task_id": "Mbpp/285", "solution": "import re\ndef text_match_two_three(text):\n \"\"\"\n Checks whether a string contains the 'a' character followed by two or three 'b' characters.\n \n Args:\n text (str): The input string to be checked.\n \n Returns:\n bool: True if the string matches the pattern, False otherwise.\n \"\"\"\n pattern = 'ab{2,3}'\n return bool(re.search(pattern, text))"} | |
| {"task_id": "Mbpp/286", "solution": "def max_sub_array_sum_repeated(arr, n, k):\n \"\"\"\n Find the largest sum of a contiguous array in the modified array which is formed by repeating the given array k times.\n \n Parameters:\n arr (list): The input array.\n n (int): The size of the input array.\n k (int): The number of times the array is repeated.\n \n Returns:\n int: The largest sum of a contiguous array in the modified array.\n \"\"\"\n # Calculate the maximum subarray sum for a single instance of the array\n max_sum = max_ending_here = arr[0]\n for i in range(1, n):\n max_ending_here = max(arr[i], max_ending_here + arr[i])\n max_sum = max(max_sum, max_ending_here)\n \n # If the maximum subarray sum is negative, return 0\n if max_sum < 0:\n return 0\n \n # Calculate the total sum of the array for k instances\n total_sum = sum(arr)\n \n # If k is 1, return the maximum subarray sum for a single instance\n if k == 1:\n return max_sum\n \n # If the total sum is positive, return the sum of the array for k instances minus the minimum subarray sum\n min_sum = min_ending_here = arr[0]\n for i in range(1, n):\n min_ending_here = min(arr[i], min_ending_here + arr[i])\n min_sum = min(min_sum, min_ending_here)\n \n if total_sum > 0:\n return max_sum + (k - 2) * total_sum + min_sum\n else:\n return max_sum"} | |
| {"task_id": "Mbpp/287", "solution": "def square_Sum(n):\n \"\"\"\n Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers.\n assert square_Sum(2) == 20\n \"\"\"\n return sum([i**2 for i in range(2, 2*n+1, 2)])"} | |
| {"task_id": "Mbpp/290", "solution": "def max_length(list_of_lists):\n \"\"\"\n Find the list of maximum length in a list of lists.\n\n Args:\n list_of_lists (list): A list containing sublists.\n\n Returns:\n tuple: A tuple containing the length of the longest sublist and the longest sublist itself.\n \"\"\"\n if not list_of_lists:\n return 0, []\n \n max_length = max(len(sublist) for sublist in list_of_lists)\n longest_sublist = max(list_of_lists, key=len)\n \n return max_length, longest_sublist"} | |
| {"task_id": "Mbpp/292", "solution": "def find_quotient(dividend, divisor):\n \"\"\"\n Calculate the quotient of two numbers (rounded down to the nearest integer).\n\n Parameters:\n dividend (int): The number to be divided.\n divisor (int): The number by which to divide.\n\n Returns:\n int: The quotient of the division, rounded down to the nearest integer.\n \"\"\"\n return dividend // divisor\n\n# Test cases\nassert find_quotient(10, 3) == 3\nassert find_quotient(15, 5) == 3\nassert find_quotient(100, 7) == 14\nassert find_quotient(0, 1) == 0\nassert find_quotient(1, 0) == 0 # This will raise a ZeroDivisionError, but it's not a valid test case"} | |
| {"task_id": "Mbpp/293", "solution": "import math\ndef otherside_rightangle(side1, side2):\n \"\"\"\n Calculate the third side of a right-angled triangle given two sides.\n \n Args:\n side1 (float): The length of the first side of the triangle.\n side2 (float): The length of the second side of the triangle.\n \n Returns:\n float: The length of the third side of the triangle.\n \"\"\"\n return math.sqrt(side1**2 + side2**2)"} | |
| {"task_id": "Mbpp/294", "solution": "def max_val(heterogeneous_list):\n \"\"\"\n Find the maximum value in a given heterogeneous list.\n\n Parameters:\n heterogeneous_list (list): A list containing elements of different types.\n\n Returns:\n int: The maximum value found in the list.\n\n Example:\n >>> max_val(['Python', 3, 2, 4, 5, 'version'])\n 5\n \"\"\"\n max_value = float('-inf')\n for item in heterogeneous_list:\n if isinstance(item, int) or isinstance(item, float):\n max_value = max(max_value, item)\n return max_value"} | |
| {"task_id": "Mbpp/296", "solution": "def get_Inv_Count(arr):\n \"\"\"\n Count the number of inversions in an array.\n \n Args:\n arr (list): A list of integers.\n \n Returns:\n int: The number of inversions in the array.\n \"\"\"\n inv_count = 0\n for i in range(len(arr)):\n for j in range(i + 1, len(arr)):\n if arr[i] > arr[j]:\n inv_count += 1\n return inv_count"} | |
| {"task_id": "Mbpp/297", "solution": "def flatten_list(nested_list):\n \"\"\"\n Flattens a given nested list structure.\n\n Args:\n nested_list: A list that may contain integers or other lists.\n\n Returns:\n A flattened list containing all the integers from the nested list.\n\n Example:\n >>> flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])\n [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]\n \"\"\"\n flattened_list = []\n for item in nested_list:\n if isinstance(item, list):\n flattened_list.extend(flatten_list(item))\n else:\n flattened_list.append(item)\n return flattened_list"} | |
| {"task_id": "Mbpp/299", "solution": "def max_aggregate(data):\n \"\"\"\n Calculate the maximum aggregate from the list of tuples.\n\n Args:\n data (list of tuples): A list of tuples containing names and their corresponding scores.\n\n Returns:\n tuple: The name and the maximum aggregate score.\n\n Example:\n >>> max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])\n ('Juan Whelan', 212)\n \"\"\"\n max_score = 0\n max_name = \"\"\n for name, score in data:\n if score > max_score:\n max_score = score\n max_name = name\n return (max_name, max_score)"} | |
| {"task_id": "Mbpp/300", "solution": "import math"} | |
| {"task_id": "Mbpp/301", "solution": "def dict_depth(d):\n \"\"\"\n Recursively calculates the depth of a dictionary.\n\n Parameters:\n d (dict): The dictionary for which to calculate the depth.\n\n Returns:\n int: The depth of the dictionary.\n \"\"\"\n if not isinstance(d, dict) or not d:\n return 0\n return 1 + max(dict_depth(v) for v in d.values())"} | |
| {"task_id": "Mbpp/305", "solution": "def start_withp(words):\n \"\"\"\n Returns the first two words from a list of words that start with the letter 'p'.\n \"\"\"\n p_words = [word for phrase in words for word in phrase.split() if word.startswith('p')]\n return tuple(p_words[:2])"} | |
| {"task_id": "Mbpp/306", "solution": "def max_sum_increasing_subseq(arr, n, k):\n \"\"\"\n Find the maximum sum of increasing subsequence from prefix until ith index and also including a given kth element which is after i, i.e., k > i.\n :param arr: List of integers\n :param n: Length of the array\n :param k: Index of the element to be included in the subsequence\n :return: Maximum sum of increasing subsequence\n \"\"\"\n # Initialize the dp array\n dp = [0] * n\n\n # Base case\n dp[0] = arr[0]\n\n # Fill the dp array\n for i in range(1, n):\n dp[i] = arr[i]\n for j in range(i):\n if arr[i] > arr[j]:\n dp[i] = max(dp[i], dp[j] + arr[i])\n\n # Initialize the result\n result = dp[k]\n\n # Include the kth element in the subsequence\n for i in range(k + 1, n):\n if arr[i] > arr[k]:\n result = max(result, dp[i])\n\n return result"} | |
| {"task_id": "Mbpp/308", "solution": "def large_product(list1, list2, n):\n \"\"\"\n Finds the specified number of largest products from two given lists, selecting one factor from each list.\n\n Args:\n list1 (list): The first list of integers.\n list2 (list): The second list of integers.\n n (int): The number of largest products to find.\n\n Returns:\n list: A list containing the n largest products.\n \"\"\"\n # Calculate all possible products\n products = [x * y for x in list1 for y in list2]\n \n # Sort the products in descending order\n sorted_products = sorted(products, reverse=True)\n \n # Return the first n products from the sorted list\n return sorted_products[:n]"} | |
| {"task_id": "Mbpp/309", "solution": "def maximum(num1, num2):\n \"\"\"\n Returns the maximum of two numbers.\n\n Parameters:\n num1 (int or float): The first number.\n num2 (int or float): The second number.\n\n Returns:\n int or float: The maximum of the two numbers.\n \"\"\"\n return max(num1, num2)"} | |
| {"task_id": "Mbpp/310", "solution": "def string_to_tuple(input_string):\n \"\"\"\n Converts a given string to a tuple of characters.\n\n Args:\n input_string (str): The string to be converted.\n\n Returns:\n tuple: A tuple containing individual characters from the input string.\n \"\"\"\n return tuple(input_string)"} | |
| {"task_id": "Mbpp/311", "solution": "def set_left_most_unset_bit(n):\n \"\"\"\n Sets the leftmost unset bit in the binary representation of a non-negative integer.\n Args:\n n (int): A non-negative integer whose leftmost unset bit is to be set.\n\n Returns:\n int: The resulting integer after setting the leftmost unset bit.\n\n Examples:\n >>> set_left_most_unset_bit(10)\n 14\n \"\"\"\n if n == 0:\n return 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n |= n >> 32 # For 64-bit integers\n return n + 1"} | |
| {"task_id": "Mbpp/312", "solution": "import math\ndef volume_cone(radius, height):\n \"\"\"\n Calculate the volume of a cone given its radius and height.\n\n Args:\n radius (float): The radius of the cone's base.\n height (float): The height of the cone.\n\n Returns:\n float: The volume of the cone.\n \"\"\"\n return (1/3) * math.pi * radius**2 * height"} | |
| {"task_id": "Mbpp/388", "solution": "def highest_Power_of_2(n):\n \"\"\"\n Find the highest power of 2 that is less than or equal to n.\n\n Args:\n n (int): The input number.\n\n Returns:\n int: The highest power of 2 less than or equal to n.\n \"\"\"\n power = 1\n while power <= n:\n power *= 2\n return power // 2"} | |
| {"task_id": "Mbpp/389", "solution": "def find_lucas(n):\n \"\"\"\n Find the n'th lucas number.\n \"\"\"\n if n == 0:\n return 2\n elif n == 1:\n return 1\n else:\n a, b = 2, 1\n for _ in range(n - 1):\n a, b = b, a + b\n return b"} | |
| {"task_id": "Mbpp/390", "solution": "def apply_format_to_list(input_list, format_string):\n \"\"\"\n Applies a given format string to all elements in the input list.\n\n Parameters:\n input_list (list): The list of elements to be formatted.\n format_string (str): The format string to be applied to each element.\n\n Returns:\n list: A new list with the formatted elements.\n \"\"\"\n return [format_string.format(item) for item in input_list]\n\n# Test cases to validate the function\nassert apply_format_to_list([1, 2, 3, 4], 'temp{0}') == ['temp1', 'temp2', 'temp3', 'temp4']\nassert apply_format_to_list(['a', 'b', 'c'], 'item{0}') == ['itema', 'itemb', 'itemc']\nassert apply_format_to_list([10, 20, 30], 'val{0}') == ['val10', 'val20', 'val30']"} | |
| {"task_id": "Mbpp/391", "solution": "def convert_list_dictionary(student_ids, names, scores):\n \"\"\"\n Converts three lists into a nested dictionary.\n \n Args:\n student_ids (list): A list of student IDs.\n names (list): A list of student names.\n scores (list): A list of student scores.\n \n Returns:\n list: A list of dictionaries representing the nested structure.\n \"\"\"\n if len(student_ids) != len(names) or len(student_ids) != len(scores):\n raise ValueError(\"All input lists must have the same length.\")\n \n nested_dict = []\n for student_id, name, score in zip(student_ids, names, scores):\n nested_dict.append({student_id: {name: score}})\n \n return nested_dict"} | |
| {"task_id": "Mbpp/392", "solution": "def get_max_sum(n):\n if n == 0:\n return 0\n max_sum = n\n for divisor in [2, 3, 4, 5]:\n if n % divisor == 0:\n max_sum = max(max_sum, get_max_sum(n // divisor) + n)\n return max_sum"} | |
| {"task_id": "Mbpp/394", "solution": "def check_distinct(tup):\n \"\"\"\n Check if given tuple contains no duplicates.\n\n Parameters:\n tup (tuple): The input tuple to be checked.\n\n Returns:\n bool: True if the tuple contains no duplicates, False otherwise.\n \"\"\"\n return len(tup) == len(set(tup))"} | |
| {"task_id": "Mbpp/395", "solution": "def first_non_repeating_character(s):\n \"\"\"\n Finds the first non-repeated character in a given string.\n \n Args:\n s (str): The input string to search for the first non-repeated character.\n \n Returns:\n str or None: The first non-repeated character if found, otherwise None.\n \"\"\"\n char_count = {}\n \n # Count occurrences of each character\n for char in s:\n if char in char_count:\n char_count[char] += 1\n else:\n char_count[char] = 1\n \n # Find the first non-repeated character\n for char in s:\n if char_count[char] == 1:\n return char\n \n return None"} | |
| {"task_id": "Mbpp/397", "solution": "def median_numbers(a, b, c):\n \"\"\"\n Find the median of three numbers.\n\n Parameters:\n a (int or float): The first number.\n b (int or float): The second number.\n c (int or float): The third number.\n\n Returns:\n float: The median of the three numbers.\n \"\"\"\n return sorted([a, b, c])[1]"} | |
| {"task_id": "Mbpp/398", "solution": "def sum_of_digits(numbers):\n \"\"\"\n Compute the sum of digits of each number in a given list.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n int: The sum of digits of each number in the list.\n \"\"\"\n total_sum = 0\n for number in numbers:\n while number > 0:\n total_sum += number % 10\n number //= 10\n return total_sum"} | |
| {"task_id": "Mbpp/404", "solution": "def minimum(num1, num2):\n \"\"\"\n Returns the minimum of two numbers.\n\n Parameters:\n num1 (int or float): The first number.\n num2 (int or float): The second number.\n\n Returns:\n int or float: The minimum of the two numbers.\n \"\"\"\n return min(num1, num2)"} | |
| {"task_id": "Mbpp/405", "solution": "def check_tuplex(tuplex, element):\n \"\"\"\n Check if an element exists within a tuple.\n\n Parameters:\n tuplex (tuple): The tuple to search in.\n element: The element to search for.\n\n Returns:\n bool: True if the element is found, False otherwise.\n \"\"\"\n return element in tuplex"} | |
| {"task_id": "Mbpp/406", "solution": "def find_Parity(n):\n \"\"\"\n Returns True if the parity of the given number is even, False otherwise.\n \"\"\"\n return n % 2 == 0"} | |
| {"task_id": "Mbpp/409", "solution": "def min_product_tuple(pairs):\n \"\"\"\n Find the minimum product from the pairs of tuples within a given list.\n\n Args:\n pairs (list): A list of tuples containing two integers each.\n\n Returns:\n int: The minimum product of the pairs.\n\n Examples:\n >>> min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)])\n 8\n \"\"\"\n return min(a * b for a, b in pairs)"} | |
| {"task_id": "Mbpp/410", "solution": "def min_val(heterogeneous_list):\n \"\"\"\n Find the minimum value in a given heterogeneous list.\n\n Parameters:\n heterogeneous_list (list): A list containing elements of different types.\n\n Returns:\n int or str: The minimum value found in the list.\n\n Example:\n >>> min_val(['Python', 3, 2, 4, 5, 'version'])\n 2\n \"\"\"\n min_value = None\n for item in heterogeneous_list:\n if min_value is None or (isinstance(item, (int, float)) and item < min_value):\n min_value = item\n return min_value"} | |
| {"task_id": "Mbpp/412", "solution": "def remove_odd(numbers):\n \"\"\"\n Removes odd numbers from a given list.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n list: A list containing only even numbers.\n \"\"\"\n return [num for num in numbers if num % 2 == 0]"} | |
| {"task_id": "Mbpp/413", "solution": "def extract_nth_element(lst, n):\n \"\"\"\n Extracts the nth element from each tuple in a list of tuples.\n\n Args:\n lst (list): A list of tuples.\n n (int): The index of the element to extract from each tuple.\n\n Returns:\n list: A list containing the nth element from each tuple in the input list.\n \"\"\"\n return [tup[n] for tup in lst]"} | |
| {"task_id": "Mbpp/414", "solution": "def overlapping(sequence1, sequence2):\n \"\"\"\n Check if any value in sequence1 exists in sequence2.\n\n Args:\n sequence1 (list): The first sequence.\n sequence2 (list): The second sequence.\n\n Returns:\n bool: True if there is an overlap, False otherwise.\n \"\"\"\n return any(value in sequence2 for value in sequence1)"} | |
| {"task_id": "Mbpp/415", "solution": "def max_Product(arr):\n \"\"\"\n Finds a pair with the highest product from a given array of integers.\n\n Parameters:\n arr (list): A list of integers.\n\n Returns:\n tuple: A tuple containing the pair of integers with the highest product.\n \"\"\"\n if len(arr) < 2:\n return None\n\n max_product = float('-inf')\n max_pair = (0, 0)\n\n for i in range(len(arr)):\n for j in range(i + 1, len(arr)):\n product = arr[i] * arr[j]\n if product > max_product:\n max_product = product\n max_pair = (arr[i], arr[j])\n\n return max_pair"} | |
| {"task_id": "Mbpp/418", "solution": "def Find_Max(lst):\n \"\"\"\n Finds the element of a list having maximum length.\n\n Parameters:\n lst (list): A list of lists.\n\n Returns:\n list: The element of the list having maximum length.\n \"\"\"\n return max(lst, key=len)"} | |
| {"task_id": "Mbpp/419", "solution": "def round_and_sum(numbers):\n \"\"\"\n Rounds every number in the given list and returns the total sum multiplied by the length of the list.\n\n Args:\n numbers (list): A list of floating-point numbers.\n\n Returns:\n int: The total sum of rounded numbers multiplied by the length of the list.\n \"\"\"\n rounded_numbers = [round(num) for num in numbers]\n total_sum = sum(rounded_numbers)\n result = total_sum * len(numbers)\n return result"} | |
| {"task_id": "Mbpp/420", "solution": "def cube_Sum(n):\n \"\"\"\n Calculate the cube sum of the first n even natural numbers.\n\n Args:\n n (int): The number of even natural numbers to consider.\n\n Returns:\n int: The sum of the cubes of the first n even natural numbers.\n \"\"\"\n return sum(i**3 for i in range(2, 2*n+1, 2))"} | |
| {"task_id": "Mbpp/421", "solution": "def concatenate_tuple(tup, delimiter='-'):\n return delimiter.join(map(str, tup))"} | |
| {"task_id": "Mbpp/422", "solution": "def find_Average_Of_Cube(n):\n \"\"\"\n Calculate the average of cubes of first n natural numbers.\n\n Args:\n n (int): The number of natural numbers to consider.\n\n Returns:\n float: The average of cubes of first n natural numbers.\n \"\"\"\n total_sum = sum(i**3 for i in range(1, n+1))\n average = total_sum / n\n return average"} | |
| {"task_id": "Mbpp/424", "solution": "def extract_rear(input_tuple):\n \"\"\"\n Extracts the rear index element of each string in the given tuple.\n\n Args:\n input_tuple (tuple): A tuple containing strings.\n\n Returns:\n list: A list of the rear index elements from each string in the input tuple.\n \"\"\"\n return [word[-1] for word in input_tuple]"} | |
| {"task_id": "Mbpp/425", "solution": "def count_element_in_list(lst, element):\n \"\"\"\n Count the number of sublists containing a particular element.\n\n Args:\n lst (list): A list of sublists.\n element: The element to search for in the sublists.\n\n Returns:\n int: The count of sublists containing the element.\n \"\"\"\n count = 0\n for sublist in lst:\n if element in sublist:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/426", "solution": "def filter_oddnumbers(numbers):\n \"\"\"\n Filter out odd numbers from a list of integers.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n list: A list containing only the odd numbers from the input list.\n \"\"\"\n return [num for num in numbers if num % 2 != 0]"} | |
| {"task_id": "Mbpp/427", "solution": "from datetime import datetime\ndef change_date_format(date_str):\n \"\"\"\n Convert a date from yyyy-mm-dd format to dd-mm-yyyy format.\n\n Parameters:\n date_str (str): A string representing a date in yyyy-mm-dd format.\n\n Returns:\n str: A string representing the same date in dd-mm-yyyy format.\n \"\"\"\n date_obj = datetime.strptime(date_str, '%Y-%m-%d')\n return date_obj.strftime('%d-%m-%Y')"} | |
| {"task_id": "Mbpp/428", "solution": "def shell_sort(arr):\n \"\"\"\n Sorts the given array using the Shell sort algorithm.\n\n Args:\n arr (list): The list of elements to be sorted.\n\n Returns:\n list: The sorted list.\n \"\"\"\n n = len(arr)\n gap = n // 2\n\n while gap > 0:\n for i in range(gap, n):\n temp = arr[i]\n j = i\n while j >= gap and arr[j - gap] > temp:\n arr[j] = arr[j - gap]\n j -= gap\n arr[j] = temp\n gap //= 2\n\n return arr"} | |
| {"task_id": "Mbpp/429", "solution": "def and_tuples(tuple1, tuple2):\n \"\"\"\n Write a function to extract the elementwise and tuples from the given two tuples.\n assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)\n \"\"\"\n return tuple(a & b for a, b in zip(tuple1, tuple2))"} | |
| {"task_id": "Mbpp/430", "solution": "def parabola_directrix(a, b, c):\n \"\"\"\n Calculate the directrix of a parabola given by the equation y = ax^2 + bx + c.\n \n Parameters:\n a (float): Coefficient of x^2\n b (float): Coefficient of x\n c (float): Constant term\n \n Returns:\n float: The y-coordinate of the directrix of the parabola.\n \"\"\"\n return c - (b**2 + 1) / (4 * a)"} | |
| {"task_id": "Mbpp/432", "solution": "def median_trapezium(base1, base2, height):\n \"\"\"\n Calculate the median length of a trapezium.\n\n Parameters:\n base1 (float): The length of the first base of the trapezium.\n base2 (float): The length of the second base of the trapezium.\n height (float): The height of the trapezium.\n\n Returns:\n float: The median length of the trapezium.\n \"\"\"\n return (base1 + base2) / 2"} | |
| {"task_id": "Mbpp/433", "solution": "def check_greater(arr, num):\n \"\"\"\n Check if the given number is greater than all elements in the array.\n\n Parameters:\n arr (list): A list of integers.\n num (int): The number to be compared.\n\n Returns:\n bool: True if the number is greater than all elements in the array, False otherwise.\n \"\"\"\n return all(num > x for x in arr)"} | |
| {"task_id": "Mbpp/435", "solution": "def last_Digit(number):\n \"\"\"\n Write a python function to find the last digit of a given number.\n assert last_Digit(123) == 3\n \"\"\"\n return number % 10"} | |
| {"task_id": "Mbpp/436", "solution": "def neg_nos(numbers):\n \"\"\"\n Returns a list of negative numbers from the input list.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n list: A list containing only the negative numbers from the input list.\n \"\"\"\n return [num for num in numbers if num < 0]"} | |
| {"task_id": "Mbpp/437", "solution": "def remove_odd(s):\n \"\"\"\n Removes odd characters from a string.\n\n Args:\n s (str): The input string.\n\n Returns:\n str: The string with odd characters removed.\n \"\"\"\n return ''.join([s[i] for i in range(len(s)) if i % 2 == 0])"} | |
| {"task_id": "Mbpp/439", "solution": "def multiple_to_single(int_list):\n \"\"\"\n Join a list of multiple integers into a single integer.\n\n Parameters:\n int_list (list): A list of integers.\n\n Returns:\n int: A single integer formed by joining the integers in the list.\n \"\"\"\n return int(''.join(map(str, int_list)))"} | |
| {"task_id": "Mbpp/440", "solution": "import re\ndef find_adverb_position(sentence):\n \"\"\"\n Finds the first adverb and its positions in a given sentence.\n \n Args:\n sentence (str): The sentence to search for adverbs.\n \n Returns:\n tuple: A tuple containing the start index, end index, and the adverb found.\n \"\"\"\n adverbs = ['ly']\n pattern = '|'.join(map(re.escape, adverbs))\n match = re.search(pattern, sentence)\n if match:\n return match.start(), match.end(), match.group()\n else:\n return None"} | |
| {"task_id": "Mbpp/441", "solution": "def surfacearea_cube(size):\n \"\"\"\n Calculate the surface area of a cube of a given size.\n\n Parameters:\n size (int): The size of the cube.\n\n Returns:\n int: The surface area of the cube.\n \"\"\"\n return 6 * size ** 2"} | |
| {"task_id": "Mbpp/445", "solution": "def index_multiplication(tup1, tup2):\n \"\"\"\n Perform index wise multiplication of tuple elements in the given two tuples.\n\n Args:\n tup1 (tuple): The first tuple.\n tup2 (tuple): The second tuple.\n\n Returns:\n tuple: A new tuple with the index wise multiplication of elements from the input tuples.\n \"\"\"\n return tuple(x * y for x, y in zip(tup1, tup2))"} | |
| {"task_id": "Mbpp/446", "solution": "def count_Occurrence(tup, lst):\n \"\"\"\n Count the occurrence of all elements of a list in a tuple.\n\n Parameters:\n tup (tuple): The tuple in which to count occurrences.\n lst (list): The list of elements to count in the tuple.\n\n Returns:\n int: The total number of occurrences of all elements in the list within the tuple.\n \"\"\"\n return sum(tup.count(elem) for elem in lst)"} | |
| {"task_id": "Mbpp/447", "solution": "def cube_nums(lst):\n \"\"\"\n This function takes a list of numbers and returns a new list with the cubes of the original numbers.\n \n :param lst: List of numbers\n :return: List of cubes of the input numbers\n \"\"\"\n return [num ** 3 for num in lst]"} | |
| {"task_id": "Mbpp/448", "solution": "def cal_sum(n):\n \"\"\"\n Calculate the sum of perrin numbers up to the nth term.\n Args:\n n (int): The number of terms to include in the sum.\n\n Returns:\n int: The sum of the first n perrin numbers.\n\n Examples:\n >>> cal_sum(9)\n 49\n \"\"\"\n if n == 0:\n return 3\n elif n == 1:\n return 0\n elif n == 2:\n return 2\n\n perrin = [3, 0, 2]\n for i in range(3, n + 1):\n perrin.append(perrin[i - 2] + perrin[i - 3])\n return sum(perrin)"} | |
| {"task_id": "Mbpp/450", "solution": "def extract_string(lst, n):\n \"\"\"\n Extracts and returns a list of strings from the input list that have a length equal to the specified size.\n\n Parameters:\n lst (list): A list of strings.\n n (int): The specified size.\n\n Returns:\n list: A list of strings with length equal to the specified size.\n \"\"\"\n return [s for s in lst if len(s) == n]"} | |
| {"task_id": "Mbpp/451", "solution": "def remove_whitespaces(input_string):\n \"\"\"\n Removes all whitespaces from the given string.\n\n Parameters:\n input_string (str): The string from which to remove whitespaces.\n\n Returns:\n str: The string with all whitespaces removed.\n \"\"\"\n return input_string.replace(\" \", \"\")"} | |
| {"task_id": "Mbpp/453", "solution": "def sumofFactors(n):\n \"\"\"\n Write a python function to find the sum of even factors of a number.\n assert sumofFactors(18) == 26\n \"\"\"\n sum = 0\n for i in range(2, n + 1, 2):\n if n % i == 0:\n sum += i\n return sum"} | |
| {"task_id": "Mbpp/454", "solution": "import re\ndef text_match_wordz(text):\n \"\"\"\n Matches a word containing 'z'.\n \"\"\"\n pattern = r'\\b\\w*z\\w*\\b'\n return bool(re.search(pattern, text))"} | |
| {"task_id": "Mbpp/455", "solution": "def check_month_number(month_number):\n \"\"\"\n Check if the given month number contains 31 days.\n \n Args:\n month_number (int): The number of the month to check.\n \n Returns:\n bool: True if the month has 31 days, False otherwise.\n \"\"\"\n # List of months with 31 days\n months_with_31_days = [1, 3, 5, 7, 8, 10, 12]\n \n # Check if the given month number is in the list\n return month_number in months_with_31_days\n\n# Test cases\nassert check_month_number(5) == True\nassert check_month_number(2) == False\nassert check_month_number(11) == True\nassert check_month_number(4) == False"} | |
| {"task_id": "Mbpp/456", "solution": "def reverse_string_list(string_list):\n \"\"\"\n Reverses each string in the given list of string values.\n\n Parameters:\n string_list (list): A list of string values.\n\n Returns:\n list: A list of reversed string values.\n \"\"\"\n return [s[::-1] for s in string_list]"} | |
| {"task_id": "Mbpp/457", "solution": "def Find_Min(lst):\n \"\"\"\n Finds the sublist with the minimum length in a given list of lists.\n\n Parameters:\n lst (list): A list of lists.\n\n Returns:\n list: The sublist with the minimum length.\n \"\"\"\n return min(lst, key=len)"} | |
| {"task_id": "Mbpp/458", "solution": "def rectangle_area(length, width):\n \"\"\"\n Calculate the area of a rectangle.\n\n Parameters:\n length (float): The length of the rectangle.\n width (float): The width of the rectangle.\n\n Returns:\n float: The area of the rectangle.\n \"\"\"\n return length * width"} | |
| {"task_id": "Mbpp/459", "solution": "def remove_uppercase(s):\n \"\"\"\n Removes uppercase substrings from a given string.\n\n Args:\n s (str): The input string.\n\n Returns:\n str: The modified string with uppercase substrings removed.\n \"\"\"\n return ''.join([c for c in s if not c.isupper()])"} | |
| {"task_id": "Mbpp/460", "solution": "def Extract(lst):\n return [item[0] for item in lst]"} | |
| {"task_id": "Mbpp/462", "solution": "from itertools import chain, combinations\ndef combinations_list(lst):\n \"\"\"\n Generate all possible combinations of the elements in the input list.\n\n Parameters:\n lst (list): The input list of elements.\n\n Returns:\n list: A list of lists containing all possible combinations of the elements.\n \"\"\"\n return list(chain.from_iterable(combinations(lst, r) for r in range(len(lst) + 1)))"} | |
| {"task_id": "Mbpp/463", "solution": "def max_subarray_product(nums):\n \"\"\"\n Finds the maximum product of a contiguous subarray within the given array.\n\n Args:\n nums (list): A list of integers.\n\n Returns:\n int: The maximum product of a contiguous subarray.\n \"\"\"\n if not nums:\n return 0\n\n max_product = min_product = result = nums[0]\n\n for num in nums[1:]:\n if num < 0:\n max_product, min_product = min_product, max_product\n\n max_product = max(num, max_product * num)\n min_product = min(num, min_product * num)\n\n result = max(result, max_product)\n\n return result"} | |
| {"task_id": "Mbpp/465", "solution": "def drop_empty(dictionary):\n \"\"\"\n Write a function to drop empty items from a given dictionary.\n assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}\n \"\"\"\n return {key: value for key, value in dictionary.items() if value is not None}"} | |
| {"task_id": "Mbpp/468", "solution": "def max_product(nums):\n \"\"\"\n Finds the maximum product formed by multiplying numbers of an increasing subsequence of the given array.\n\n Args:\n nums (list): A list of integers.\n\n Returns:\n int: The maximum product of an increasing subsequence.\n\n Examples:\n >>> max_product([3, 100, 4, 5, 150, 6])\n 3000\n \"\"\"\n if not nums:\n return 1\n\n max_product = [nums[0]]\n min_product = [nums[0]]\n\n for i in range(1, len(nums)):\n max_product.append(max(nums[i], max_product[i - 1] * nums[i], min_product[i - 1] * nums[i]))\n min_product.append(min(nums[i], max_product[i - 1] * nums[i], min_product[i - 1] * nums[i]))\n\n return max(max_product)"} | |
| {"task_id": "Mbpp/470", "solution": "def add_pairwise(numbers):\n \"\"\"\n Find the pairwise addition of the neighboring elements of the given tuple.\n\n Args:\n numbers (tuple): A tuple of numbers.\n\n Returns:\n tuple: A tuple containing the pairwise addition of neighboring elements.\n \"\"\"\n return tuple(a + b for a, b in zip(numbers, numbers[1:]))"} | |
| {"task_id": "Mbpp/471", "solution": "def find_remainder(arr, n):\n \"\"\"\n This function takes an array of integers and an integer n, and returns the product of the array elements modulo n.\n \"\"\"\n product = 1\n for num in arr:\n product = (product * num) % n\n return product"} | |
| {"task_id": "Mbpp/472", "solution": "def check_Consecutive(lst):\n return all(x == y - 1 for x, y in zip(lst, lst[1:]))"} | |
| {"task_id": "Mbpp/473", "solution": "def tuple_intersection(t1, t2):\n \"\"\"\n Find the tuple intersection of elements in the given tuple list irrespective of their order.\n\n Args:\n t1 (list): The first list of tuples.\n t2 (list): The second list of tuples.\n\n Returns:\n set: A set containing the intersecting tuples.\n\n Example:\n >>> tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)], [(5, 4), (3, 4), (6, 5), (9, 11)])\n {(4, 5), (3, 4), (5, 6)}\n \"\"\"\n # Convert each tuple in t1 and t2 to a set of frozensets for unordered comparison\n set_t1 = {frozenset(t) for t in t1}\n set_t2 = {frozenset(t) for t in t2}\n\n # Find the intersection of the two sets\n intersection = set_t1 & set_t2\n\n # Convert the frozensets back to tuples and return as a set\n return {tuple(t) for t in intersection}"} | |
| {"task_id": "Mbpp/474", "solution": "def replace_char(input_string, old_char, new_char):\n \"\"\"\n Replaces all occurrences of old_char with new_char in the input_string.\n\n Parameters:\n input_string (str): The string in which characters are to be replaced.\n old_char (str): The character to be replaced.\n new_char (str): The character to replace with.\n\n Returns:\n str: A new string with all occurrences of old_char replaced by new_char.\n \"\"\"\n return input_string.replace(old_char, new_char)"} | |
| {"task_id": "Mbpp/475", "solution": "def sort_counter(counter):\n \"\"\"\n Sorts a dictionary by its values in descending order.\n\n Args:\n counter (dict): The dictionary to be sorted.\n\n Returns:\n list: A list of tuples sorted by the dictionary's values in descending order.\n \"\"\"\n return sorted(counter.items(), key=lambda item: item[1], reverse=True)"} | |
| {"task_id": "Mbpp/476", "solution": "def big_sum(arr):\n \"\"\"\n Finds the sum of the largest and smallest value in a given array.\n\n Parameters:\n arr (list): A list of integers.\n\n Returns:\n int: The sum of the largest and smallest value in the array.\n \"\"\"\n if not arr:\n return 0\n return max(arr) + min(arr)"} | |
| {"task_id": "Mbpp/477", "solution": "def is_lower(s):\n \"\"\"\n Convert the given string to lower case.\n\n Parameters:\n s (str): The string to be converted.\n\n Returns:\n str: The converted string in lower case.\n \"\"\"\n return s.lower()"} | |
| {"task_id": "Mbpp/478", "solution": "import re\ndef remove_lowercase(input_string):\n \"\"\"\n Removes lowercase substrings from the given string.\n\n Args:\n input_string (str): The string from which lowercase substrings are to be removed.\n\n Returns:\n str: The modified string with lowercase substrings removed.\n \"\"\"\n return re.sub('[a-z]', '', input_string)"} | |
| {"task_id": "Mbpp/479", "solution": "def first_Digit(n):\n \"\"\"\n Find the first digit of a given number.\n\n Parameters:\n n (int): The number to find the first digit of.\n\n Returns:\n int: The first digit of the given number.\n \"\"\"\n while n >= 10:\n n //= 10\n return n"} | |
| {"task_id": "Mbpp/554", "solution": "def Split(numbers):\n \"\"\"\n Takes a list of integers and returns only the odd ones.\n \"\"\"\n return [num for num in numbers if num % 2 != 0]"} | |
| {"task_id": "Mbpp/555", "solution": "def difference(n):\n \"\"\"\n Calculate the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.\n\n Args:\n n (int): The number of natural numbers to consider.\n\n Returns:\n int: The difference between the sum of cubes and the sum of the first n natural numbers.\n \"\"\"\n sum_of_cubes = sum(i**3 for i in range(1, n+1))\n sum_of_numbers = sum(range(1, n+1))\n return sum_of_cubes - sum_of_numbers"} | |
| {"task_id": "Mbpp/556", "solution": "def find_Odd_Pair(arr, n):\n odd_count = 0\n for i in range(n):\n for j in range(i + 1, n):\n if (arr[i] ^ arr[j]) % 2 != 0:\n odd_count += 1\n return odd_count"} | |
| {"task_id": "Mbpp/557", "solution": "def toggle_string(s):\n \"\"\"\n Write a function to toggle the case of all characters in a string.\n assert toggle_string(\"Python\")==(\"pYTHON\")\n \"\"\"\n return s.swapcase()"} | |
| {"task_id": "Mbpp/558", "solution": "def digit_distance_nums(num1, num2):\n \"\"\"\n Calculate the sum of the per-digit difference between two integers.\n\n Args:\n num1 (int): The first integer.\n num2 (int): The second integer.\n\n Returns:\n int: The sum of the per-digit difference between the two integers.\n \"\"\"\n # Convert the integers to strings to iterate over each digit\n str_num1, str_num2 = str(num1), str(num2)\n \n # Determine the length of the longer number\n max_length = max(len(str_num1), len(str_num2))\n \n # Pad the shorter number with leading zeros\n str_num1 = str_num1.zfill(max_length)\n str_num2 = str_num2.zfill(max_length)\n \n # Calculate the sum of the per-digit difference\n digit_distance = sum(abs(int(d1) - int(d2)) for d1, d2 in zip(str_num1, str_num2))\n \n return digit_distance"} | |
| {"task_id": "Mbpp/559", "solution": "def max_sub_array_sum(nums, k):\n \"\"\"\n Find the sum of the largest contiguous sublist in the given list.\n\n Args:\n nums (list): A list of integers.\n k (int): The length of the sublist.\n\n Returns:\n int: The sum of the largest contiguous sublist.\n \"\"\"\n if not nums or k <= 0 or k > len(nums):\n return 0\n\n max_sum = current_sum = sum(nums[:k])\n for i in range(k, len(nums)):\n current_sum += nums[i] - nums[i - k]\n max_sum = max(max_sum, current_sum)\n\n return max_sum"} | |
| {"task_id": "Mbpp/560", "solution": "def union_elements(tuple1, tuple2):\n \"\"\"\n Find the union of the elements of two given tuples and output them in sorted order.\n\n Args:\n tuple1 (tuple): The first input tuple.\n tuple2 (tuple): The second input tuple.\n\n Returns:\n tuple: The sorted union of the elements from both input tuples.\n \"\"\"\n # Convert tuples to sets to remove duplicates and perform union operation\n union_set = set(tuple1) | set(tuple2)\n # Convert the set back to a tuple and sort it\n sorted_union = tuple(sorted(union_set))\n return sorted_union"} | |
| {"task_id": "Mbpp/562", "solution": "def Find_Max_Length(list_of_lists):\n \"\"\"\n Finds the length of the longest sublists within a given list of lists.\n\n Parameters:\n list_of_lists (list): A list containing sublists.\n\n Returns:\n int: The length of the longest sublist.\n \"\"\"\n max_length = 0\n for sublist in list_of_lists:\n if len(sublist) > max_length:\n max_length = len(sublist)\n return max_length"} | |
| {"task_id": "Mbpp/563", "solution": "import re\ndef extract_values(input_string):\n \"\"\"\n Extracts values between quotation marks from a string.\n\n Parameters:\n input_string (str): The string to extract values from.\n\n Returns:\n list: A list of values extracted from the string.\n \"\"\"\n return re.findall(r'\"(.*?)\"', input_string)"} | |
| {"task_id": "Mbpp/564", "solution": "def count_pairs(numbers, n):\n \"\"\"\n Counts the number of unique unordered pairs from the given list of integers where both elements are unequal.\n\n Parameters:\n numbers (list): A list of integers.\n n (int): The number of elements in the list.\n\n Returns:\n int: The count of unique unordered pairs with unequal elements.\n \"\"\"\n unique_elements = set(numbers)\n return len(unique_elements) * (len(unique_elements) - 1) // 2\n\n# Test cases\nassert count_pairs([1, 2, 1], 3) == 2\nassert count_pairs([1, 1, 1, 1], 4) == 0\nassert count_pairs([1, 2, 3, 4], 4) == 6\nassert count_pairs([1, 2, 3, 1, 2, 3], 6) == 9"} | |
| {"task_id": "Mbpp/565", "solution": "def split(string):\n \"\"\"\n Splits a string into a list of characters.\n\n Parameters:\n string (str): The string to split.\n\n Returns:\n list: A list of characters in the string.\n \"\"\"\n return list(string)"} | |
| {"task_id": "Mbpp/566", "solution": "def sum_digits(n):\n \"\"\"\n Calculate the sum of the digits of a non-negative integer.\n\n Args:\n n (int): A non-negative integer.\n\n Returns:\n int: The sum of the digits of the integer.\n \"\"\"\n return sum(int(digit) for digit in str(n))"} | |
| {"task_id": "Mbpp/567", "solution": "def issort_list(lst):\n return lst == sorted(lst)"} | |
| {"task_id": "Mbpp/568", "solution": "def create_empty_dictionaries(n):\n \"\"\"\n Create a list of n empty dictionaries.\n\n Parameters:\n n (int): The number of empty dictionaries to create.\n\n Returns:\n list: A list of n empty dictionaries.\n \"\"\"\n return [{} for _ in range(n)]\n\n# Test cases\nassert create_empty_dictionaries(5) == [{}, {}, {}, {}, {}]\nassert create_empty_dictionaries(0) == []\nassert create_empty_dictionaries(3) == [{}, {}, {}]\n\n# Print results of test cases"} | |
| {"task_id": "Mbpp/569", "solution": "def sort_sublists(list_of_lists):\n \"\"\"\n Sorts each sublist of strings in a given list of lists.\n\n Args:\n list_of_lists (list): A list of lists containing strings.\n\n Returns:\n list: A new list of lists with each sublist sorted.\n \"\"\"\n return [sorted(sublist) for sublist in list_of_lists]"} | |
| {"task_id": "Mbpp/572", "solution": "def two_unique_nums(lists):\n \"\"\"\n Remove duplicate numbers from a given number of lists.\n\n Args:\n lists (list): A list of lists containing numbers.\n\n Returns:\n list: A list of unique numbers from all the input lists.\n \"\"\"\n unique_nums = set()\n for lst in lists:\n unique_nums.update(lst)\n return list(unique_nums)"} | |
| {"task_id": "Mbpp/573", "solution": "def unique_product(lst):\n \"\"\"\n Calculate the product of the unique numbers in a given list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n int: The product of the unique numbers in the list.\n \"\"\"\n unique_numbers = set(lst)\n product = 1\n for num in unique_numbers:\n product *= num\n return product"} | |
| {"task_id": "Mbpp/576", "solution": "def is_Sub_Array(large_list, small_list):\n \"\"\"\n Check if small_list is a sublist of large_list.\n\n Parameters:\n large_list (list): The list in which to search for the sublist.\n small_list (list): The list that may be a sublist of large_list.\n\n Returns:\n bool: True if small_list is a sublist of large_list, False otherwise.\n \"\"\"\n if not small_list:\n return True\n if not large_list:\n return False\n for i in range(len(large_list) - len(small_list) + 1):\n if large_list[i:i+len(small_list)] == small_list:\n return True\n return False"} | |
| {"task_id": "Mbpp/577", "solution": "def last_Digit_Factorial(n):\n \"\"\"\n Write a python function to find the last digit in factorial of a given number.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n last_digit = 0\n for i in range(2, n + 1):\n last_digit = (last_digit * i) % 10\n return last_digit"} | |
| {"task_id": "Mbpp/578", "solution": "def interleave_lists(list1, list2, list3):\n \"\"\"\n Interleave three lists of the same length into a single flat list.\n\n Args:\n list1 (list): The first list.\n list2 (list): The second list.\n list3 (list): The third list.\n\n Returns:\n list: A single flat list containing interleaved elements from the input lists.\n \"\"\"\n return [item for sublist in zip(list1, list2, list3) for item in sublist]"} | |
| {"task_id": "Mbpp/579", "solution": "def find_dissimilar(tup1, tup2):\n \"\"\"\n Find the dissimilar elements in the given two tuples.\n\n Args:\n tup1 (tuple): The first tuple.\n tup2 (tuple): The second tuple.\n\n Returns:\n tuple: A tuple containing the dissimilar elements from both input tuples.\n \"\"\"\n return tuple(set(tup1) ^ set(tup2))"} | |
| {"task_id": "Mbpp/580", "solution": "def extract_even(nested_tuple):\n \"\"\"\n Write a function to remove uneven elements in the nested mixed tuple.\n assert extract_even((4, 5, (7, 6, (2, 4)), 6, 8)) == (4, (6, (2, 4)), 6, 8)\n \"\"\"\n result = ()\n for element in nested_tuple:\n if isinstance(element, tuple):\n # Recursively call the function for nested tuples\n element = extract_even(element)\n if element % 2 == 0:\n result += (element,)\n return result"} | |
| {"task_id": "Mbpp/581", "solution": "def surface_Area(base_edge, height):\n \"\"\"\n Calculate the surface area of a square pyramid given its base edge and height.\n\n Args:\n base_edge (float): The length of the base edge of the square pyramid.\n height (float): The height of the square pyramid.\n\n Returns:\n float: The surface area of the square pyramid.\n \"\"\"\n base_area = base_edge ** 2\n slant_height = (base_edge / 2) ** 2 + height ** 2\n slant_height = slant_height ** 0.5\n lateral_area = 4 * (base_edge * slant_height) / 2\n surface_area = base_area + lateral_area\n return surface_area"} | |
| {"task_id": "Mbpp/583", "solution": "def catalan_number(n):\n \"\"\"\n Returns the nth Catalan number.\n \"\"\"\n if n == 0:\n return 1\n catalan = [0] * (n + 1)\n catalan[0], catalan[1] = 1, 1\n for i in range(2, n + 1):\n for j in range(i):\n catalan[i] += catalan[j] * catalan[i - j - 1]\n return catalan[n]"} | |
| {"task_id": "Mbpp/585", "solution": "def expensive_items(dataset, n):\n \"\"\"\n Find the n most expensive items in a given dataset.\n\n Parameters:\n dataset (list): A list of dictionaries, where each dictionary represents an item with 'name' and 'price' keys.\n n (int): The number of most expensive items to find.\n\n Returns:\n list: A list of dictionaries representing the n most expensive items.\n \"\"\"\n sorted_items = sorted(dataset, key=lambda x: x['price'], reverse=True)\n return sorted_items[:n]"} | |
| {"task_id": "Mbpp/586", "solution": "def split_arr(arr, n):\n \"\"\"\n Split a list at the nth element and add the first part to the end.\n\n Parameters:\n arr (list): The input list.\n n (int): The index at which to split the list.\n\n Returns:\n list: The modified list with the first part moved to the end.\n \"\"\"\n return arr[n:] + arr[:n]\n\n# Test cases\nassert split_arr([12,10,5,6,52,36],2) == [5,6,52,36,12,10]\nassert split_arr([1,2,3,4,5],1) == [2,3,4,5,1]\nassert split_arr([1,2,3,4,5],4) == [5,1,2,3,4]\nassert split_arr([1,2,3,4,5],0) == [1,2,3,4,5]\nassert split_arr([1,2,3,4,5],5) == [1,2,3,4,5]"} | |
| {"task_id": "Mbpp/587", "solution": "def list_to_tuple(input_list):\n \"\"\"\n Converts a list to a tuple.\n\n Parameters:\n input_list (list): The list to be converted.\n\n Returns:\n tuple: The converted tuple.\n \"\"\"\n return tuple(input_list)\n\n# Test cases to validate the function\nassert list_to_tuple([5, 10, 7, 4, 15, 3]) == (5, 10, 7, 4, 15, 3)"} | |
| {"task_id": "Mbpp/588", "solution": "def big_diff(nums):\n \"\"\"\n Find the difference between the largest and smallest value in a given list.\n\n Args:\n nums (list): A list of integers.\n\n Returns:\n int: The difference between the largest and smallest value in the list.\n\n Examples:\n >>> big_diff([1, 2, 3, 4])\n 3\n >>> big_diff([10, 3, 5, 6])\n 7\n \"\"\"\n if not nums:\n return 0\n return max(nums) - min(nums)"} | |
| {"task_id": "Mbpp/589", "solution": "import math\ndef perfect_squares(start, end):\n \"\"\"\n Find all perfect squares between two given numbers.\n\n Args:\n start (int): The starting number.\n end (int): The ending number.\n\n Returns:\n list: A list of perfect squares between the start and end numbers.\n \"\"\"\n squares = []\n for i in range(start, end + 1):\n root = math.isqrt(i)\n if root * root == i:\n squares.append(i)\n return squares"} | |
| {"task_id": "Mbpp/590", "solution": "import cmath"} | |
| {"task_id": "Mbpp/591", "solution": "def swap_List(input_list):\n \"\"\"\n Function to interchange the first and last elements in a list.\n\n Parameters:\n input_list (list): The list whose first and last elements are to be swapped.\n\n Returns:\n list: The list with its first and last elements swapped.\n \"\"\"\n if len(input_list) > 1:\n input_list[0], input_list[-1] = input_list[-1], input_list[0]\n return input_list"} | |
| {"task_id": "Mbpp/592", "solution": "from math import comb"} | |
| {"task_id": "Mbpp/593", "solution": "def removezero_ip(ip_address):\n \"\"\"\n Removes leading zeroes from an IP address.\n\n Parameters:\n ip_address (str): The IP address to remove leading zeroes from.\n\n Returns:\n str: The IP address with leading zeroes removed.\n \"\"\"\n return '.'.join(str(int(part)) for part in ip_address.split('.'))"} | |
| {"task_id": "Mbpp/594", "solution": "def diff_even_odd(numbers):\n \"\"\"\n Find the difference between the first even and first odd number in a given list.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n int: The difference between the first even and first odd number.\n\n Examples:\n >>> diff_even_odd([1,3,5,7,4,1,6,8])\n 3\n \"\"\"\n first_odd = None\n first_even = None\n\n for num in numbers:\n if first_odd is None and num % 2 != 0:\n first_odd = num\n if first_even is None and num % 2 == 0:\n first_even = num\n if first_odd is not None and first_even is not None:\n break\n\n if first_odd is None or first_even is None:\n return 0\n else:\n return first_even - first_odd"} | |
| {"task_id": "Mbpp/596", "solution": "import sys\ndef tuple_size(t):\n \"\"\"\n Calculate the size in bytes of the given tuple.\n\n Parameters:\n t (tuple): The tuple for which to calculate the size in bytes.\n\n Returns:\n int: The size in bytes of the given tuple.\n \"\"\"\n return sys.getsizeof(t)"} | |
| {"task_id": "Mbpp/597", "solution": "def find_kth_element(arr1, arr2, k):\n \"\"\"\n Finds the kth element from two sorted arrays.\n\n Args:\n arr1 (list): The first sorted array.\n arr2 (list): The second sorted array.\n k (int): The kth position to find.\n\n Returns:\n int: The kth element from the combined sorted array.\n \"\"\"\n if not arr1:\n return arr2[k - 1]\n if not arr2:\n return arr1[k - 1]\n if k == 1:\n return min(arr1[0], arr2[0])\n\n mid1 = arr1[k // 2 - 1] if k // 2 <= len(arr1) else float('inf')\n mid2 = arr2[k // 2 - 1] if k // 2 <= len(arr2) else float('inf')\n\n if mid1 < mid2:\n return find_kth_element(arr1[k // 2:], arr2, k - k // 2)\n else:\n return find_kth_element(arr1, arr2[k // 2:], k - k // 2)\n\n# Test cases\nassert find_kth_element([2, 3, 6, 7, 9], [1, 4, 8, 10], 5) == 6\nassert find_kth_element([1, 2], [3, 4, 5], 3) == 3\nassert find_kth_element([1, 2, 3], [4, 5, 6], 4) == 4\nassert find_kth_element([1, 2, 3], [], 2) == 2\nassert find_kth_element([], [1, 2, 3], 1) == 1"} | |
| {"task_id": "Mbpp/598", "solution": "def armstrong_number(number):\n \"\"\"\n Check if the given number is an Armstrong number.\n \n Args:\n number (int): The number to check.\n \n Returns:\n bool: True if the number is an Armstrong number, False otherwise.\n \"\"\"\n num_str = str(number)\n num_digits = len(num_str)\n sum_of_powers = sum(int(digit) ** num_digits for digit in num_str)\n return sum_of_powers == number"} | |
| {"task_id": "Mbpp/599", "solution": "def sum_average(n):\n \"\"\"\n Calculate the sum and average of the first n natural numbers.\n\n Parameters:\n n (int): The number of natural numbers to consider.\n\n Returns:\n tuple: A tuple containing the sum and average of the first n natural numbers.\n \"\"\"\n sum_n = n * (n + 1) // 2\n average_n = sum_n / n\n return sum_n, average_n"} | |
| {"task_id": "Mbpp/600", "solution": "def is_Even(n):\n \"\"\"\n Check if the given number is even.\n\n Parameters:\n n (int): The number to check.\n\n Returns:\n bool: True if the number is even, False otherwise.\n \"\"\"\n return n % 2 == 0"} | |
| {"task_id": "Mbpp/602", "solution": "def first_repeated_char(s):\n \"\"\"\n Find the first repeated character in a given string.\n\n Args:\n s (str): The input string to search for the first repeated character.\n\n Returns:\n str: The first repeated character found in the string, or None if no repeated character is found.\n \"\"\"\n char_count = {}\n for char in s:\n if char in char_count:\n return char\n else:\n char_count[char] = 1\n return None"} | |
| {"task_id": "Mbpp/603", "solution": "def get_ludic(n):\n \"\"\"\n Returns a list of lucid numbers smaller than or equal to n.\n \"\"\"\n ludic_numbers = list(range(1, n + 1))\n index = 1\n while index < len(ludic_numbers):\n step = ludic_numbers[index]\n ludic_numbers = [ludic_numbers[i] for i in range(len(ludic_numbers)) if (i + 1) % step != 0]\n index += 1\n return ludic_numbers"} | |
| {"task_id": "Mbpp/604", "solution": "def reverse_words(s):\n \"\"\"\n Reverse words in a given string separated by spaces.\n\n Args:\n s (str): The input string.\n\n Returns:\n str: The string with words reversed.\n\n Examples:\n >>> reverse_words(\"python program\")\n \"program python\"\n \"\"\"\n return ' '.join(s.split()[::-1])"} | |
| {"task_id": "Mbpp/605", "solution": "def prime_num(n):\n \"\"\"\n Check if the given integer is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n if n % i == 0 or n % (i + 2) == 0:\n return False\n i += 6\n return True"} | |
| {"task_id": "Mbpp/606", "solution": "import math\ndef radian_degree(degrees):\n \"\"\"\n Convert degrees to radians.\n \"\"\"\n return degrees * (math.pi / 180)"} | |
| {"task_id": "Mbpp/607", "solution": "import re\ndef find_literals(text, pattern):\n \"\"\"\n Search a string for a regex pattern and return the matching substring, start index, and end index.\n\n Args:\n text (str): The string to search.\n pattern (str): The regex pattern to search for.\n\n Returns:\n tuple: A tuple containing the matching substring, start index, and end index.\n \"\"\"\n match = re.search(pattern, text)\n if match:\n return match.group(), match.start(), match.end()\n else:\n return None, -1, -1"} | |
| {"task_id": "Mbpp/608", "solution": "def bell_number(n):\n \"\"\"\n Calculate the nth Bell number.\n\n Args:\n n (int): The order of the Bell number to calculate.\n\n Returns:\n int: The nth Bell number.\n\n Examples:\n >>> bell_number(2)\n 2\n \"\"\"\n bell = [[0 for _ in range(n+1)] for _ in range(n+1)]\n bell[0][0] = 1\n for i in range(1, n+1):\n bell[i][0] = bell[i-1][i-1]\n for j in range(1, i+1):\n bell[i][j] = bell[i-1][j-1] + bell[i][j-1]\n return bell[n][0]\n\n# Test cases\nassert bell_number(2) == 2\nassert bell_number(3) == 5\nassert bell_number(4) == 15\nassert bell_number(5) == 52"} | |
| {"task_id": "Mbpp/610", "solution": "def remove_kth_element(lst, k):\n \"\"\"\n Removes the k'th element from the given list and returns a new list with the remaining elements.\n \n Parameters:\n lst (list): The input list.\n k (int): The index of the element to remove.\n \n Returns:\n list: A new list with the k'th element removed.\n \"\"\"\n if 1 <= k <= len(lst):\n return lst[:k-1] + lst[k:]\n else:\n return lst"} | |
| {"task_id": "Mbpp/611", "solution": "def max_of_nth(matrix, n):\n \"\"\"\n Given a matrix represented as a list of lists, returns the maximum value in the n'th column.\n\n Args:\n matrix (list of lists): The input matrix.\n n (int): The index of the column to find the maximum value in.\n\n Returns:\n int: The maximum value in the n'th column.\n\n Example:\n >>> max_of_nth([[5, 6, 7], [1, 3, 5], [8, 9, 19]], 2)\n 19\n \"\"\"\n if not matrix or n < 0 or n >= len(matrix[0]):\n return None # Return None if the matrix is empty or n is out of bounds\n\n max_value = matrix[0][n]\n for row in matrix:\n if row[n] > max_value:\n max_value = row[n]\n\n return max_value"} | |
| {"task_id": "Mbpp/612", "solution": "def merge(lst):\n \"\"\"\n 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.\n \"\"\"\n return [list(map(lambda x: x[0], lst)), list(map(lambda x: x[1], lst))]"} | |
| {"task_id": "Mbpp/614", "solution": "def cummulative_sum(tuples):\n \"\"\"\n Calculate the cumulative sum of all values in the given tuple list.\n\n Args:\n tuples (list of tuples): A list containing tuples with integer values.\n\n Returns:\n int: The cumulative sum of all values in the tuples.\n\n Example:\n >>> cummulative_sum([(1, 3), (5, 6, 7), (2, 6)])\n 30\n \"\"\"\n return sum(sum(t) for t in tuples)"} | |
| {"task_id": "Mbpp/615", "solution": "def average_tuple(tuples):\n \"\"\"\n Takes a tuple of tuples and returns the average value for each tuple as a list.\n \"\"\"\n return [sum(t) / len(t) for t in tuples]"} | |
| {"task_id": "Mbpp/616", "solution": "def tuple_modulo(tup1, tup2):\n \"\"\"\n Perform element-wise modulo operation on two tuples of the same length.\n\n Args:\n tup1 (tuple): The first input tuple.\n tup2 (tuple): The second input tuple.\n\n Returns:\n tuple: A new tuple containing the element-wise modulo results.\n\n Raises:\n ValueError: If the input tuples are not of the same length.\n\n Examples:\n >>> tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5))\n (0, 4, 5, 1)\n \"\"\"\n if len(tup1) != len(tup2):\n raise ValueError(\"Input tuples must be of the same length.\")\n\n return tuple(x % y for x, y in zip(tup1, tup2))"} | |
| {"task_id": "Mbpp/618", "solution": "def div_list(l1, l2):\n \"\"\"\n Divide two lists element wise.\n\n Parameters:\n l1 (list): The first list.\n l2 (list): The second list.\n\n Returns:\n list: A new list containing the element-wise division of l1 by l2.\n \"\"\"\n return [a / b for a, b in zip(l1, l2)]"} | |
| {"task_id": "Mbpp/619", "solution": "def move_num(s):\n \"\"\"\n Move all the numbers to the end of the given string.\n\n Parameters:\n s (str): The input string.\n\n Returns:\n str: The modified string with all numbers moved to the end.\n \"\"\"\n return ''.join([c for c in s if not c.isdigit()]) + ''.join([c for c in s if c.isdigit()])"} | |
| {"task_id": "Mbpp/620", "solution": "def largest_subset(nums):\n \"\"\"\n Finds the size of the largest subset of a list of numbers so that every pair is divisible.\n \"\"\"\n nums.sort()\n dp = [1] * len(nums)\n max_size = 1\n\n for i in range(len(nums)):\n for j in range(i):\n if nums[i] % nums[j] == 0:\n dp[i] = max(dp[i], dp[j] + 1)\n max_size = max(max_size, dp[i])\n\n return max_size"} | |
| {"task_id": "Mbpp/622", "solution": "def get_median(list1, list2, n):\n \"\"\"\n Find the median of two sorted lists of the same size.\n\n Args:\n list1 (list): The first sorted list.\n list2 (list): The second sorted list.\n n (int): The size of the lists.\n\n Returns:\n float: The median of the two lists.\n \"\"\"\n # Merge the two lists\n merged_list = sorted(list1 + list2)\n\n # Calculate the median\n if n % 2 == 0:\n median = (merged_list[n // 2 - 1] + merged_list[n // 2]) / 2\n else:\n median = merged_list[n // 2]\n\n return median"} | |
| {"task_id": "Mbpp/623", "solution": "def nth_nums(lst, n):\n \"\"\"\n Compute the n-th power of each number in a list.\n\n Parameters:\n lst (list): A list of numbers.\n n (int): The power to which each number in the list should be raised.\n\n Returns:\n list: A new list containing the n-th powers of the original numbers.\n \"\"\"\n return [x**n for x in lst]"} | |
| {"task_id": "Mbpp/624", "solution": "def to_uppercase(input_string):\n \"\"\"\n Converts the given string to uppercase.\n\n Parameters:\n input_string (str): The string to be converted.\n\n Returns:\n str: The uppercase version of the input string.\n \"\"\"\n return input_string.upper()\n\n# Test cases to validate the function\nassert to_uppercase(\"person\") == \"PERSON\"\nassert to_uppercase(\"world\") == \"WORLD\"\nassert to_uppercase(\"python\") == \"PYTHON\"\nassert to_uppercase(\"programming\") == \"PROGRAMMING\""} | |
| {"task_id": "Mbpp/626", "solution": "import math\ndef triangle_area(radius):\n \"\"\"\n Calculate the area of the largest triangle that can be inscribed in a semicircle with the given radius.\n \n Parameters:\n radius (float): The radius of the semicircle.\n \n Returns:\n float: The area of the largest inscribed triangle, or None if the input is invalid.\n \"\"\"\n if radius < 0:\n return None\n return (math.sqrt(3) / 4) * radius ** 2"} | |
| {"task_id": "Mbpp/628", "solution": "def replace_spaces(input_string):\n \"\"\"\n Replaces all spaces in the given string with '%20'.\n\n Parameters:\n input_string (str): The string to be processed.\n\n Returns:\n str: The processed string with spaces replaced by '%20'.\n \"\"\"\n return input_string.replace(\" \", \"%20\")"} | |
| {"task_id": "Mbpp/629", "solution": "def find_even_numbers(numbers):\n \"\"\"\n This function takes a list of numbers and returns a list of even numbers.\n \n Args:\n numbers (list): A list of integers.\n \n Returns:\n list: A list containing only the even numbers from the input list.\n \"\"\"\n return [num for num in numbers if num % 2 == 0]\n\n# Test cases to verify the correctness of the function\nassert find_even_numbers([1, 2, 3, 4, 5]) == [2, 4]\nassert find_even_numbers([10, 15, 20, 25, 30]) == [10, 20, 30]\nassert find_even_numbers([0, 1, -2, -3, 4]) == [0, -2, 4]"} | |
| {"task_id": "Mbpp/630", "solution": "def get_coordinates(point):\n \"\"\"\n Extracts all the adjacent coordinates of the given coordinate tuple.\n \n Args:\n point (tuple): A tuple representing the coordinate (x, y).\n \n Returns:\n list: A list of tuples representing the adjacent coordinates.\n \"\"\"\n x, y = point\n return [[x-1, y-1], [x, y-1], [x+1, y-1], [x-1, y], [x+1, y], [x-1, y+1], [x, y+1], [x+1, y+1]]"} | |
| {"task_id": "Mbpp/631", "solution": "def replace_spaces(input_string):\n \"\"\"\n Replaces whitespaces with underscores and underscores with whitespaces in the given string.\n\n Args:\n input_string (str): The string to be transformed.\n\n Returns:\n str: The transformed string with spaces replaced by underscores and vice versa.\n \"\"\"\n transformed_string = input_string.replace(' ', '_').replace('_', ' ')\n return transformed_string"} | |
| {"task_id": "Mbpp/632", "solution": "def move_zero(lst):\n \"\"\"\n Move all zeroes to the end of the given list.\n\n Args:\n lst (list): The input list containing integers.\n\n Returns:\n list: A new list with all zeroes moved to the end.\n\n Examples:\n >>> move_zero([1,0,2,0,3,4])\n [1, 2, 3, 4, 0, 0]\n \"\"\"\n non_zero = [num for num in lst if num != 0]\n zeros = [0] * (len(lst) - len(non_zero))\n return non_zero + zeros"} | |
| {"task_id": "Mbpp/633", "solution": "def pair_xor_Sum(arr, n):\n \"\"\"\n Calculate the sum of xor of all pairs of numbers in the given list.\n\n Parameters:\n arr (list): A list of integers.\n n (int): The number of elements in the list.\n\n Returns:\n int: The sum of xor of all pairs of numbers in the list.\n \"\"\"\n result = 0\n for i in range(32):\n count = 0\n for j in range(n):\n if (arr[j] >> i) & 1:\n count += 1\n result += (count * (n - count) * (1 << i))\n return result"} | |
| {"task_id": "Mbpp/635", "solution": "def heap_sort(lst):\n \"\"\"\n Sorts the given list using the heap sort algorithm.\n\n Args:\n lst (list): The list to be sorted.\n\n Returns:\n list: The sorted list.\n \"\"\"\n def heapify(arr, n, i):\n largest = i\n l = 2 * i + 1\n r = 2 * i + 2\n\n if l < n and arr[i] < arr[l]:\n largest = l\n\n if r < n and arr[largest] < arr[r]:\n largest = r\n\n if largest != i:\n arr[i], arr[largest] = arr[largest], arr[i]\n heapify(arr, n, largest)\n\n n = len(lst)\n\n for i in range(n // 2 - 1, -1, -1):\n heapify(lst, n, i)\n\n for i in range(n - 1, 0, -1):\n lst[i], lst[0] = lst[0], lst[i]\n heapify(lst, i, 0)\n\n return lst"} | |
| {"task_id": "Mbpp/637", "solution": "def noprofit_noloss(revenue, cost):\n \"\"\"\n Check if there is no profit and no loss.\n\n Args:\n revenue (int): The total revenue.\n cost (int): The total cost.\n\n Returns:\n bool: True if there is no profit and no loss, False otherwise.\n \"\"\"\n return revenue == cost"} | |
| {"task_id": "Mbpp/638", "solution": "def wind_chill(velocity, temperature):\n \"\"\"\n Calculate the wind chill index rounded to the next integer given the wind velocity in km/h and a temperature in celsius.\n \"\"\"\n if velocity < 3 or temperature > 10:\n return None\n wind_chill = 13.12 + 0.6215 * temperature - 11.37 * velocity**0.16 + 0.3965 * temperature * velocity**0.16\n return round(wind_chill)"} | |
| {"task_id": "Mbpp/639", "solution": "def sample_nam(names):\n \"\"\"\n Sums the length of the names in the given list after removing names that start with a lowercase letter.\n\n Args:\n names (list): A list of names (strings).\n\n Returns:\n int: The sum of the lengths of the names that do not start with a lowercase letter.\n \"\"\"\n total_length = 0\n for name in names:\n if name[0].isupper():\n total_length += len(name)\n return total_length"} | |
| {"task_id": "Mbpp/641", "solution": "def is_nonagonal(n):\n \"\"\"\n Calculate the nth nonagonal number.\n Args:\n n (int): The position of the nonagonal number in the sequence.\n\n Returns:\n int: The nth nonagonal number.\n\n Examples:\n >>> is_nonagonal(10)\n 325\n \"\"\"\n if n < 1:\n raise ValueError(\"n must be a positive integer\")\n return n * (7 * n - 5) // 2"} | |
| {"task_id": "Mbpp/643", "solution": "import re\ndef text_match_wordz_middle(text):\n \"\"\"\n Checks if a string contains 'z', except at the start and end of the word.\n \n Args:\n text (str): The input string to be checked.\n \n Returns:\n bool: True if 'z' is found in the middle of a word, False otherwise.\n \"\"\"\n pattern = r'\\Bz\\B'\n return bool(re.search(pattern, text))"} | |
| {"task_id": "Mbpp/644", "solution": "def reverse_Array_Upto_K(arr, k):\n \"\"\"\n Reverses the array up to the given position k.\n \n Parameters:\n arr (list): The input list of integers.\n k (int): The position up to which the array should be reversed.\n \n Returns:\n list: The modified list with the elements up to position k reversed.\n \"\"\"\n return arr[:k][::-1] + arr[k:]"} | |
| {"task_id": "Mbpp/720", "solution": "def add_dict_to_tuple(tup, dictionary):\n \"\"\"\n Add a dictionary to the end of a tuple and return the new tuple.\n\n Parameters:\n tup (tuple): The input tuple.\n dictionary (dict): The dictionary to be added to the tuple.\n\n Returns:\n tuple: A new tuple with the dictionary added to the end.\n \"\"\"\n return tup + (dictionary,)"} | |
| {"task_id": "Mbpp/721", "solution": "def maxAverageOfPath(matrix):\n \"\"\"\n Given a square matrix of size N*N, find the path with the maximum average cost.\n The path starts from the top-left cell, moves only right or down, and ends on the bottom-right cell.\n The average is computed as the total cost divided by the number of cells visited in the path.\n \n Args:\n matrix (list of lists): A square matrix of size N*N with integer values representing costs.\n \n Returns:\n float: The maximum average cost of a path.\n \"\"\"\n n = len(matrix)\n dp = [[0] * n for _ in range(n)]\n dp[0][0] = matrix[0][0]\n \n # Fill the first row and first column of dp\n for i in range(1, n):\n dp[i][0] = dp[i-1][0] + matrix[i][0]\n dp[0][i] = dp[0][i-1] + matrix[0][i]\n \n # Fill the rest of the dp table\n for i in range(1, n):\n for j in range(1, n):\n dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + matrix[i][j]\n \n # Calculate the maximum average cost\n return dp[n-1][n-1] / n"} | |
| {"task_id": "Mbpp/722", "solution": "def filter_data(students, min_height, min_weight):\n \"\"\"\n Filter students based on height and weight.\n\n Parameters:\n students (dict): A dictionary with student names as keys and tuples of (height, weight) as values.\n min_height (float): The minimum height required.\n min_weight (float): The minimum weight required.\n\n Returns:\n dict: A dictionary with students who meet the height and weight criteria.\n \"\"\"\n return {name: data for name, data in students.items() if data[0] > min_height and data[1] > min_weight}"} | |
| {"task_id": "Mbpp/723", "solution": "def count_same_pair(list1, list2):\n \"\"\"\n Count the number of indices where two lists have the same values.\n\n Parameters:\n list1 (list): The first input list.\n list2 (list): The second input list.\n\n Returns:\n int: The count of indices where the lists have the same values.\n \"\"\"\n if len(list1) != len(list2):\n raise ValueError(\"Input lists must have the same length.\")\n\n count = sum(1 for a, b in zip(list1, list2) if a == b)\n return count"} | |
| {"task_id": "Mbpp/724", "solution": "def power_base_sum(base, power):\n \"\"\"\n Calculate the sum of all digits of the base to the specified power.\n\n Args:\n base (int): The base number.\n power (int): The power to which the base is raised.\n\n Returns:\n int: The sum of all digits of the result.\n \"\"\"\n result = base ** power\n return sum(int(digit) for digit in str(result))"} | |
| {"task_id": "Mbpp/725", "solution": "import re\ndef extract_quotation(text):\n \"\"\"\n Extracts values between quotation marks \" \" of the given string.\n\n Args:\n text (str): The input string.\n\n Returns:\n list: A list of strings extracted between quotation marks.\n \"\"\"\n return re.findall(r'\"(.*?)\"', text)"} | |
| {"task_id": "Mbpp/726", "solution": "def multiply_elements(numbers):\n \"\"\"\n Takes a tuple of numbers (t_1,...,t_{N+1}) and returns a tuple of length N where the i-th element of the tuple is equal to t_i * t_{i+1}.\n \"\"\"\n return tuple(numbers[i] * numbers[i + 1] for i in range(len(numbers) - 1))"} | |
| {"task_id": "Mbpp/728", "solution": "def sum_list(lst1, lst2):\n \"\"\"\n Takes two lists [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].\n \"\"\"\n return [a + b for a, b in zip(lst1, lst2)]"} | |
| {"task_id": "Mbpp/730", "solution": "def consecutive_duplicates(lst):\n \"\"\"\n Removes consecutive duplicates of a given list.\n\n Parameters:\n lst (list): The input list.\n\n Returns:\n list: A new list with consecutive duplicates removed.\n \"\"\"\n if not lst:\n return []\n \n result = [lst[0]]\n for item in lst[1:]:\n if item != result[-1]:\n result.append(item)\n return result"} | |
| {"task_id": "Mbpp/731", "solution": "import math\ndef lateralsurface_cone(r, h):\n \"\"\"\n Calculate the lateral surface area of a cone given radius r and height h.\n \n Args:\n r (float): The radius of the base of the cone.\n h (float): The height of the cone.\n \n Returns:\n float: The lateral surface area of the cone.\n \"\"\"\n slant_height = math.sqrt(r**2 + h**2)\n lateral_surface_area = math.pi * r * slant_height\n return lateral_surface_area"} | |
| {"task_id": "Mbpp/732", "solution": "def replace_specialchar(input_str):\n \"\"\"\n Replace all occurrences of spaces, commas, or dots with a colon.\n \n Args:\n input_str (str): The input string containing spaces, commas, or dots.\n \n Returns:\n str: The modified string with all spaces, commas, or dots replaced by colons.\n \"\"\"\n return ''.join(char if char not in ' ,.' else ':' for char in input_str)"} | |
| {"task_id": "Mbpp/733", "solution": "def find_first_occurrence(arr, target):\n \"\"\"\n Finds the index of the first occurrence of a given number in a sorted array.\n \n Parameters:\n arr (list): A sorted list of integers.\n target (int): The number to search for in the array.\n \n Returns:\n int: The index of the first occurrence of the target number, or -1 if not found.\n \"\"\"\n left, right = 0, len(arr) - 1\n result = -1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n result = mid\n right = mid - 1 # Continue searching in the left half\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return result"} | |
| {"task_id": "Mbpp/734", "solution": "from itertools import combinations"} | |
| {"task_id": "Mbpp/735", "solution": "def toggle_middle_bits(n):\n \"\"\"\n Toggle bits of the number except the first and the last bit.\n \n Args:\n n (int): The input number.\n \n Returns:\n int: The number with the middle bits toggled.\n \"\"\"\n # Calculate the number of bits in the number\n num_bits = n.bit_length()\n \n # Create a mask with all bits set except the first and last\n mask = (1 << (num_bits - 1)) - 1 # Sets all bits\n mask = mask ^ ((1 << num_bits) - 1) # Clears the first and last bits\n \n # Toggle the middle bits using XOR\n result = n ^ mask\n \n return result"} | |
| {"task_id": "Mbpp/736", "solution": "def left_insertion(sorted_list, value):\n \"\"\"\n Locate the left insertion point for a specified value in sorted order.\n\n Args:\n sorted_list (list): A list of sorted integers.\n value (int): The value to insert.\n\n Returns:\n int: The index at which the value should be inserted.\n\n Examples:\n >>> left_insertion([1,2,4,5], 6)\n 4\n \"\"\"\n left, right = 0, len(sorted_list)\n while left < right:\n mid = (left + right) // 2\n if sorted_list[mid] < value:\n left = mid + 1\n else:\n right = mid\n return left"} | |
| {"task_id": "Mbpp/737", "solution": "import re\ndef check_str(s):\n \"\"\"\n Check if the given string starts with a vowel using regex.\n\n Args:\n s (str): The input string to check.\n\n Returns:\n bool: True if the string starts with a vowel, False otherwise.\n \"\"\"\n return bool(re.match(r'^[aeiouAEIOU]', s))"} | |
| {"task_id": "Mbpp/739", "solution": "def find_Index(n):\n \"\"\"\n Find the index of the smallest triangular number with n digits.\n \n Parameters:\n n (int): The number of digits in the triangular number.\n \n Returns:\n int: The index of the smallest triangular number with n digits.\n \"\"\"\n start = 1\n while True:\n triangular_number = start * (start + 1) // 2\n if len(str(triangular_number)) == n:\n return start\n start += 1"} | |
| {"task_id": "Mbpp/740", "solution": "def tuple_to_dict(t):\n \"\"\"\n Converts a tuple of alternating keys and values into a dictionary.\n \n Args:\n t (tuple): A tuple containing alternating keys and values.\n \n Returns:\n dict: A dictionary with keys and values from the input tuple.\n \"\"\"\n return {t[i]: t[i + 1] for i in range(0, len(t), 2)}"} | |
| {"task_id": "Mbpp/741", "solution": "def all_Characters_Same(input_string):\n \"\"\"\n Check if all characters in the input string are the same.\n\n Args:\n input_string (str): The string to check.\n\n Returns:\n bool: True if all characters are the same, False otherwise.\n \"\"\"\n return len(set(input_string)) == 1"} | |
| {"task_id": "Mbpp/742", "solution": "import math\ndef area_tetrahedron(side_length):\n \"\"\"\n Calculate the surface area of a regular tetrahedron.\n\n Parameters:\n side_length (float): The length of a side of the tetrahedron.\n\n Returns:\n float: The surface area of the tetrahedron.\n \"\"\"\n return math.sqrt(3) * side_length ** 2"} | |
| {"task_id": "Mbpp/743", "solution": "def rotate_right(lst, num):\n \"\"\"\n Rotates a given list by specified number of items to the right direction.\n\n Args:\n lst (list): The input list to be rotated.\n num (int): The number of items to rotate the list by.\n\n Returns:\n list: The rotated list.\n \"\"\"\n num %= len(lst) # Handle cases where num is larger than the list length\n return lst[-num:] + lst[:-num]"} | |
| {"task_id": "Mbpp/744", "solution": "def check_none(tup):\n \"\"\"\n Check if the given tuple has any None value or not.\n\n Parameters:\n tup (tuple): The input tuple to be checked.\n\n Returns:\n bool: True if the tuple contains None, False otherwise.\n \"\"\"\n return None in tup"} | |
| {"task_id": "Mbpp/745", "solution": "def divisible_by_digits(startnum, endnum):\n \"\"\"\n Find numbers within a given range from startnum to endnum where every number is divisible by every digit it contains.\n\n Args:\n startnum (int): The starting number of the range.\n endnum (int): The ending number of the range.\n\n Returns:\n list: A list of numbers that are divisible by every digit they contain.\n\n Example:\n >>> divisible_by_digits(1, 22)\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n \"\"\"\n def all_divisible(n):\n for digit in str(n):\n if digit == '0' or n % int(digit) != 0:\n return False\n return True\n\n return [n for n in range(startnum, endnum + 1) if all_divisible(n)]"} | |
| {"task_id": "Mbpp/748", "solution": "def capital_words_spaces(text):\n \"\"\"\n Insert spaces before words that start with a capital letter in the given string.\n\n Args:\n text (str): The input string.\n\n Returns:\n str: The modified string with spaces inserted before capital words.\n \"\"\"\n import re\n return re.sub(r'(?<!^)(?=[A-Z])', ' ', text)"} | |
| {"task_id": "Mbpp/749", "solution": "def sort_numeric_strings(lst):\n \"\"\"\n Sorts a given list of strings of numbers numerically.\n\n Args:\n lst (list): A list of strings representing numbers.\n\n Returns:\n list: A sorted list of numbers.\n \"\"\"\n return sorted(lst, key=int)"} | |
| {"task_id": "Mbpp/750", "solution": "def add_tuple(lst, tpl):\n \"\"\"\n Add the given tuple to the given list.\n\n Parameters:\n lst (list): The list to which the tuple will be added.\n tpl (tuple): The tuple to be added to the list.\n\n Returns:\n list: The updated list with the tuple appended.\n\n Example:\n >>> add_tuple([5, 6, 7], (9, 10))\n [5, 6, 7, 9, 10]\n \"\"\"\n return lst + list(tpl)"} | |
| {"task_id": "Mbpp/751", "solution": "def check_min_heap(arr):\n \"\"\"\n Check if the given array represents a min heap or not.\n\n Args:\n arr (list): The input array to check.\n\n Returns:\n bool: True if the array represents a min heap, False otherwise.\n \"\"\"\n n = len(arr)\n for i in range(n // 2 - 1, -1, -1):\n if arr[i] > arr[2 * i + 1]:\n return False\n if 2 * i + 2 < n and arr[i] > arr[2 * i + 2]:\n return False\n return True"} | |
| {"task_id": "Mbpp/752", "solution": "def jacobsthal_num(n):\n \"\"\"\n Calculate the nth Jacobsthal number.\n \n Args:\n n (int): The position of the Jacobsthal number to be calculated.\n \n Returns:\n int: The nth Jacobsthal number.\n \"\"\"\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, 2 * b + a\n return b"} | |
| {"task_id": "Mbpp/753", "solution": "def min_k(tuple_list, k):\n \"\"\"\n Find the minimum k records from a list of tuples.\n\n Args:\n tuple_list (list): A list of tuples.\n k (int): The number of minimum records to find.\n\n Returns:\n list: A list of k tuples with the smallest second elements.\n \"\"\"\n return sorted(tuple_list, key=lambda x: x[1])[:k]"} | |
| {"task_id": "Mbpp/754", "solution": "def extract_index_list(l1, l2, l3):\n \"\"\"\n Finds common elements from three lists based on their indices.\n\n Parameters:\n l1 (list): The first list.\n l2 (list): The second list.\n l3 (list): The third list.\n\n Returns:\n list: A list of common elements found at the same indices in all three lists.\n \"\"\"\n common_elements = []\n for i in range(min(len(l1), len(l2), len(l3))):\n if l1[i] == l2[i] == l3[i]:\n common_elements.append(l1[i])\n return common_elements"} | |
| {"task_id": "Mbpp/755", "solution": "def second_smallest(numbers):\n \"\"\"\n Find the second smallest number in a list.\n\n Args:\n numbers (list): A list of numbers.\n\n Returns:\n int or float: The second smallest number in the list.\n\n Examples:\n >>> second_smallest([1, 2, -8, -2, 0, -2])\n -2\n \"\"\"\n if len(numbers) < 2:\n raise ValueError(\"List must contain at least two elements.\")\n \n smallest = second_smallest = float('inf')\n for number in numbers:\n if number < smallest:\n second_smallest = smallest\n smallest = number\n elif smallest < number < second_smallest:\n second_smallest = number\n\n return second_smallest"} | |
| {"task_id": "Mbpp/757", "solution": "def count_reverse_pairs(lst):\n \"\"\"\n Count the pairs of reverse strings in the given string list.\n\n Args:\n lst (list): A list of strings.\n\n Returns:\n int: The number of reverse string pairs.\n \"\"\"\n count = 0\n for i in range(len(lst)):\n for j in range(i + 1, len(lst)):\n if lst[i] == lst[j][::-1]:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/758", "solution": "from collections import Counter\ndef unique_sublists(lst):\n \"\"\"\n Count the number of occurrences of each sublist in the given list and return a dictionary with tuples of sublists as keys and their counts as values.\n \n Args:\n lst (list): A list containing sublists.\n \n Returns:\n dict: A dictionary with tuples of sublists as keys and their counts as values.\n \"\"\"\n # Convert each sublist to a tuple and count occurrences using Counter\n return dict(Counter(map(tuple, lst)))"} | |
| {"task_id": "Mbpp/759", "solution": "def is_decimal(s):\n \"\"\"\n Check if the input string is a decimal number with a precision of 2.\n \n Args:\n s (str): The input string to be checked.\n \n Returns:\n bool: True if the string is a decimal number with a precision of 2, False otherwise.\n \"\"\"\n try:\n float(s)\n return s.count('.') == 1 and s.replace('.', '').isdigit() and len(s.split('.')[1]) == 2\n except ValueError:\n return False"} | |
| {"task_id": "Mbpp/760", "solution": "def unique_Element(lst):\n \"\"\"\n Check if all elements in the list are the same.\n\n Args:\n lst (list): A list of numbers.\n\n Returns:\n bool: True if all elements are the same, False otherwise.\n \"\"\"\n return len(set(lst)) == 1"} | |
| {"task_id": "Mbpp/762", "solution": "def check_month_number(month_number):\n \"\"\"\n Check if the given month number contains 30 days.\n\n Parameters:\n month_number (int): The number of the month (1-12).\n\n Returns:\n bool: True if the month has 30 days, False otherwise.\n \"\"\"\n # List of months with 30 days\n thirty_day_months = [4, 6, 9, 11]\n \n # Check if the given month number is in the list\n return month_number in thirty_day_months\n\n# Test cases to validate the function\nassert check_month_number(6) == True\nassert check_month_number(2) == False\nassert check_month_number(11) == True\nassert check_month_number(1) == False"} | |
| {"task_id": "Mbpp/763", "solution": "def find_min_diff(arr, n):\n \"\"\"\n Finds the minimum difference between any two elements in a given array.\n\n Parameters:\n arr (tuple): The input array of integers.\n n (int): The number of elements to consider from the end of the array.\n\n Returns:\n int: The minimum difference between any two elements.\n\n Example:\n >>> find_min_diff((1, 5, 3, 19, 18, 25), 6)\n 1\n \"\"\"\n # Sort the array in ascending order\n sorted_arr = sorted(arr)\n \n # Initialize the minimum difference to a large number\n min_diff = float('inf')\n \n # Iterate over the first n-1 elements\n for i in range(n - 1):\n # Calculate the difference between the current element and the next one\n diff = sorted_arr[i + 1] - sorted_arr[i]\n \n # Update the minimum difference if the current difference is smaller\n if diff < min_diff:\n min_diff = diff\n \n return min_diff"} | |
| {"task_id": "Mbpp/764", "solution": "def number_ctr(input_string):\n \"\"\"\n Count the number of digits in a given string.\n\n Args:\n input_string (str): The string to count digits in.\n\n Returns:\n int: The number of digits in the input string.\n \"\"\"\n return sum(c.isdigit() for c in input_string)"} | |
| {"task_id": "Mbpp/765", "solution": "def is_polite(n):\n \"\"\"\n Check if a number is polite or not.\n A polite number is a positive integer that can be written as the sum of two or more consecutive positive integers.\n \"\"\"\n if n == 1:\n return False\n for i in range(1, n):\n if (n - i) % i == 0:\n return True\n return False"} | |
| {"task_id": "Mbpp/766", "solution": "def pair_wise(lst):\n \"\"\"\n Returns a list of all pairs of consecutive items in a given list.\n\n Args:\n lst (list): The input list.\n\n Returns:\n list: A list of tuples, where each tuple contains a pair of consecutive items.\n\n Examples:\n >>> pair_wise([1,1,2,3,3,4,4,5])\n [(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]\n \"\"\"\n return [(lst[i], lst[i + 1]) for i in range(len(lst) - 1)]"} | |
| {"task_id": "Mbpp/767", "solution": "def get_pairs_count(arr, sum):\n count = 0\n for i in range(len(arr)):\n for j in range(i + 1, len(arr)):\n if arr[i] + arr[j] == sum:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/769", "solution": "def Diff(list1, list2):\n \"\"\"\n Returns the difference between two lists.\n\n Args:\n list1 (list): The first list.\n list2 (list): The second list.\n\n Returns:\n list: The difference between the two lists.\n \"\"\"\n return list(set(list1) - set(list2))"} | |
| {"task_id": "Mbpp/770", "solution": "def odd_num_sum(n):\n \"\"\"\n Calculate the sum of the fourth power of the first n odd natural numbers.\n\n Args:\n n (int): The number of initial odd natural numbers to consider.\n\n Returns:\n int: The sum of the fourth power of the first n odd natural numbers.\n\n Examples:\n >>> odd_num_sum(2)\n 82\n \"\"\"\n return sum((2 * i - 1) ** 4 for i in range(1, n + 1))"} | |
| {"task_id": "Mbpp/771", "solution": "def check_expression(expression):\n \"\"\"\n Check if the given expression is balanced or not.\n \"\"\"\n stack = []\n mapping = {\")\": \"(\", \"}\": \"{\", \"]\": \"[\"}\n for char in expression:\n if char in mapping.values():\n stack.append(char)\n elif char in mapping.keys():\n if not stack or mapping[char] != stack.pop():\n return False\n return not stack"} | |
| {"task_id": "Mbpp/772", "solution": "def remove_length(text, k):\n \"\"\"\n Write a function to remove all the words with k length in the given string.\n assert remove_length('The person is most value tet', 3) == 'person is most value'\n \"\"\"\n words = text.split()\n return ' '.join(word for word in words if len(word) != k)"} | |
| {"task_id": "Mbpp/773", "solution": "def find_substring_occurrence(main_string, substring):\n \"\"\"\n Finds the occurrence and position of the substring within the main string.\n Returns a tuple with the substring, start index, and end index if found, otherwise returns None.\n \n Example:\n >>> find_substring_occurrence('python programming, python language', 'python')\n ('python', 0, 6)\n \"\"\"\n index = main_string.find(substring)\n if index != -1:\n return substring, index, index + len(substring)\n else:\n return None\n\n# Check function to verify the correctness of the solution\ndef check_solution():\n assert find_substring_occurrence('python programming, python language', 'python') == ('python', 0, 6)\n assert find_substring_occurrence('python programming, python language', 'java') == None\n assert find_substring_occurrence('python programming, python language', 'programming') == ('programming', 11, 22)\n assert find_substring_occurrence('python programming, python language', 'language') == ('language', 23, 32)\n assert find_substring_occurrence('python programming, python language', 'java') == None\n print(\"All tests passed!\")\n\n# Run the check function\ncheck_solution()"} | |
| {"task_id": "Mbpp/775", "solution": "def odd_position(lst):\n \"\"\"\n Check if every odd index contains odd numbers in the given list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n bool: True if every odd index contains odd numbers, False otherwise.\n \"\"\"\n for i in range(1, len(lst), 2):\n if lst[i] % 2 == 0:\n return False\n return True"} | |
| {"task_id": "Mbpp/777", "solution": "def find_sum(lst):\n \"\"\"\n Find the sum of non-repeated elements in a given list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n int: The sum of non-repeated elements in the list.\n \"\"\"\n # Create a dictionary to store the count of each element\n element_count = {}\n for element in lst:\n if element in element_count:\n element_count[element] += 1\n else:\n element_count[element] = 1\n\n # Calculate the sum of non-repeated elements\n non_repeated_sum = 0\n for element, count in element_count.items():\n if count == 1:\n non_repeated_sum += element\n\n return non_repeated_sum"} | |
| {"task_id": "Mbpp/778", "solution": "def pack_consecutive_duplicates(lst):\n if not lst:\n return []\n \n packed_list = [[lst[0]]]\n for item in lst[1:]:\n if item == packed_list[-1][0]:\n packed_list[-1].append(item)\n else:\n packed_list.append([item])\n return packed_list"} | |
| {"task_id": "Mbpp/780", "solution": "from itertools import combinations\ndef find_combinations(tuples_list):\n \"\"\"\n Find all possible combinations of sums from the given list of tuples.\n\n Args:\n tuples_list (list): A list of tuples containing integer pairs.\n\n Returns:\n list: A list of tuples representing the sums of all possible combinations.\n \"\"\"\n result = []\n for r in range(1, len(tuples_list) + 1):\n for combo in combinations(tuples_list, r):\n sums = [sum(pair) for pair in zip(*combo)]\n result.append(tuple(sums))\n return result"} | |
| {"task_id": "Mbpp/781", "solution": "def count_divisors(n):\n \"\"\"\n Returns the count of divisors of a given number n.\n \n Args:\n n (int): The number to find the divisors for.\n \n Returns:\n int: The count of divisors of n.\n \"\"\"\n count = 0\n for i in range(1, int(n**0.5) + 1):\n if n % i == 0:\n count += 1\n if i != n // i:\n count += 1\n return count"} | |
| {"task_id": "Mbpp/782", "solution": "def odd_length_sum(arr):\n \"\"\"\n Calculate the sum of all odd length subarrays of the given array.\n\n Parameters:\n arr (list): A list of integers.\n\n Returns:\n int: The sum of all odd length subarrays.\n \"\"\"\n total_sum = 0\n n = len(arr)\n for i in range(n):\n for j in range(i, n, 2):\n total_sum += sum(arr[i:j+1])\n return total_sum"} | |
| {"task_id": "Mbpp/784", "solution": "def mul_even_odd(lst):\n \"\"\"\n Find the product of the first even and odd numbers in a given list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n int: The product of the first even and odd numbers in the list.\n \"\"\"\n even = None\n odd = None\n\n for num in lst:\n if num % 2 == 0 and even is None:\n even = num\n elif num % 2 != 0 and odd is None:\n odd = num\n if even is not None and odd is not None:\n break\n\n if even is None or odd is None:\n return 0\n else:\n return even * odd"} | |
| {"task_id": "Mbpp/785", "solution": "def tuple_str_int(tuple_str):\n \"\"\"\n Convert a tuple string to an integer tuple.\n\n Parameters:\n tuple_str (str): A string representation of a tuple.\n\n Returns:\n tuple: An integer tuple.\n \"\"\"\n # Remove parentheses and split the string by comma\n tuple_str = tuple_str.strip(\"()\")\n tuple_list = tuple_str.split(\", \")\n\n # Convert each element to an integer and return as a tuple\n return tuple(map(int, tuple_list))"} | |
| {"task_id": "Mbpp/786", "solution": "def right_insertion(sorted_list, value):\n \"\"\"\n Locate the right insertion point for a specified value in sorted order.\n\n Parameters:\n sorted_list (list): A sorted list of numbers.\n value (int): The value to insert into the list.\n\n Returns:\n int: The index at which the value should be inserted.\n\n Examples:\n >>> right_insertion([1,2,4,5], 6)\n 4\n >>> right_insertion([1,2,2,2,4,5], 2)\n 4\n \"\"\"\n left, right = 0, len(sorted_list)\n while left < right:\n mid = (left + right) // 2\n if sorted_list[mid] < value:\n left = mid + 1\n else:\n right = mid\n return left"} | |
| {"task_id": "Mbpp/787", "solution": "import re\ndef text_match_three(text):\n \"\"\"\n Matches a string that has an 'a' followed by exactly three 'b's.\n \n Args:\n text (str): The string to be matched against the pattern.\n \n Returns:\n bool: True if the string matches the pattern, False otherwise.\n \"\"\"\n pattern = 'ab{3}'\n return bool(re.search(pattern, text))"} | |
| {"task_id": "Mbpp/788", "solution": "def new_tuple(lst, s):\n \"\"\"\n Create a new tuple from the given string and list.\n Args:\n lst: A list of strings.\n s: A string.\n Returns:\n A tuple containing the elements of the list followed by the string.\n \"\"\"\n return tuple(lst + [s])"} | |
| {"task_id": "Mbpp/790", "solution": "def even_position(lst):\n \"\"\"\n Check if every even index contains even numbers in the given list.\n\n Args:\n lst (list): A list of integers.\n\n Returns:\n bool: True if every even index contains even numbers, False otherwise.\n \"\"\"\n for i in range(0, len(lst), 2):\n if lst[i] % 2 != 0:\n return False\n return True"} | |
| {"task_id": "Mbpp/791", "solution": "def remove_nested(tup):\n \"\"\"\n Write a function to remove tuples from the given tuple.\n assert remove_nested((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10)\n \"\"\"\n return tuple(item for item in tup if not isinstance(item, tuple))"} | |
| {"task_id": "Mbpp/792", "solution": "def count_list(lists):\n return len(lists)"} | |
| {"task_id": "Mbpp/793", "solution": "def last(arr, target):\n \"\"\"\n Find the last position of an element in a sorted array.\n\n Parameters:\n arr (list): The sorted array to search in.\n target: The element to find the last position of.\n\n Returns:\n int: The last position of the element in the array, or -1 if not found.\n \"\"\"\n left, right = 0, len(arr) - 1\n result = -1\n\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n result = mid\n left = mid + 1\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n\n return result"} | |
| {"task_id": "Mbpp/794", "solution": "import re\ndef text_starta_endb(s):\n \"\"\"\n Match a string that has an 'a' followed by anything, ending in 'b'.\n \n Args:\n s (str): The input string to be matched.\n \n Returns:\n bool: True if the string matches the pattern, False otherwise.\n \"\"\"\n pattern = r'a.*b$'\n return bool(re.match(pattern, s))"} | |
| {"task_id": "Mbpp/796", "solution": "def return_sum(dictionary):\n \"\"\"\n Returns the sum of all items in the given dictionary.\n\n Args:\n dictionary (dict): A dictionary containing numeric values.\n\n Returns:\n int: The sum of all values in the dictionary.\n \"\"\"\n return sum(dictionary.values())"} | |
| {"task_id": "Mbpp/797", "solution": "def sum_in_range(l, r):\n \"\"\"\n Calculate the sum of all odd natural numbers within the range l and r.\n\n Args:\n l (int): The lower limit of the range.\n r (int): The upper limit of the range.\n\n Returns:\n int: The sum of all odd natural numbers within the range.\n\n Examples:\n >>> sum_in_range(2, 5)\n 8\n \"\"\"\n return sum(num for num in range(l, r + 1) if num % 2 != 0)"} | |
| {"task_id": "Mbpp/798", "solution": "def _sum(arr):\n \"\"\"\n Calculate the sum of elements in an array.\n\n Parameters:\n arr (list): A list of numbers.\n\n Returns:\n int: The sum of the elements in the array.\n \"\"\"\n return sum(arr)"} | |
| {"task_id": "Mbpp/799", "solution": "def left_rotate(number, d):\n \"\"\"\n Rotate left bits by d bits a given number. We assume that the number is 32 bit.\n\n Args:\n number (int): The number to rotate.\n d (int): The number of bits to rotate.\n\n Returns:\n int: The result of the left rotation.\n \"\"\"\n d = d % 32 # Ensure d is within the range of 32 bits\n return (number << d) | (number >> (32 - d))"} | |
| {"task_id": "Mbpp/800", "solution": "def remove_all_spaces(input_string):\n \"\"\"\n Removes all whitespaces from the input string.\n\n Parameters:\n input_string (str): The string from which to remove whitespaces.\n\n Returns:\n str: The string with all whitespaces removed.\n \"\"\"\n return input_string.replace(\" \", \"\")"} | |
| {"task_id": "Mbpp/801", "solution": "def count_equal_numbers(a, b, c):\n \"\"\"\n Count the number of equal numbers from three given integers.\n\n Args:\n a (int): The first integer.\n b (int): The second integer.\n c (int): The third integer.\n\n Returns:\n int: The count of equal numbers among the three integers.\n \"\"\"\n if a == b == c:\n return 3\n elif a == b or a == c or b == c:\n return 2\n else:\n return 0\n\n# Test cases\nassert count_equal_numbers(1, 1, 1) == 3\nassert count_equal_numbers(1, 2, 2) == 2\nassert count_equal_numbers(-1, -2, -3) == 0\nassert count_equal_numbers(-1, -1, -1) == 3\nassert count_equal_numbers(0, 0, 0) == 3\nassert count_equal_numbers(10, 10, 20) == 2\nassert count_equal_numbers(10, 20, 30) == 0"} | |
| {"task_id": "Mbpp/803", "solution": "import math\ndef is_perfect_square(number):\n \"\"\"\n Check if the given number is a perfect square or not.\n\n Args:\n number (int): The number to check.\n\n Returns:\n bool: True if the number is a perfect square, False otherwise.\n \"\"\"\n if number < 0:\n return False\n root = math.isqrt(number)\n return number == root * root"} | |
| {"task_id": "Mbpp/804", "solution": "def is_product_even(numbers):\n \"\"\"\n Check if the product of numbers in a list is even.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n bool: True if the product is even, False otherwise.\n \"\"\"\n product = 1\n for num in numbers:\n product *= num\n return product % 2 == 0"} | |
| {"task_id": "Mbpp/805", "solution": "def max_sum_list(list_of_lists):\n \"\"\"\n Returns the list in a list of lists whose sum of elements is the highest.\n\n Parameters:\n list_of_lists (list): A list of lists of integers.\n\n Returns:\n list: The list with the highest sum of elements.\n \"\"\"\n return max(list_of_lists, key=sum)"} | |
| {"task_id": "Mbpp/806", "solution": "def max_run_uppercase(s):\n max_count = 0\n current_count = 0\n for char in s:\n if char.isupper():\n current_count += 1\n max_count = max(max_count, current_count)\n else:\n current_count = 0\n return max_count"} | |
| {"task_id": "Mbpp/807", "solution": "def first_odd(numbers):\n \"\"\"\n Find the first odd number in a given list of numbers.\n\n Args:\n numbers (list): A list of integers.\n\n Returns:\n int: The first odd number in the list.\n\n Examples:\n >>> first_odd([1, 2, 3, 4, 5])\n 1\n >>> first_odd([2, 4, 6, 8])\n 2\n >>> first_odd([1, 3, 5])\n 1\n \"\"\"\n for num in numbers:\n if num % 2 != 0:\n return num\n return None # In case there are no odd numbers in the list"} | |
| {"task_id": "Mbpp/808", "solution": "def check_K(tuples, k):\n \"\"\"\n Check if the given tuples contain the k or not.\n\n Parameters:\n tuples (tuple): A tuple of tuples.\n k (int): The value to check for.\n\n Returns:\n bool: True if k is found in any of the tuples, False otherwise.\n \"\"\"\n return any(k in t for t in tuples)"} | |
| {"task_id": "Mbpp/809", "solution": "def check_smaller(t1, t2):\n \"\"\"\n Check if each element of the second tuple is smaller than its corresponding element in the first tuple.\n\n Args:\n t1 (tuple): The first tuple.\n t2 (tuple): The second tuple.\n\n Returns:\n bool: True if each element of t2 is smaller than its corresponding element in t1, False otherwise.\n \"\"\"\n return all(x > y for x, y in zip(t1, t2))"} | |