tedrics-data / tedrics_data_codefunctions_val.json
KlaudiaTH
Debugged dataset loading script.
301b108
raw
history blame
4.55 kB
[{
"task_id": 16,
"mbpp_task_id": 760,
"description": "Write a Python function to check whether a list of numbers contains only one distinct element or not.",
"cot":"Given is a list of numbers l. The check whether a list of numbers contains only one element or not can be realized using a set, since no repetitions are allowed in a set. Insert the elements of the list into the set. If there is only one element, the length of the set should be 1. In this case return True else False.",
"imports": "",
"function_head": "def unique_element(l):\n",
"function_body": " s = set(l)\n return len(s) == 1"
}, {
"task_id": 17,
"mbpp_task_id": 744,
"description": "Write a Python function to check if the given tuple has any none value or not.",
"cot":"Given a tuple t. To check if the given tuple has any none value or not can be implemented by using the functions any(), map() and lambda. The map() function iterates over each element of the given tuple and returns an iterable of the results after applying the lambda function to each item of the given tuple. The lambda function checks if an item is None. The any() function returns True if any of the elements of the returned map results are True else it returns False.",
"imports": "",
"function_head": "def check_none(test_tup):\n",
"function_body": " res = any(map(lambda ele: ele is None, test_tup))\n return res"
}, {
"task_id": 18,
"mbpp_task_id": 772,
"description": "Write a Python function to remove all the words with k length in the given string.",
"cot":"Given a string s and the length k. To remove k length words in the given string s can be realized using a list comprehension and the functions split(), join() and len(). The split() function splits a string into a list of strings after breaking the given string by the specified separator. If is not provided then any white space is a separator. Iterate over the splits with a list comprehension and omit all elements whose length differs from k, i.e. len(ele) != k. Then use the join() function to concatenate the elements of length k separated by the space character. The joined elements of length k are returned as a string.",
"imports": "",
"function_head": "def remove_length(s, k):\n",
"function_body": " temp = s.split()\n res = [ele for ele in temp if len(ele) != k]\n res = ' '.join(res)\n return (res)"
}, {
"task_id": 19,
"mbpp_task_id": 775,
"description": "Write a Python function to check whether every odd index contains odd numbers of a given list.",
"cot":"Given a list of integer numbers. To check whether every even index contains an even number and every odd index contains odd number of the input list num can be implemented using a generator expression and the modulo operator. Iterate over the indexes of the list and compare whether the index and the value stored under the index is an even or odd number. If each even index has an even value and each odd index has an odd value then return True otherwise False. Use the all() function for this. The all() function returns True if all items in an iterable are true, otherwise it returns False. If the iterable object is empty, the all() function also returns True.",
"imports": "",
"function_head": "def odd_position(nums):\n",
"function_body": " return all(nums[i]%2==i%2 for i in range(len(nums)))"
}, {
"task_id": 20,
"mbpp_task_id": 597,
"description": "Write a Python function to find kth element from the given two sorted arrays.",
"cot":"Given two sorted lists of size m and n respectively and a value k. Finding the k-th element from the given two lists of integers can be realized by using a technique based on while-loops to merge two lists. From the merged (and sorted) list the element from the k-th position can be easily determined.",
"imports": "",
"function_head": "def find_kth(arr1, arr2, k):\n",
"function_body": " m = len(arr1)\n n = len(arr2)\n sorted1 = [0] * (m + n)\n i = 0\n j = 0\n d = 0\n while (i < m and j < n):\n if (arr1[i] < arr2[j]):\n sorted1[d] = arr1[i]\n i += 1\n else:\n sorted1[d] = arr2[j]\n j += 1\n d += 1\n while (i < m):\n sorted1[d] = arr1[i]\n d += 1\n i += 1\n while (j < n):\n sorted1[d] = arr2[j]\n d += 1\n j += 1\n return sorted1[k - 1]"
}
]