mbpp / mbpp_valid.jsonl
jash404's picture
Upload mbpp_valid.jsonl with huggingface_hub
e46a839 verified
{"task_id": 511, "text": "Write a python function to find minimum sum of factors of a given number.", "code": "def find_Min_Sum(num): \r\n sum = 0\r\n i = 2\r\n while(i * i <= num): \r\n while(num % i == 0): \r\n sum += i \r\n num /= i \r\n i += 1\r\n sum += num \r\n return sum", "test_list": ["assert find_Min_Sum(12) == 7", "assert find_Min_Sum(105) == 15", "assert find_Min_Sum(2) == 2"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 512, "text": "Write a function to count the element frequency in the mixed nested tuple.", "code": "def flatten(test_tuple): \r\n\tfor tup in test_tuple: \r\n\t\tif isinstance(tup, tuple): \r\n\t\t\tyield from flatten(tup) \r\n\t\telse: \r\n\t\t\tyield tup \r\ndef count_element_freq(test_tuple):\r\n res = {}\r\n for ele in flatten(test_tuple):\r\n if ele not in res:\r\n res[ele] = 0\r\n res[ele] += 1\r\n return (res) ", "test_list": ["assert count_element_freq((5, 6, (5, 6), 7, (8, 9), 9) ) == {5: 2, 6: 2, 7: 1, 8: 1, 9: 2}", "assert count_element_freq((6, 7, (6, 7), 8, (9, 10), 10) ) == {6: 2, 7: 2, 8: 1, 9: 1, 10: 2}", "assert count_element_freq((7, 8, (7, 8), 9, (10, 11), 11) ) == {7: 2, 8: 2, 9: 1, 10: 1, 11: 2}"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 513, "text": "Write a function to convert tuple into list by adding the given string after every element.", "code": "def add_str(test_tup, K):\r\n res = [ele for sub in test_tup for ele in (sub, K)]\r\n return (res) ", "test_list": ["assert add_str((5, 6, 7, 4, 9) , \"FDF\") == [5, 'FDF', 6, 'FDF', 7, 'FDF', 4, 'FDF', 9, 'FDF']", "assert add_str((7, 8, 9, 10) , \"PF\") == [7, 'PF', 8, 'PF', 9, 'PF', 10, 'PF']", "assert add_str((11, 14, 12, 1, 4) , \"JH\") == [11, 'JH', 14, 'JH', 12, 'JH', 1, 'JH', 4, 'JH']"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 514, "text": "Write a function to find the summation of tuple elements in the given tuple list.", "code": "def sum_elements(test_tup):\r\n res = sum(list(test_tup))\r\n return (res) ", "test_list": ["assert sum_elements((7, 8, 9, 1, 10, 7)) == 42", "assert sum_elements((1, 2, 3, 4, 5, 6)) == 21", "assert sum_elements((11, 12 ,13 ,45, 14)) == 95"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 515, "text": "Write a function to check if there is a subset with sum divisible by m.", "code": "def modular_sum(arr, n, m): \r\n\tif (n > m): \r\n\t\treturn True\r\n\tDP = [False for i in range(m)] \r\n\tfor i in range(n): \r\n\t\tif (DP[0]): \r\n\t\t\treturn True\r\n\t\ttemp = [False for i in range(m)] \r\n\t\tfor j in range(m): \r\n\t\t\tif (DP[j] == True): \r\n\t\t\t\tif (DP[(j + arr[i]) % m] == False): \r\n\t\t\t\t\ttemp[(j + arr[i]) % m] = True\r\n\t\tfor j in range(m): \r\n\t\t\tif (temp[j]): \r\n\t\t\t\tDP[j] = True\r\n\t\tDP[arr[i] % m] = True\r\n\treturn DP[0]", "test_list": ["assert modular_sum([3, 1, 7, 5], 4, 6) == True", "assert modular_sum([1, 7], 2, 5) == False", "assert modular_sum([1, 6], 2, 5) == False"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 516, "text": "Write a function to sort a list of elements using radix sort.", "code": "def radix_sort(nums):\r\n RADIX = 10\r\n placement = 1\r\n max_digit = max(nums)\r\n\r\n while placement < max_digit:\r\n buckets = [list() for _ in range( RADIX )]\r\n for i in nums:\r\n tmp = int((i / placement) % RADIX)\r\n buckets[tmp].append(i)\r\n a = 0\r\n for b in range( RADIX ):\r\n buck = buckets[b]\r\n for i in buck:\r\n nums[a] = i\r\n a += 1\r\n placement *= RADIX\r\n return nums", "test_list": ["assert radix_sort([15, 79, 25, 68, 37]) == [15, 25, 37, 68, 79]", "assert radix_sort([9, 11, 8, 7, 3, 2]) == [2, 3, 7, 8, 9, 11]", "assert radix_sort([36, 12, 24, 26, 29]) == [12, 24, 26, 29, 36]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 517, "text": "Write a python function to find the largest postive number from the given list.", "code": "def largest_pos(list1): \r\n max = list1[0] \r\n for x in list1: \r\n if x > max : \r\n max = x \r\n return max", "test_list": ["assert largest_pos([1,2,3,4,-1]) == 4", "assert largest_pos([0,1,2,-5,-1,6]) == 6", "assert largest_pos([0,0,1,0]) == 1"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 518, "text": "Write a function to find the square root of a perfect number.", "code": "import math\r\ndef sqrt_root(num):\r\n sqrt_root = math.pow(num, 0.5)\r\n return sqrt_root ", "test_list": ["assert sqrt_root(4)==2", "assert sqrt_root(16)==4", "assert sqrt_root(400)==20"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 519, "text": "Write a function to calculate volume of a tetrahedron.", "code": "import math\r\ndef volume_tetrahedron(num):\r\n\tvolume = (num ** 3 / (6 * math.sqrt(2)))\t\r\n\treturn round(volume, 2)", "test_list": ["assert volume_tetrahedron(10)==117.85", "assert volume_tetrahedron(15)==397.75", "assert volume_tetrahedron(20)==942.81"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 520, "text": "Write a function to find the lcm of the given array elements.", "code": "def find_lcm(num1, num2): \r\n\tif(num1>num2): \r\n\t\tnum = num1 \r\n\t\tden = num2 \r\n\telse: \r\n\t\tnum = num2 \r\n\t\tden = num1 \r\n\trem = num % den \r\n\twhile (rem != 0): \r\n\t\tnum = den \r\n\t\tden = rem \r\n\t\trem = num % den \r\n\tgcd = den \r\n\tlcm = int(int(num1 * num2)/int(gcd)) \r\n\treturn lcm \r\ndef get_lcm(l):\r\n num1 = l[0]\r\n num2 = l[1]\r\n lcm = find_lcm(num1, num2)\r\n for i in range(2, len(l)):\r\n lcm = find_lcm(lcm, l[i])\r\n return lcm ", "test_list": ["assert get_lcm([2, 7, 3, 9, 4]) == 252", "assert get_lcm([1, 2, 8, 3]) == 24", "assert get_lcm([3, 8, 4, 10, 5]) == 120"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 521, "text": "Write a function to print check if the triangle is scalene or not.", "code": "def check_isosceles(x,y,z):\r\n if x!=y & y!=z & z!=x:\r\n\t return True\r\n else:\r\n return False", "test_list": ["assert check_isosceles(6,8,12)==True", "assert check_isosceles(6,6,12)==False", "assert check_isosceles(6,15,20)==True"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 522, "text": "Write a function to find the longest bitonic subsequence for the given array.", "code": "def lbs(arr): \r\n\tn = len(arr) \r\n\tlis = [1 for i in range(n+1)] \r\n\tfor i in range(1 , n): \r\n\t\tfor j in range(0 , i): \r\n\t\t\tif ((arr[i] > arr[j]) and (lis[i] < lis[j] +1)): \r\n\t\t\t\tlis[i] = lis[j] + 1\r\n\tlds = [1 for i in range(n+1)] \r\n\tfor i in reversed(range(n-1)): \r\n\t\tfor j in reversed(range(i-1 ,n)): \r\n\t\t\tif(arr[i] > arr[j] and lds[i] < lds[j] + 1): \r\n\t\t\t\tlds[i] = lds[j] + 1\r\n\tmaximum = lis[0] + lds[0] - 1\r\n\tfor i in range(1 , n): \r\n\t\tmaximum = max((lis[i] + lds[i]-1), maximum) \r\n\treturn maximum", "test_list": ["assert lbs([0 , 8 , 4, 12, 2, 10 , 6 , 14 , 1 , 9 , 5 , 13, 3, 11 , 7 , 15]) == 7", "assert lbs([1, 11, 2, 10, 4, 5, 2, 1]) == 6", "assert lbs([80, 60, 30, 40, 20, 10]) == 5"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 523, "text": "Write a function to check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda function.", "code": "def check_string(str1):\r\n messg = [\r\n lambda str1: any(x.isupper() for x in str1) or 'String must have 1 upper case character.',\r\n lambda str1: any(x.islower() for x in str1) or 'String must have 1 lower case character.',\r\n lambda str1: any(x.isdigit() for x in str1) or 'String must have 1 number.',\r\n lambda str1: len(str1) >= 7 or 'String length should be atleast 8.',]\r\n result = [x for x in [i(str1) for i in messg] if x != True]\r\n if not result:\r\n result.append('Valid string.')\r\n return result ", "test_list": ["assert check_string('python')==['String must have 1 upper case character.', 'String must have 1 number.', 'String length should be atleast 8.']", "assert check_string('123python')==['String must have 1 upper case character.']", "assert check_string('123Python')==['Valid string.']"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 524, "text": "Write a function to find the sum of maximum increasing subsequence of the given array.", "code": "def max_sum_increasing_subsequence(arr, n): \r\n\tmax = 0\r\n\tmsis = [0 for x in range(n)] \r\n\tfor i in range(n): \r\n\t\tmsis[i] = arr[i] \r\n\tfor i in range(1, n): \r\n\t\tfor j in range(i): \r\n\t\t\tif (arr[i] > arr[j] and\r\n\t\t\t\tmsis[i] < msis[j] + arr[i]): \r\n\t\t\t\tmsis[i] = msis[j] + arr[i] \r\n\tfor i in range(n): \r\n\t\tif max < msis[i]: \r\n\t\t\tmax = msis[i] \r\n\treturn max", "test_list": ["assert max_sum_increasing_subsequence([1, 101, 2, 3, 100, 4, 5], 7) == 106", "assert max_sum_increasing_subsequence([3, 4, 5, 10], 4) == 22", "assert max_sum_increasing_subsequence([10, 5, 4, 3], 4) == 10"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 525, "text": "Write a python function to check whether two given lines are parallel or not.", "code": "def parallel_lines(line1, line2):\r\n return line1[0]/line1[1] == line2[0]/line2[1]", "test_list": ["assert parallel_lines([2,3,4], [2,3,8]) == True", "assert parallel_lines([2,3,4], [4,-3,8]) == False", "assert parallel_lines([3,3],[5,5]) == True"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 526, "text": "Write a python function to capitalize first and last letters of each word of a given string.", "code": "def capitalize_first_last_letters(str1):\r\n str1 = result = str1.title()\r\n result = \"\"\r\n for word in str1.split():\r\n result += word[:-1] + word[-1].upper() + \" \"\r\n return result[:-1] ", "test_list": ["assert capitalize_first_last_letters(\"python\") == \"PythoN\"", "assert capitalize_first_last_letters(\"bigdata\") == \"BigdatA\"", "assert capitalize_first_last_letters(\"Hadoop\") == \"HadooP\""], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 527, "text": "Write a function to find all pairs in an integer array whose sum is equal to a given number.", "code": "def get_pairs_count(arr, n, sum):\r\n count = 0 \r\n for i in range(0, n):\r\n for j in range(i + 1, n):\r\n if arr[i] + arr[j] == sum:\r\n count += 1\r\n return count", "test_list": ["assert get_pairs_count([1, 5, 7, -1, 5], 5, 6) == 3", "assert get_pairs_count([1, 5, 7, -1], 4, 6) == 2", "assert get_pairs_count([1, 1, 1, 1], 4, 2) == 6"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 528, "text": "Write a function to find the list of lists with minimum length.", "code": "def min_length(list1):\r\n min_length = min(len(x) for x in list1 ) \r\n min_list = min((x) for x in list1)\r\n return(min_length, min_list) ", "test_list": ["assert min_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0])", "assert min_length([[1], [5, 7], [10, 12, 14,15]])==(1, [1])", "assert min_length([[5], [15,20,25]])==(1, [5])"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 529, "text": "Write a function to find the nth jacobsthal-lucas number.", "code": "def jacobsthal_lucas(n): \r\n\tdp=[0] * (n + 1) \r\n\tdp[0] = 2\r\n\tdp[1] = 1\r\n\tfor i in range(2, n+1): \r\n\t\tdp[i] = dp[i - 1] + 2 * dp[i - 2]; \r\n\treturn dp[n]", "test_list": ["assert jacobsthal_lucas(5) == 31", "assert jacobsthal_lucas(2) == 5", "assert jacobsthal_lucas(4) == 17"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 530, "text": "Write a function to find the ration of negative numbers in an array of integers.", "code": "from array import array\r\ndef negative_count(nums):\r\n n = len(nums)\r\n n1 = 0\r\n for x in nums:\r\n if x < 0:\r\n n1 += 1\r\n else:\r\n None\r\n return round(n1/n,2)", "test_list": ["assert negative_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.31", "assert negative_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.31", "assert negative_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.44"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 531, "text": "Write a function to find minimum number of coins that make a given value.", "code": "import sys \r\ndef min_coins(coins, m, V): \r\n if (V == 0): \r\n return 0\r\n res = sys.maxsize \r\n for i in range(0, m): \r\n if (coins[i] <= V): \r\n sub_res = min_coins(coins, m, V-coins[i]) \r\n if (sub_res != sys.maxsize and sub_res + 1 < res): \r\n res = sub_res + 1 \r\n return res ", "test_list": ["assert min_coins([9, 6, 5, 1] ,4,11)==2", "assert min_coins([4,5,6,7,8,9],6,9)==1", "assert min_coins([1, 2, 3],3,4)==2"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 532, "text": "Write a function to check if the two given strings are permutations of each other.", "code": "def check_permutation(str1, str2):\r\n n1=len(str1)\r\n n2=len(str2)\r\n if(n1!=n2):\r\n return False\r\n a=sorted(str1)\r\n str1=\" \".join(a)\r\n b=sorted(str2)\r\n str2=\" \".join(b)\r\n for i in range(0, n1, 1):\r\n if(str1[i] != str2[i]):\r\n return False\r\n return True", "test_list": ["assert check_permutation(\"abc\", \"cba\") == True", "assert check_permutation(\"test\", \"ttew\") == False", "assert check_permutation(\"xxyz\", \"yxzx\") == True"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 533, "text": "Write a function to remove particular data type elements from the given tuple.", "code": "def remove_datatype(test_tuple, data_type):\r\n res = []\r\n for ele in test_tuple:\r\n if not isinstance(ele, data_type):\r\n res.append(ele)\r\n return (res) ", "test_list": ["assert remove_datatype((4, 5, 4, 7.7, 1.2), int) == [7.7, 1.2]", "assert remove_datatype((7, 8, 9, \"SR\"), str) == [7, 8, 9]", "assert remove_datatype((7, 1.1, 2, 2.2), float) == [7, 2]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 534, "text": "Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs.", "code": "import re\r\ndef search_literal(pattern,text):\r\n match = re.search(pattern, text)\r\n s = match.start()\r\n e = match.end()\r\n return (s, e)", "test_list": ["assert search_literal('python','python programming language')==(0,6)", "assert search_literal('programming','python programming language')==(7,18)", "assert search_literal('language','python programming language')==(19,27)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 535, "text": "Write a function to find the top or bottom surface area of a cylinder.", "code": "def topbottom_surfacearea(r):\r\n toporbottomarea=3.1415*r*r\r\n return toporbottomarea", "test_list": ["assert topbottom_surfacearea(10)==314.15000000000003", "assert topbottom_surfacearea(5)==78.53750000000001", "assert topbottom_surfacearea(4)==50.264"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 536, "text": "Write a function to select the nth items of a list.", "code": "def nth_items(list,n):\r\n return list[::n]", "test_list": ["assert nth_items([1, 2, 3, 4, 5, 6, 7, 8, 9],2)==[1, 3, 5, 7, 9] ", "assert nth_items([10,15,19,17,16,18],3)==[10,17] ", "assert nth_items([14,16,19,15,17],4)==[14,17]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 537, "text": "Write a python function to find the first repeated word in a given string.", "code": "def first_repeated_word(str1):\r\n temp = set()\r\n for word in str1.split():\r\n if word in temp:\r\n return word;\r\n else:\r\n temp.add(word)\r\n return 'None'", "test_list": ["assert first_repeated_word(\"ab ca bc ab\") == \"ab\"", "assert first_repeated_word(\"ab ca bc\") == 'None'", "assert first_repeated_word(\"ab ca bc ca ab bc\") == \"ca\""], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 538, "text": "Write a python function to convert a given string list to a tuple.", "code": "def string_list_to_tuple(str1):\r\n result = tuple(x for x in str1 if not x.isspace()) \r\n return result", "test_list": ["assert string_list_to_tuple((\"python 3.0\")) == ('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')", "assert string_list_to_tuple((\"bigdata\")) == ('b', 'i', 'g', 'd', 'a', 't', 'a')", "assert string_list_to_tuple((\"language\")) == ('l', 'a', 'n', 'g', 'u', 'a', 'g','e')"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 539, "text": "Write a function to create a list containing the power of said number in bases raised to the corresponding number in the index using map function.", "code": "def basesnum_coresspondingnum(bases_num,index):\r\n result = list(map(pow, bases_num, index))\r\n return result", "test_list": ["assert basesnum_coresspondingnum([10, 20, 30, 40, 50, 60, 70, 80, 90, 100],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[10, 400, 27000, 2560000, 312500000, 46656000000, 8235430000000, 1677721600000000, 387420489000000000, 100000000000000000000]", "assert basesnum_coresspondingnum([1, 2, 3, 4, 5, 6, 7],[10, 20, 30, 40, 50, 60, 70])==[1, 1048576, 205891132094649, 1208925819614629174706176, 88817841970012523233890533447265625, 48873677980689257489322752273774603865660850176, 143503601609868434285603076356671071740077383739246066639249]", "assert basesnum_coresspondingnum([4, 8, 12, 16, 20, 24, 28],[3, 6, 9, 12, 15, 18, 21])==[64, 262144, 5159780352, 281474976710656, 32768000000000000000, 6979147079584381377970176, 2456510688823056210273111113728]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 540, "text": "Write a python function to find the difference between highest and least frequencies in a given array.", "code": "def find_Diff(arr,n): \r\n arr.sort() \r\n count = 0; max_count = 0; min_count = n \r\n for i in range(0,(n-1)): \r\n if arr[i] == arr[i + 1]: \r\n count += 1\r\n continue\r\n else: \r\n max_count = max(max_count,count) \r\n min_count = min(min_count,count) \r\n count = 0\r\n return max_count - min_count ", "test_list": ["assert find_Diff([1,1,2,2,7,8,4,5,1,4],10) == 2", "assert find_Diff([1,7,9,2,3,3,1,3,3],9) == 3", "assert find_Diff([1,2,1,2],4) == 0"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 541, "text": "Write a function to find if the given number is abundant or not.", "code": "import math \r\ndef get_sum(n): \r\n\tsum = 0\r\n\ti = 1\r\n\twhile i <= (math.sqrt(n)): \r\n\t\tif n%i == 0: \r\n\t\t\tif n/i == i : \r\n\t\t\t\tsum = sum + i \r\n\t\t\telse: \r\n\t\t\t\tsum = sum + i \r\n\t\t\t\tsum = sum + (n / i ) \r\n\t\ti = i + 1\r\n\tsum = sum - n \r\n\treturn sum\r\ndef check_abundant(n): \r\n\tif (get_sum(n) > n): \r\n\t\treturn True\r\n\telse: \r\n\t\treturn False", "test_list": ["assert check_abundant(12) == True", "assert check_abundant(15) == False", "assert check_abundant(18) == True"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 542, "text": "Write a function to replace all occurrences of spaces, commas, or dots with a colon in the given string by using regex.", "code": "import re\r\ndef fill_spaces(text):\r\n return (re.sub(\"[ ,.]\", \":\", text))", "test_list": ["assert fill_spaces('Boult Curve Wireless Neckband') == 'Boult:Curve:Wireless:Neckband'", "assert fill_spaces('Stereo Sound Sweatproof') == 'Stereo:Sound:Sweatproof'", "assert fill_spaces('Probass Curve Audio') == 'Probass:Curve:Audio'"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 543, "text": "Write a function to add two numbers and print number of digits of sum.", "code": "def count_digits(num1,num2):\r\n number=num1+num2\r\n count = 0\r\n while(number > 0):\r\n number = number // 10\r\n count = count + 1\r\n return count", "test_list": ["assert count_digits(9875,10)==(4)", "assert count_digits(98759853034,100)==(11)", "assert count_digits(1234567,500)==(7)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 544, "text": "Write a function to flatten the tuple list to a string.", "code": "def flatten_tuple(test_list):\r\n res = ' '.join([idx for tup in test_list for idx in tup])\r\n return (res) ", "test_list": ["assert flatten_tuple([('1', '4', '6'), ('5', '8'), ('2', '9'), ('1', '10')]) == '1 4 6 5 8 2 9 1 10'", "assert flatten_tuple([('2', '3', '4'), ('6', '9'), ('3', '2'), ('2', '11')]) == '2 3 4 6 9 3 2 2 11'", "assert flatten_tuple([('14', '21', '9'), ('24', '19'), ('12', '29'), ('23', '17')]) == '14 21 9 24 19 12 29 23 17'"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 545, "text": "Write a python function to toggle only first and last bits of a given number.", "code": "def take_L_and_F_set_bits(n) : \r\n n = n | n >> 1\r\n n = n | n >> 2\r\n n = n | n >> 4\r\n n = n | n >> 8\r\n n = n | n >> 16 \r\n return ((n + 1) >> 1) + 1 \r\ndef toggle_F_and_L_bits(n) : \r\n if (n == 1) : \r\n return 0 \r\n return n ^ take_L_and_F_set_bits(n) ", "test_list": ["assert toggle_F_and_L_bits(10) == 3", "assert toggle_F_and_L_bits(15) == 6", "assert toggle_F_and_L_bits(20) == 5"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 546, "text": "Write a function to find the last occurrence of a character in a string.", "code": "def last_occurence_char(string,char):\r\n flag = -1\r\n for i in range(len(string)):\r\n if(string[i] == char):\r\n flag = i\r\n if(flag == -1):\r\n return None\r\n else:\r\n return flag + 1", "test_list": ["assert last_occurence_char(\"hello world\",'l')==10", "assert last_occurence_char(\"language\",'g')==7", "assert last_occurence_char(\"little\",'y')==None"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 547, "text": "Write a python function to find the sum of hamming distances of all consecutive numbers from o to n.", "code": "def Total_Hamming_Distance(n): \r\n i = 1\r\n sum = 0\r\n while (n // i > 0): \r\n sum = sum + n // i \r\n i = i * 2 \r\n return sum", "test_list": ["assert Total_Hamming_Distance(4) == 7", "assert Total_Hamming_Distance(2) == 3", "assert Total_Hamming_Distance(5) == 8"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 548, "text": "Write a function to find the length of the longest increasing subsequence of the given sequence.", "code": "def longest_increasing_subsequence(arr): \r\n\tn = len(arr) \r\n\tlongest_increasing_subsequence = [1]*n \r\n\tfor i in range (1 , n): \r\n\t\tfor j in range(0 , i): \r\n\t\t\tif arr[i] > arr[j] and longest_increasing_subsequence[i]< longest_increasing_subsequence[j] + 1 : \r\n\t\t\t\tlongest_increasing_subsequence[i] = longest_increasing_subsequence[j]+1\r\n\tmaximum = 0\r\n\tfor i in range(n): \r\n\t\tmaximum = max(maximum , longest_increasing_subsequence[i]) \r\n\treturn maximum", "test_list": ["assert longest_increasing_subsequence([10, 22, 9, 33, 21, 50, 41, 60]) == 5", "assert longest_increasing_subsequence([3, 10, 2, 1, 20]) == 3", "assert longest_increasing_subsequence([50, 3, 10, 7, 40, 80]) == 4 "], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 549, "text": "Write a python function to find the sum of fifth power of first n odd natural numbers.", "code": "def odd_Num_Sum(n) : \r\n j = 0\r\n sm = 0\r\n for i in range(1,n+1) : \r\n j = (2*i-1) \r\n sm = sm + (j*j*j*j*j) \r\n return sm ", "test_list": ["assert odd_Num_Sum(1) == 1", "assert odd_Num_Sum(2) == 244", "assert odd_Num_Sum(3) == 3369"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 550, "text": "Write a python function to find the maximum element in a sorted and rotated array.", "code": "def find_Max(arr,low,high): \r\n if (high < low): \r\n return arr[0] \r\n if (high == low): \r\n return arr[low] \r\n mid = low + (high - low) // 2 \r\n if (mid < high and arr[mid + 1] < arr[mid]): \r\n return arr[mid] \r\n if (mid > low and arr[mid] < arr[mid - 1]): \r\n return arr[mid - 1] \r\n if (arr[low] > arr[mid]): \r\n return find_Max(arr,low,mid - 1) \r\n else: \r\n return find_Max(arr,mid + 1,high) ", "test_list": ["assert find_Max([2,3,5,6,9],0,4) == 9", "assert find_Max([3,4,5,2,1],0,4) == 5", "assert find_Max([1,2,3],0,2) == 3"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 551, "text": "Write a function to extract a specified column from a given nested list.", "code": "def extract_column(list1, n):\r\n result = [i.pop(n) for i in list1]\r\n return result ", "test_list": ["assert extract_column([[1, 2, 3], [2, 4, 5], [1, 1, 1]],0)==[1, 2, 1]", "assert extract_column([[1, 2, 3], [-2, 4, -5], [1, -1, 1]],2)==[3, -5, 1]", "assert extract_column([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]],0)==[1, 5, 1, 13, 5, 9]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 552, "text": "Write a python function to check whether a given sequence is linear or not.", "code": "def Seq_Linear(seq_nums):\r\n seq_nums = [seq_nums[x] - seq_nums[x-1] for x in range(1, len(seq_nums))]\r\n if len(set(seq_nums)) == 1: \r\n return \"Linear Sequence\"\r\n else:\r\n return \"Non Linear Sequence\"", "test_list": ["assert Seq_Linear([0,2,4,6,8,10]) == \"Linear Sequence\"", "assert Seq_Linear([1,2,3]) == \"Linear Sequence\"", "assert Seq_Linear([1,5,2]) == \"Non Linear Sequence\""], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 553, "text": "Write a function to convert the given tuple to a floating-point number.", "code": "def tuple_to_float(test_tup):\r\n res = float('.'.join(str(ele) for ele in test_tup))\r\n return (res) ", "test_list": ["assert tuple_to_float((4, 56)) == 4.56", "assert tuple_to_float((7, 256)) == 7.256", "assert tuple_to_float((8, 123)) == 8.123"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 554, "text": "Write a python function to find odd numbers from a mixed list.", "code": "def Split(list): \r\n od_li = [] \r\n for i in list: \r\n if (i % 2 != 0): \r\n od_li.append(i) \r\n return od_li", "test_list": ["assert Split([1,2,3,4,5,6]) == [1,3,5]", "assert Split([10,11,12,13]) == [11,13]", "assert Split([7,8,9,1]) == [7,9,1]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 555, "text": "Write a python function to find the difference between sum of cubes of first n natural numbers and the sum of first n natural numbers.", "code": "def difference(n) : \r\n S = (n*(n + 1))//2; \r\n res = S*(S-1); \r\n return res; ", "test_list": ["assert difference(3) == 30", "assert difference(5) == 210", "assert difference(2) == 6"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 556, "text": "Write a python function to count the pairs with xor as an odd number.", "code": "def find_Odd_Pair(A,N) : \r\n oddPair = 0\r\n for i in range(0,N) : \r\n for j in range(i+1,N) : \r\n if ((A[i] ^ A[j]) % 2 != 0): \r\n oddPair+=1 \r\n return oddPair ", "test_list": ["assert find_Odd_Pair([5,4,7,2,1],5) == 6", "assert find_Odd_Pair([7,2,8,1,0,5,11],7) == 12", "assert find_Odd_Pair([1,2,3],3) == 2"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 557, "text": "Write a function to toggle characters case in a string.", "code": "def toggle_string(string):\r\n string1 = string.swapcase()\r\n return string1", "test_list": ["assert toggle_string(\"Python\")==(\"pYTHON\")", "assert toggle_string(\"Pangram\")==(\"pANGRAM\")", "assert toggle_string(\"LIttLE\")==(\"liTTle\")"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 558, "text": "Write a python function to find the digit distance between two integers.", "code": "def digit_distance_nums(n1, n2):\r\n return sum(map(int,str(abs(n1-n2))))", "test_list": ["assert digit_distance_nums(1,2) == 1", "assert digit_distance_nums(23,56) == 6", "assert digit_distance_nums(123,256) == 7"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 559, "text": "Write a function to find the largest sum of contiguous subarray in the given array.", "code": "def max_sub_array_sum(a, size):\r\n max_so_far = 0\r\n max_ending_here = 0\r\n for i in range(0, size):\r\n max_ending_here = max_ending_here + a[i]\r\n if max_ending_here < 0:\r\n max_ending_here = 0\r\n elif (max_so_far < max_ending_here):\r\n max_so_far = max_ending_here\r\n return max_so_far", "test_list": ["assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8) == 7", "assert max_sub_array_sum([-3, -4, 5, -2, -3, 2, 6, -4], 8) == 8", "assert max_sub_array_sum([-4, -5, 6, -3, -4, 3, 7, -5], 8) == 10"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 560, "text": "Write a function to find the union of elements of the given tuples.", "code": "def union_elements(test_tup1, test_tup2):\r\n res = tuple(set(test_tup1 + test_tup2))\r\n return (res) ", "test_list": ["assert union_elements((3, 4, 5, 6),(5, 7, 4, 10) ) == (3, 4, 5, 6, 7, 10)", "assert union_elements((1, 2, 3, 4),(3, 4, 5, 6) ) == (1, 2, 3, 4, 5, 6)", "assert union_elements((11, 12, 13, 14),(13, 15, 16, 17) ) == (11, 12, 13, 14, 15, 16, 17)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 561, "text": "Write a function to assign with each element, its pair elements from other similar pairs in the given tuple.", "code": "def assign_elements(test_list):\r\n res = dict()\r\n for key, val in test_list:\r\n res.setdefault(val, [])\r\n res.setdefault(key, []).append(val)\r\n return (res) ", "test_list": ["assert assign_elements([(5, 3), (7, 5), (2, 7), (3, 8), (8, 4)] ) == {3: [8], 5: [3], 7: [5], 2: [7], 8: [4], 4: []}", "assert assign_elements([(6, 4), (9, 4), (3, 8), (4, 9), (9, 5)] ) == {4: [9], 6: [4], 9: [4, 5], 8: [], 3: [8], 5: []}", "assert assign_elements([(6, 2), (6, 8), (4, 9), (4, 9), (3, 7)] ) == {2: [], 6: [2, 8], 8: [], 9: [], 4: [9, 9], 7: [], 3: [7]}"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 562, "text": "Write a python function to find the maximum length of sublist.", "code": "def Find_Max_Length(lst): \r\n maxLength = max(len(x) for x in lst )\r\n return maxLength ", "test_list": ["assert Find_Max_Length([[1],[1,4],[5,6,7,8]]) == 4", "assert Find_Max_Length([[0,1],[2,2,],[3,2,1]]) == 3", "assert Find_Max_Length([[7],[22,23],[13,14,15],[10,20,30,40,50]]) == 5"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 563, "text": "Write a function to extract values between quotation marks of a string.", "code": "import re\r\ndef extract_values(text):\r\n return (re.findall(r'\"(.*?)\"', text))", "test_list": ["assert extract_values('\"Python\", \"PHP\", \"Java\"')==['Python', 'PHP', 'Java']", "assert extract_values('\"python\",\"program\",\"language\"')==['python','program','language']", "assert extract_values('\"red\",\"blue\",\"green\",\"yellow\"')==['red','blue','green','yellow']"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 564, "text": "Write a python function to count unequal element pairs from the given array.", "code": "def count_Pairs(arr,n): \r\n cnt = 0; \r\n for i in range(n): \r\n for j in range(i + 1,n): \r\n if (arr[i] != arr[j]): \r\n cnt += 1; \r\n return cnt; ", "test_list": ["assert count_Pairs([1,2,1],3) == 2", "assert count_Pairs([1,1,1,1],4) == 0", "assert count_Pairs([1,2,3,4,5],5) == 10"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 565, "text": "Write a python function to split a string into characters.", "code": "def split(word): \r\n return [char for char in word] ", "test_list": ["assert split('python') == ['p','y','t','h','o','n']", "assert split('Name') == ['N','a','m','e']", "assert split('program') == ['p','r','o','g','r','a','m']"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 566, "text": "Write a function to get the sum of a non-negative integer.", "code": "def sum_digits(n):\r\n if n == 0:\r\n return 0\r\n else:\r\n return n % 10 + sum_digits(int(n / 10))", "test_list": ["assert sum_digits(345)==12", "assert sum_digits(12)==3", "assert sum_digits(97)==16"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 567, "text": "Write a function to check whether a specified list is sorted or not.", "code": "def issort_list(list1):\r\n result = all(list1[i] <= list1[i+1] for i in range(len(list1)-1))\r\n return result", "test_list": ["assert issort_list([1,2,4,6,8,10,12,14,16,17])==True", "assert issort_list([1, 2, 4, 6, 8, 10, 12, 14, 20, 17])==False", "assert issort_list([1, 2, 4, 6, 8, 10,15,14,20])==False"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 568, "text": "Write a function to create a list of empty dictionaries.", "code": "def empty_list(length):\r\n empty_list = [{} for _ in range(length)]\r\n return empty_list", "test_list": ["assert empty_list(5)==[{},{},{},{},{}]", "assert empty_list(6)==[{},{},{},{},{},{}]", "assert empty_list(7)==[{},{},{},{},{},{},{}]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 569, "text": "Write a function to sort each sublist of strings in a given list of lists.", "code": "def sort_sublists(list1):\r\n result = list(map(sorted,list1)) \r\n return result", "test_list": ["assert sort_sublists([['green', 'orange'], ['black', 'white'], ['white', 'black', 'orange']])==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]", "assert sort_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])==[['green', 'orange'], ['black'], ['green', 'orange'], ['white']]", "assert sort_sublists([['a','b'],['d','c'],['g','h'] , ['f','e']])==[['a', 'b'], ['c', 'd'], ['g', 'h'], ['e', 'f']]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 570, "text": "Write a function to remove words from a given list of strings containing a character or string.", "code": "def remove_words(list1, charlist):\r\n new_list = []\r\n for line in list1:\r\n new_words = ' '.join([word for word in line.split() if not any([phrase in word for phrase in charlist])])\r\n new_list.append(new_words)\r\n return new_list", "test_list": ["assert remove_words(['Red color', 'Orange#', 'Green', 'Orange @', \"White\"],['#', 'color', '@'])==['Red', '', 'Green', 'Orange', 'White']", "assert remove_words(['Red &', 'Orange+', 'Green', 'Orange @', 'White'],['&', '+', '@'])==['Red', '', 'Green', 'Orange', 'White']", "assert remove_words(['Red &', 'Orange+', 'Green', 'Orange @', 'White'],['@'])==['Red &', 'Orange+', 'Green', 'Orange', 'White']"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 571, "text": "Write a function to find maximum possible sum of disjoint pairs for the given array of integers and a number k.", "code": "def max_sum_pair_diff_lessthan_K(arr, N, K): \r\n\tarr.sort() \r\n\tdp = [0] * N \r\n\tdp[0] = 0\r\n\tfor i in range(1, N): \r\n\t\tdp[i] = dp[i-1] \r\n\t\tif (arr[i] - arr[i-1] < K): \r\n\t\t\tif (i >= 2): \r\n\t\t\t\tdp[i] = max(dp[i], dp[i-2] + arr[i] + arr[i-1]); \r\n\t\t\telse: \r\n\t\t\t\tdp[i] = max(dp[i], arr[i] + arr[i-1]); \r\n\treturn dp[N - 1]", "test_list": ["assert max_sum_pair_diff_lessthan_K([3, 5, 10, 15, 17, 12, 9], 7, 4) == 62", "assert max_sum_pair_diff_lessthan_K([5, 15, 10, 300], 4, 12) == 25", "assert max_sum_pair_diff_lessthan_K([1, 2, 3, 4, 5, 6], 6, 6) == 21"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 572, "text": "Write a python function to remove two duplicate numbers from a given number of lists.", "code": "def two_unique_nums(nums):\r\n return [i for i in nums if nums.count(i)==1]", "test_list": ["assert two_unique_nums([1,2,3,2,3,4,5]) == [1, 4, 5]", "assert two_unique_nums([1,2,3,2,4,5]) == [1, 3, 4, 5]", "assert two_unique_nums([1,2,3,4,5]) == [1, 2, 3, 4, 5]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 573, "text": "Write a python function to calculate the product of the unique numbers of a given list.", "code": "def unique_product(list_data):\r\n temp = list(set(list_data))\r\n p = 1\r\n for i in temp:\r\n p *= i\r\n return p", "test_list": ["assert unique_product([10, 20, 30, 40, 20, 50, 60, 40]) == 720000000", "assert unique_product([1, 2, 3, 1,]) == 6", "assert unique_product([7, 8, 9, 0, 1, 1]) == 0"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 574, "text": "Write a function to find the surface area of a cylinder.", "code": "def surfacearea_cylinder(r,h):\r\n surfacearea=((2*3.1415*r*r) +(2*3.1415*r*h))\r\n return surfacearea", "test_list": ["assert surfacearea_cylinder(10,5)==942.45", "assert surfacearea_cylinder(4,5)==226.18800000000002", "assert surfacearea_cylinder(4,10)==351.848"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 575, "text": "Write a python function to find nth number in a sequence which is not a multiple of a given number.", "code": "def count_no (A,N,L,R): \r\n count = 0\r\n for i in range (L,R + 1): \r\n if (i % A != 0): \r\n count += 1\r\n if (count == N): \r\n break\r\n return (i) ", "test_list": ["assert count_no(2,3,1,10) == 5", "assert count_no(3,6,4,20) == 11", "assert count_no(5,10,4,20) == 16"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 576, "text": "Write a python function to check whether an array is subarray of another or not.", "code": "def is_Sub_Array(A,B,n,m): \r\n i = 0; j = 0; \r\n while (i < n and j < m): \r\n if (A[i] == B[j]): \r\n i += 1; \r\n j += 1; \r\n if (j == m): \r\n return True; \r\n else: \r\n i = i - j + 1; \r\n j = 0; \r\n return False; ", "test_list": ["assert is_Sub_Array([1,4,3,5],[1,2],4,2) == False", "assert is_Sub_Array([1,2,1],[1,2,1],3,3) == True", "assert is_Sub_Array([1,0,2,2],[2,2,0],4,3) ==False"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 577, "text": "Write a python function to find the last digit in factorial of a given number.", "code": "def last_Digit_Factorial(n): \r\n if (n == 0): return 1\r\n elif (n <= 2): return n \r\n elif (n == 3): return 6\r\n elif (n == 4): return 4 \r\n else: \r\n return 0", "test_list": ["assert last_Digit_Factorial(4) == 4", "assert last_Digit_Factorial(21) == 0", "assert last_Digit_Factorial(30) == 0"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 578, "text": "Write a function to interleave lists of the same length.", "code": "def interleave_lists(list1,list2,list3):\r\n result = [el for pair in zip(list1, list2, list3) for el in pair]\r\n return result", "test_list": ["assert interleave_lists([1,2,3,4,5,6,7],[10,20,30,40,50,60,70],[100,200,300,400,500,600,700])==[1, 10, 100, 2, 20, 200, 3, 30, 300, 4, 40, 400, 5, 50, 500, 6, 60, 600, 7, 70, 700]", "assert interleave_lists([10,20],[15,2],[5,10])==[10,15,5,20,2,10]", "assert interleave_lists([11,44], [10,15], [20,5])==[11,10,20,44,15,5]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 579, "text": "Write a function to find the dissimilar elements in the given two tuples.", "code": "def find_dissimilar(test_tup1, test_tup2):\r\n res = tuple(set(test_tup1) ^ set(test_tup2))\r\n return (res) ", "test_list": ["assert find_dissimilar((3, 4, 5, 6), (5, 7, 4, 10)) == (3, 6, 7, 10)", "assert find_dissimilar((1, 2, 3, 4), (7, 2, 3, 9)) == (1, 4, 7, 9)", "assert find_dissimilar((21, 11, 25, 26), (26, 34, 21, 36)) == (34, 36, 11, 25)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 580, "text": "Write a function to extract the even elements in the nested mixed tuple.", "code": "def even_ele(test_tuple, even_fnc): \r\n\tres = tuple() \r\n\tfor ele in test_tuple: \r\n\t\tif isinstance(ele, tuple): \r\n\t\t\tres += (even_ele(ele, even_fnc), ) \r\n\t\telif even_fnc(ele): \r\n\t\t\tres += (ele, ) \r\n\treturn res \r\ndef extract_even(test_tuple):\r\n res = even_ele(test_tuple, lambda x: x % 2 == 0)\r\n return (res) ", "test_list": ["assert extract_even((4, 5, (7, 6, (2, 4)), 6, 8)) == (4, (6, (2, 4)), 6, 8)", "assert extract_even((5, 6, (8, 7, (4, 8)), 7, 9)) == (6, (8, (4, 8)))", "assert extract_even((5, 6, (9, 8, (4, 6)), 8, 10)) == (6, (8, (4, 6)), 8, 10)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 581, "text": "Write a python function to find the surface area of the square pyramid.", "code": "def surface_Area(b,s): \r\n return 2 * b * s + pow(b,2) ", "test_list": ["assert surface_Area(3,4) == 33", "assert surface_Area(4,5) == 56", "assert surface_Area(1,2) == 5"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 582, "text": "Write a function to check if a dictionary is empty or not.", "code": "def my_dict(dict1):\r\n if bool(dict1):\r\n return False\r\n else:\r\n return True", "test_list": ["assert my_dict({10})==False", "assert my_dict({11})==False", "assert my_dict({})==True"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 583, "text": "Write a function for nth catalan number.", "code": "def catalan_number(num):\r\n if num <=1:\r\n return 1 \r\n res_num = 0\r\n for i in range(num):\r\n res_num += catalan_number(i) * catalan_number(num-i-1)\r\n return res_num", "test_list": ["assert catalan_number(10)==16796", "assert catalan_number(9)==4862", "assert catalan_number(7)==429"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 584, "text": "Write a function to find all adverbs and their positions in a given sentence by using regex.", "code": "import re\r\ndef find_adverbs(text):\r\n for m in re.finditer(r\"\\w+ly\", text):\r\n return ('%d-%d: %s' % (m.start(), m.end(), m.group(0)))", "test_list": ["assert find_adverbs(\"Clearly, he has no excuse for such behavior.\") == '0-7: Clearly'", "assert find_adverbs(\"Please handle the situation carefuly\") == '28-36: carefuly'", "assert find_adverbs(\"Complete the task quickly\") == '18-25: quickly'"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 585, "text": "Write a function to find the n - expensive price items from a given dataset using heap queue algorithm.", "code": "import heapq\r\ndef expensive_items(items,n):\r\n expensive_items = heapq.nlargest(n, items, key=lambda s: s['price'])\r\n return expensive_items", "test_list": ["assert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-2', 'price': 555.22}]", "assert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09}],2)==[{'name': 'Item-2', 'price': 555.22},{'name': 'Item-1', 'price': 101.1}]", "assert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1)==[{'name': 'Item-2', 'price': 555.22}]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 586, "text": "Write a python function to split the array and add the first part to the end.", "code": "def split_Arr(a,n,k): \r\n b = a[:k] \r\n return (a[k::]+b[::]) ", "test_list": ["assert split_Arr([12,10,5,6,52,36],6,2) == [5,6,52,36,12,10]", "assert split_Arr([1,2,3,4],4,1) == [2,3,4,1]", "assert split_Arr([0,1,2,3,4,5,6,7],8,3) == [3,4,5,6,7,0,1,2]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 587, "text": "Write a function to convert a list to a tuple.", "code": "def list_tuple(listx):\r\n tuplex = tuple(listx)\r\n return tuplex", "test_list": ["assert list_tuple([5, 10, 7, 4, 15, 3])==(5, 10, 7, 4, 15, 3)", "assert list_tuple([2, 4, 5, 6, 2, 3, 4, 4, 7])==(2, 4, 5, 6, 2, 3, 4, 4, 7)", "assert list_tuple([58,44,56])==(58,44,56)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 588, "text": "Write a python function to find the difference between largest and smallest value in a given array.", "code": "def big_diff(nums):\r\n diff= max(nums)-min(nums)\r\n return diff", "test_list": ["assert big_diff([1,2,3,4]) == 3", "assert big_diff([4,5,12]) == 8", "assert big_diff([9,2,3]) == 7"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 589, "text": "Write a function to find perfect squares between two given numbers.", "code": "def perfect_squares(a, b):\r\n lists=[]\r\n for i in range (a,b+1):\r\n j = 1;\r\n while j*j <= i:\r\n if j*j == i:\r\n lists.append(i) \r\n j = j+1\r\n i = i+1\r\n return lists", "test_list": ["assert perfect_squares(1,30)==[1, 4, 9, 16, 25]", "assert perfect_squares(50,100)==[64, 81, 100]", "assert perfect_squares(100,200)==[100, 121, 144, 169, 196]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 590, "text": "Write a function to convert polar coordinates to rectangular coordinates.", "code": "import cmath\r\ndef polar_rect(x,y):\r\n cn = complex(x,y)\r\n cn=cmath.polar(cn)\r\n cn1 = cmath.rect(2, cmath.pi)\r\n return (cn,cn1)", "test_list": ["assert polar_rect(3,4)==((5.0, 0.9272952180016122), (-2+2.4492935982947064e-16j))", "assert polar_rect(4,7)==((8.06225774829855, 1.0516502125483738), (-2+2.4492935982947064e-16j))", "assert polar_rect(15,17)==((22.67156809750927, 0.8478169733934057), (-2+2.4492935982947064e-16j))"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 591, "text": "Write a python function to interchange the first and last elements in a list.", "code": "def swap_List(newList): \r\n size = len(newList) \r\n temp = newList[0] \r\n newList[0] = newList[size - 1] \r\n newList[size - 1] = temp \r\n return newList ", "test_list": ["assert swap_List([12, 35, 9, 56, 24]) == [24, 35, 9, 56, 12]", "assert swap_List([1, 2, 3]) == [3, 2, 1]", "assert swap_List([4, 5, 6]) == [6, 5, 4]"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 592, "text": "Write a python function to find sum of product of binomial co-efficients.", "code": "def binomial_Coeff(n,k): \r\n C = [0] * (k + 1); \r\n C[0] = 1; # nC0 is 1 \r\n for i in range(1,n + 1): \r\n for j in range(min(i, k),0,-1): \r\n C[j] = C[j] + C[j - 1]; \r\n return C[k]; \r\ndef sum_Of_product(n): \r\n return binomial_Coeff(2 * n,n - 1); ", "test_list": ["assert sum_Of_product(3) == 15", "assert sum_Of_product(4) == 56", "assert sum_Of_product(1) == 1"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 593, "text": "Write a function to remove leading zeroes from an ip address.", "code": "import re\r\ndef removezero_ip(ip):\r\n string = re.sub('\\.[0]*', '.', ip)\r\n return string\r", "test_list": ["assert removezero_ip(\"216.08.094.196\")==('216.8.94.196') ", "assert removezero_ip(\"12.01.024\")==('12.1.24') ", "assert removezero_ip(\"216.08.094.0196\")==('216.8.94.196') "], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 594, "text": "Write a function to find the difference of first even and odd number of a given list.", "code": "def diff_even_odd(list1):\r\n first_even = next((el for el in list1 if el%2==0),-1)\r\n first_odd = next((el for el in list1 if el%2!=0),-1)\r\n return (first_even-first_odd)", "test_list": ["assert diff_even_odd([1,3,5,7,4,1,6,8])==3", "assert diff_even_odd([1,2,3,4,5,6,7,8,9,10])==1", "assert diff_even_odd([1,5,7,9,10])==9"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 595, "text": "Write a python function to count minimum number of swaps required to convert one binary string to another.", "code": "def min_Swaps(str1,str2) : \r\n count = 0\r\n for i in range(len(str1)) : \r\n if str1[i] != str2[i] : \r\n count += 1\r\n if count % 2 == 0 : \r\n return (count // 2) \r\n else : \r\n return (\"Not Possible\") ", "test_list": ["assert min_Swaps(\"1101\",\"1110\") == 1", "assert min_Swaps(\"111\",\"000\") == \"Not Possible\"", "assert min_Swaps(\"111\",\"110\") == \"Not Possible\""], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 596, "text": "Write a function to find the size of the given tuple.", "code": "import sys \r\ndef tuple_size(tuple_list):\r\n return (sys.getsizeof(tuple_list)) ", "test_list": ["assert tuple_size((\"A\", 1, \"B\", 2, \"C\", 3) ) == sys.getsizeof((\"A\", 1, \"B\", 2, \"C\", 3))", "assert tuple_size((1, \"Raju\", 2, \"Nikhil\", 3, \"Deepanshu\") ) == sys.getsizeof((1, \"Raju\", 2, \"Nikhil\", 3, \"Deepanshu\"))", "assert tuple_size(((1, \"Lion\"), ( 2, \"Tiger\"), (3, \"Fox\"), (4, \"Wolf\")) ) == sys.getsizeof(((1, \"Lion\"), ( 2, \"Tiger\"), (3, \"Fox\"), (4, \"Wolf\")))"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 597, "text": "Write a function to find kth element from the given two sorted arrays.", "code": "def find_kth(arr1, arr2, m, n, k):\r\n\tsorted1 = [0] * (m + n)\r\n\ti = 0\r\n\tj = 0\r\n\td = 0\r\n\twhile (i < m and j < n):\r\n\t\tif (arr1[i] < arr2[j]):\r\n\t\t\tsorted1[d] = arr1[i]\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tsorted1[d] = arr2[j]\r\n\t\t\tj += 1\r\n\t\td += 1\r\n\twhile (i < m):\r\n\t\tsorted1[d] = arr1[i]\r\n\t\td += 1\r\n\t\ti += 1\r\n\twhile (j < n):\r\n\t\tsorted1[d] = arr2[j]\r\n\t\td += 1\r\n\t\tj += 1\r\n\treturn sorted1[k - 1]", "test_list": ["assert find_kth([2, 3, 6, 7, 9], [1, 4, 8, 10], 5, 4, 5) == 6", "assert find_kth([100, 112, 256, 349, 770], [72, 86, 113, 119, 265, 445, 892], 5, 7, 7) == 256", "assert find_kth([3, 4, 7, 8, 10], [2, 5, 9, 11], 5, 4, 6) == 8"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 598, "text": "Write a function to check whether the given number is armstrong or not.", "code": "def armstrong_number(number):\r\n sum = 0\r\n times = 0\r\n temp = number\r\n while temp > 0:\r\n times = times + 1\r\n temp = temp // 10\r\n temp = number\r\n while temp > 0:\r\n reminder = temp % 10\r\n sum = sum + (reminder ** times)\r\n temp //= 10\r\n if number == sum:\r\n return True\r\n else:\r\n return False", "test_list": ["assert armstrong_number(153)==True", "assert armstrong_number(259)==False", "assert armstrong_number(4458)==False"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 599, "text": "Write a function to find sum and average of first n natural numbers.", "code": "def sum_average(number):\r\n total = 0\r\n for value in range(1, number + 1):\r\n total = total + value\r\n average = total / number\r\n return (total,average)", "test_list": ["assert sum_average(10)==(55, 5.5)", "assert sum_average(15)==(120, 8.0)", "assert sum_average(20)==(210, 10.5)"], "test_setup_code": "", "challenge_test_list": []}
{"task_id": 600, "text": "Write a python function to check whether the given number is even or not using bitwise operator.", "code": "def is_Even(n) : \r\n if (n^1 == n+1) :\r\n return True; \r\n else :\r\n return False; ", "test_list": ["assert is_Even(1) == False", "assert is_Even(2) == True", "assert is_Even(3) == False"], "test_setup_code": "", "challenge_test_list": []}