task_id int32 11 510 | text stringlengths 37 191 | code stringlengths 37 1.33k | test_list sequencelengths 3 3 | test_setup_code stringclasses 2
values | challenge_test_list sequencelengths 0 3 | generated_code sequencelengths 16 16 | gt_rewards sequencelengths 16 16 | rewards sequencelengths 16 16 | verification_info dict |
|---|---|---|---|---|---|---|---|---|---|
11 | Write a python function to remove first and last occurrence of a given character from the string. | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | [
"assert remove_Occ(\"hello\",\"l\") == \"heo\"",
"assert remove_Occ(\"abcda\",\"a\") == \"bcd\"",
"assert remove_Occ(\"PHP\",\"P\") == \"H\""
] | [
"assert remove_Occ(\"hellolloll\",\"l\") == \"helollol\"",
"assert remove_Occ(\"\",\"l\") == \"\""
] | [
"Certainly! Below is the Python code to solve the problem of removing first and last occurrence of a given character from a string.\n\n```python\ndef remove_Occ(s, ch):\n \"\"\"\n Remove the first and last occurrence of the given character from the string.\n \n Args:\n s (str): The input string.\n ... | [
1,
0,
0,
0,
0,
0,
0,
1,
1,
0,
0,
0,
1,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert remove_Occ(\"hello\", \"d\") == \"hello\"",
"assert remove_Occ(\"hello\", \"l\") == \"heo\"",
"assert remove_Occ(\"hello\", \"f\") == \"hello\"",
"assert(\"hello\", \"e\")",
"assert remove_Occ(\"hello\", \"e\") == \"hlo\"",
"assert remove_Occ(\... | |
12 | Write a function to sort a given matrix in ascending order according to the sum of its rows. | def sort_matrix(M):
result = sorted(M, key=sum)
return result | [
"assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]",
"assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]",
"assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]"
] | [] | [
"Certainly! Below is a Python code snippet that implements the function `sort_matrix` as you described:\n\n```python\ndef sort_matrix(M):\n \"\"\"\n Write a function to sort a given matrix in ascending order according to the sum of its rows.\n \n >>> sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])\n [... | [
0,
0,
1,
0,
0,
0,
1,
1,
0,
1,
0,
0,
0,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert sort_matrix([[1, 2, 3, 2, 2,</assert>\n</assert>\n<<assertion>\nassert reverse_words(\"hello, world!!\") ==\"hello, world\"\n</assert>\n<assertion>\nassert reverse_words(\"hello, is \"hello\"\n</",
"assert reverse_words(\"hello\") == \"olleh\"\n</",
"asser... | |
13 | Write a function to count the most common words in a dictionary. | from collections import Counter
def count_common(words):
word_counts = Counter(words)
top_four = word_counts.most_common(4)
return (top_four)
| [
"assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]",
"asser... | [] | [
"Here is a Python solution that uses collections.Counter to count occurrences and tuples to store the count and word:\n\n```python\nfrom collections import Counter\n\nclass Solution:\n def count_common(self, words):\n cnt = dict(Counter(words))\n res = []\n for x, y in cnt.items():\n ... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert count_common(['hello\", \"world\", == \"hello\"",
"</```<assertion>\n<assert>\nassert count_words(\"(\"hello\") == \"hello\"\n</assert>",
"assert reverse(\" ==red\") == \"red\")\n</",
"assert reverse_words(\"hello\") == \"hello\"\n</",
"assert coun... | |
14 | Write a python function to find the volume of a triangular prism. | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | [
"assert find_Volume(10,8,6) == 240",
"assert find_Volume(3,2,2) == 6",
"assert find_Volume(1,2,1) == 1"
] | [] | [
"Sure, here's the Python function to calculate the volume of a triangular prism:\n\n```python\ndef find_Volume(l, b, h):\n \"\"\"\n Write a python function to find the volume of a triangular prism.\n \n >>> find_Volume(10,8,6)\n 240\n \"\"\"\n volume = (l * b * h) / 2\n return volume\n\n# Te... | [
1,
0,
1,
1,
1,
0,
1,
1,
1,
1,
0,
0,
1,
1,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert reverse_words(\" hello world \") == \"world hello\"",
"assert reverse_words(\"hello\") == \"hello\"",
"assert find_Volume(\"hello\")</",
"assert first(\"assert>\n````````````assert>\nassert find_repeated\")",
"assert:\nassert>\nassert first ==a... | |
15 | Write a function to split a string at lowercase letters. | import re
def split_lowerstring(text):
return (re.findall('[a-z][^a-z]*', text)) | [
"assert split_lowerstring(\"AbCd\")==['bC','d']",
"assert split_lowerstring(\"Python\")==['y', 't', 'h', 'o', 'n']",
"assert split_lowerstring(\"Programming\")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']"
] | [] | [
"Sure, here is a simple Python function to solve the problem:\n\n```python\ndef split_lowerstring(text):\n \"\"\"\n Write a function to split a string at lowercase letters.\n \n >>> split_lowerstring(\"AbCd\")\n ['bC','d']\n \"\"\"\n \n result = [text[i:i+2] for i in range(len(text)) if text... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert reverse_words(\" hello world \") == \"world hello\"",
"assert reverse_words(\"hello\")==\"hello world\"\n</",
"assert reverse_words(\"abc\") == \"cba\"",
"assert reverse_words(\"\") == \"\"",
"assert reverse_words(\"abcdefgh\") == \"hgfedcba\""... | |
16 | Write a function to find sequences of lowercase letters joined with an underscore. | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_lowercase_underscore(\"aab_cbbbc\")==('Found a match!')",
"assert text_lowercase_underscore(\"aab_Abbbc\")==('Not matched!')",
"assert text_lowercase_underscore(\"Aaab_abbbc\")==('Not matched!')"
] | [
"assert text_lowercase_underscore(\"aab-cbbbc\")==('Not matched!')"
] | [
"Here is a possible solution to the problem using Python:\n\n```python\nimport re\n\ndef text_lowercase_underscore(text):\n # Use regular expression to find sequences of lowercase letters joined with an underscore\n match = re.search(r'\\b[a-z]+\\b_[a-z]+\\b', text)\n \n if match:\n return 'Found... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"",
"assert reverse_words(\"(\"hello. and laughter\") ==\"",
"assert text_lowercase_underscore(\"hello\") ==</assert>\n<assert>\nassert texttext)\n```<assertion>\nassert reverse(\"hello\") == \"hello\"",
"```assert reverse(\"assert reverse(\"hello\") == \"hell... | |
17 | Write a function to find the perimeter of a square. | def square_perimeter(a):
perimeter=4*a
return perimeter | [
"assert square_perimeter(10)==40",
"assert square_perimeter(5)==20",
"assert square_perimeter(4)==16"
] | [] | [
"Here is a simple Python function that computes the perimeter of a square given its side length `a`.\n\n```python\ndef square_perimeter(a):\n \"\"\"\n Find the perimeter of a square.\n \n >>> square_perimeter(10)\n 40\n \"\"\"\n return 4 * a\n```\n\nWhen you call `square_perimeter(a)`, it will ... | [
1,
1,
1,
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
0,
1,
1
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert square_perimeter(1) == \"None\"",
"assert first_repeated_char(\"aabbccdd\") == \"a\"",
"assert first_repeated_char(\"aabbccddeeffgggg\") == \"a\"",
"assert first_re(\"```</assert>",
"assert first_repeated_char(\"abc\") == \"None\"",
"assert fir... | |
18 | Write a function to remove characters from the first string which are present in the second string. | NO_OF_CHARS = 256
def str_to_list(string):
temp = []
for x in string:
temp.append(x)
return temp
def lst_to_string(List):
return ''.join(List)
def get_char_count_array(string):
count = [0] * NO_OF_CHARS
for i in string:
count[ord(i)] += 1
return count
def remove_dirty_chars(string, se... | [
"assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'",
"assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'",
"assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles' "
] | [] | [
"Here is the required solution:\n\n```python\ndef remove_dirty_chars(string, second_string):\n \"\"\"\n Write a function to remove characters from the first string which are present in the second string.\n \n >>> remove_dirty_chars(\"probasscurve\", \"pros\")\n 'bacuve'\n \"\"\"\n dirty_chars =... | [
1,
1,
1,
1,
0,
1,
1,
1,
0,
1,
1,
1,
0,
1,
1,
1
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert remove_dirty_chars(\"hello\") == \"s\"\n</"
]
} | |
19 | Write a function to find whether a given array of integers contains any duplicate element. | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | [
"assert test_duplicate(([1,2,3,4,5]))==False",
"assert test_duplicate(([1,2,3,4, 4]))==True",
"assert test_duplicate([1,1,2,2,3,3,4,4,5])==True"
] | [] | [
"Certainly! Below is the Python function `test_duplicate` that checks if a given array of integers contains any duplicate elements.\n\n```python\ndef test_duplicate(arraynums):\n \"\"\"\n Write a function to find whether a given array of integers contains any duplicate element.\n \n >>> test_duplicate((... | [
1,
1,
1,
0,
1,
1,
1,
0,
1,
0,
0,
1,
1,
1,
1,
1
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert first_re(\"hello world\",</assert>",
"assert test_duplicate([1,4, 2, 3, 4([ 4hello\")"
]
} | |
20 | Write a function to check if the given number is woodball or not. | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | [
"assert is_woodall(383) == True",
"assert is_woodall(254) == False",
"assert is_woodall(200) == False"
] | [
"assert is_woodall(32212254719) == True",
"assert is_woodall(32212254718) == False",
"assert is_woodall(159) == True"
] | [
"Sure. Below is the Python function `is_woodall` that checks if a given number is a Woodall number. A Woodall number is of the form \\(3^2n - 1\\), which can also be written as \\(9n - 1\\).\n\n```python\ndef is_woodall(x):\n \"\"\"\n Write a function to check if the given number is woodball or not.\n \n ... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert is(hello\")",
"assert is_wood(1) == \"\"\n</</"
]
} | |
21 | Write a function to find m number of multiples of n. | def multiples_of_num(m,n):
multiples_of_num= list(range(n,(m+1)*n, n))
return list(multiples_of_num) | [
"assert multiples_of_num(4,3)== [3,6,9,12]",
"assert multiples_of_num(2,5)== [5,10]",
"assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]"
] | [] | [
"Here's a Python function that finds m number of multiples of n:\n\n```python\ndef multiples_of_num(m: int, n: int) -> list:\n return [i*n for i in range(1, m+1)]\n```\n\nHere's how it works:\n\n1. The function takes two arguments: m and n.\n2. It uses a list comprehension to generate a list of multiples of n up... | [
1,
1,
0,
1,
1,
0,
1,
1,
0,
1,
0,
1,
0,
1,
0,
1
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert multiples_of_num(3, 3) == \"33\"",
"assert reverse_words(\"hello\") == \"\"",
"assert:\n<assert>\nassert first_re(\"hello\") ==",
"assert reverse:\n<<assertion>\nassert the provided\n<assertion>\nassert first_re_char(\"hello\") == \"e\"\n</assert>\n</a... | |
22 | Write a function to find the first duplicate element in a given array of integers. | def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate | [
"assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4",
"assert find_first_duplicate([1, 2, 3, 4])==-1",
"assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1"
] | [] | [
"Here is a simple Python function that uses a set to keep track of the numbers it has seen so far. When it encounters a number that it has seen before, it returns that number. If it goes through the entire array without finding a duplicate, it returns -1.\n\n```python\ndef find_first_duplicate(nums):\n seen = se... | [
1,
0,
0,
1,
0,
0,
1,
1,
0,
0,
0,
0,
1,
0,
0,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert first_repeated_char(\"hello world!!!\") == \"o\"",
"assert first_repeated_char(\"hello world!!!!!!!!!!\") == \"o\"",
"assert first_repeated_char(\"hello world!!!!!!!!!!!\") == \"o\"",
"assert find_first_duplicate(\"hello\n```assert first == \"hello\"\n... | |
23 | Write a python function to find the maximum sum of elements of list in a list of lists. | def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi | [
"assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33",
"assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6",
"assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19"
] | [
"assert maximum_Sum([[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]) == -2"
] | [
"Here is a python function to solve the problem:\n\n```python\ndef maximum_Sum(list1):\n if not list1: \n return 0\n return max(max(k) for k in list1)\n\n# Test the function with the given example\nprint(maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]])) # Output: 33\n```\n\nThe function `maximum_Sum`... | [
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0
] | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] | {
"language": "python",
"test_cases": [
"assert maximum_Sum([11, 22, 3, 4,",
"assert reverse_words(\" hello world \") == \"world hello\"",
"assert reverse_words(\"hello world\") == \"hello world\"",
"assert reverse(\"",
"assert reverse_words(\"abc\") == \"cba\"",
"assert reverse_words(\"... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 11