Datasets:
source_id int64 1.31k 685k | source_row int64 0 157 | source_revision stringclasses 1
value | source_seed_sha1 stringlengths 40 40 | source_url stringclasses 1
value | instruction stringlengths 149 1.85k | original_response stringlengths 89 1.53k | prompt stringlengths 178 1.92k | completion stringlengths 28 680 | token_count int64 94 816 | body_sha256 stringlengths 64 64 | split stringclasses 1
value | validation_status stringclasses 1
value | loss_mask stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
165,808 | 0 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | f35b008f8b8ce16c456068d0066447b71244c41b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function named `get_value` that takes a matrix (represented by a list of lists) and a tuple of indices, and returns the value at that index in the matrix. The function should handle index out of range errors by returning None. | To handle the index out of range errors, we need to check if the indices are valid before accessing the matrix. We can do this by checking if the indices are within the bounds of the matrix dimensions. If they are not valid, we can return None. If they are valid, we can access the matrix and return the value at that in... | def get_value(matrix, indices):
'Write a Python function named `get_value` that takes a matrix (represented by a list of lists) and a tuple of indices, and returns the value at that index in the matrix. The function should handle index out of range errors by returning None.'
| row_index, col_index = indices
if row_index < 0 or row_index >= len(matrix) or col_index < 0 or (col_index >= len(matrix[row_index])):
return None
return matrix[row_index][col_index]
| 149 | 9e7bdc46d214c75ca1d6e017d08ac1ef8c225013e8e763e9e743f697e1d34e67 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
533,341 | 1 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c2ab70d6100ff7ee18de97027618a6cad3fe9fe6 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `check_collision` that takes a list of `rectangles` as input and checks if there are any collisions between any two rectangles. A rectangle is represented as a tuple (x, y, w, h) where (x, y) is the top-left corner of the rectangle, `w` is the width, and `h` is the height.
The function should r... | Here's how you could implement the `check_collision` function:
```python
def check_collision(rectangles):
for i in range(len(rectangles)):
for j in range(i + 1, len(rectangles)):
x1, y1, w1, h1 = rectangles[i]
x2, y2, w2, h2 = rectangles[j]
if x1 + w1 > x2 and x1 < x2 +... | def check_collision(rectangles):
'Write a Python function `check_collision` that takes a list of `rectangles` as input and checks if there are any collisions between any two rectangles. A rectangle is represented as a tuple (x, y, w, h) where (x, y) is the top-left corner of the rectangle, `w` is the width, and `h`... | for i in range(len(rectangles)):
for j in range(i + 1, len(rectangles)):
x1, y1, w1, h1 = rectangles[i]
x2, y2, w2, h2 = rectangles[j]
if x1 + w1 > x2 and x1 < x2 + w2 and (y1 + h1 > y2) and (y1 < y2 + h2):
return True
return False
| 324 | 1dff8a71069b7a767469ec77b8c8d90802d8e7e867fe617554d190bb383b20c2 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
219,475 | 4 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0d414e66e9959250b88f5419355616d128759bd5 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes two lists `A` and `B`, each representing a matrix, and returns their sum in the form of a new list. The matrices are of the same size, and each element of the output matrix is the sum of the corresponding elements in `A` and `B`. | You can create a Python function that takes two lists `A` and `B` as input. Both lists represent matrices of the same size. Each element of the output matrix is the sum of the corresponding elements in `A` and `B`.
Here's how you could do it:
```python
def matrix_sum(A, B):
rows = len(A)
cols = len(A[0])
... | def matrix_sum(A, B):
'Write a Python function that takes two lists `A` and `B`, each representing a matrix, and returns their sum in the form of a new list. The matrices are of the same size, and each element of the output matrix is the sum of the corresponding elements in `A` and `B`.'
| rows = len(A)
cols = len(A[0])
C = []
for i in range(rows):
row = []
for j in range(cols):
row.append(A[i][j] + B[i][j])
C.append(row)
return C
| 197 | 4712777cb9205f3f1f1101fd5c0b8c1a7b8161a9d9521c2d1733916585e13844 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
81,575 | 5 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 7d5eb4016d6a12ba12a343bbf02c37d4029e65f2 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Given a list of dictionaries, your goal is to traverse the list and create a new list with the value of the key `'id'` for each dictionary. For example, given `[{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Bob'}]`, the desired output would be `[1, 2]`. Make use of list comprehension and dictionary lookup to solve the ... | To achieve the desired result, we can use list comprehension in Python to iterate over the list of dictionaries and extract the `'id'` value for each dictionary. This allows us to create a new list with the extracted `'id'` values. Additionally, we can use dictionary lookup to retrieve the `'id'` value for each diction... | def extract_id_values(data: list) -> list:
"Given a list of dictionaries, your goal is to traverse the list and create a new list with the value of the key `'id'` for each dictionary. For example, given `[{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Bob'}]`, the desired output would be `[1, 2]`. Make use of list c... | return [dictionary['id'] for dictionary in data]
| 136 | 30b450aca858eeeb5e81aeb03532b3b8e900a08823cc03a844ab8c79f58b69e3 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
444,447 | 6 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | cc029e11d2de9c2ccedb4e60fbf030478468d9a9 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a list of strings and a special string, and returns a list of strings sorted using a lexicographic comparison. However, the special string should be treated as smaller than all other strings. The function should return a sorted list of strings in the same order as the input.
For exam... | To write a Python function that sorts a list of strings in lexicographic order while treating a special string as smaller than all other strings, you can follow these steps:
1. Create a list of strings that includes the special string as the first element.
2. Use the built-in `sorted` function to sort the list of stri... | def sort_strings(strings, special_string):
"Write a Python function that takes a list of strings and a special string, and returns a list of strings sorted using a lexicographic comparison. However, the special string should be treated as smaller than all other strings. The function should return a sorted list of s... | strings_with_special = [special_string] + [string for string in strings if string != special_string]
sorted_strings = sorted(strings_with_special)
sorted_strings.remove(special_string)
sorted_strings.insert(0, special_string)
return sorted_strings
| 216 | a4c6677ab226f7efbc7bdd278aa164eb85dc8f5c978a584629fd8acd0d4fc471 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
203,341 | 8 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0eb7c9940f38acc0cd148a8b54c99d9cd1e8cfb1 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Implement a Python function to convert a positive integer number from its decimal representation to its binary (base 2) representation as a string. Your function should recursively convert the integer number by repeatedly dividing it by 2 and adding the remainder to the result string. If the integer number is 0, return... | Here is a Python function that implements this approach:
```python
def decimal_to_binary(num: int) -> str:
"""
Converts a positive integer number from its decimal representation to its binary (base 2) representation.
"""
if num == 0:
return ""
return decimal_to_binary(num // 2) + str(num %... | def decimal_to_binary(num: int) -> str:
'Implement a Python function to convert a positive integer number from its decimal representation to its binary (base 2) representation as a string. Your function should recursively convert the integer number by repeatedly dividing it by 2 and adding the remainder to the resu... | if num == 0:
return ''
return decimal_to_binary(num // 2) + str(num % 2)
| 163 | 73322b0aaac92ce412693dbb9cbe4786a600e7f8371f6ac95dbdc1ca78f17697 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
348,373 | 9 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | d6bd365dcc69a4036248171931422b19c52c1745 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that returns the factorial of a given natural number. The function should support recursion and should be properly commented. The function should check for valid input and return an error message if the input is not a natural number.
Here is an example of a factorial function:
```python
def fa... | Here is a Python function that implements a factorial function using recursion:
```python
def factorial_recursive(n):
"""
Recursively calculates the factorial of a natural number.
Args:
n (int): The natural number.
Returns:
int: The factorial of n.
Raises:
ValueError: If ... | def factorial_recursive(n):
'Write a Python function that returns the factorial of a given natural number. The function should support recursion and should be properly commented. The function should check for valid input and return an error message if the input is not a natural number.\n\nHere is an example of a fa... | if n < 0:
raise ValueError('The input must be a natural number.')
elif n == 0:
return 1
else:
return n * factorial_recursive(n - 1)
| 358 | a401b142fac019cec82f9645b36f45399f8942d15d6b9bb320a444f81f49dd93 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
488,041 | 10 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 3edda847b270f1d013c9cb06731d220d7d629081 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a list of numbers and modifies it in place by squaring all the elements that are divisible by 3. You can do this by modifying the input list directly without returning a new list.
### Instruction (2)
Modify the function you wrote in the previous prompt to also modify the input list s... | To modify the input list in place, we can iterate over the list using a for loop, and update the elements that are divisible by 3 and 5. We can use the modulus operator (`%`) to check if an element is divisible by 3 or 5, and assign the appropriate value. For example, if the element is divisible by 3 but not 5, we can ... | def modify_list(nums):
'Write a Python function that takes a list of numbers and modifies it in place by squaring all the elements that are divisible by 3. You can do this by modifying the input list directly without returning a new list.\n\n### Instruction (2)\nModify the function you wrote in the previous prompt ... | for i in range(len(nums)):
if nums[i] % 3 == 0 and nums[i] % 5 != 0:
nums[i] = nums[i] ** 2
elif nums[i] % 5 == 0:
nums[i] = -1
| 283 | f8a3e0eb78f73505bf330e9c20906188421e6366bd014332d2f74f179e4db931 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
664,621 | 11 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 10fe03ab2ddb1a5602e816dac398e6ce57fca082 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to encode a list of integers into a string of characters. Convert each integer to its corresponding ASCII character and concatenate all characters together to form the final encoded string.
For example, given the list `[65, 66, 67]`, the function should return the string `'ABC'`. | To encode a list of integers into a string of characters, you need to convert each integer to its corresponding ASCII character and concatenate all characters together to form the final encoded string.
Python provides the `chr()` function to convert an integer to its corresponding ASCII character. You can use a list c... | def encode_list(input_list):
"Write a Python function to encode a list of integers into a string of characters. Convert each integer to its corresponding ASCII character and concatenate all characters together to form the final encoded string.\n\nFor example, given the list `[65, 66, 67]`, the function should retur... | return ''.join((chr(i) for i in input_list))
| 106 | 2f222d388bcac039a769d42c99cbb6412b61f6cee64a715d5247a289fba8e238 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
633,087 | 13 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 83c7445e1c4c2c034f609f19da0d9638b3d9dbf3 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to convert a list of keys and values into a dictionary. Keys must be unique and values may be duplicated. The function should transform the dictionary by grouping duplicate values into a set for each key. For example, given keys=[1, 2, 3, 4], values=[10, 20, 30, 40], the function should return {... | To transform the dictionary into the desired format by grouping duplicate values into a set for each key, we must iterate through each key-value pair and add the value to the corresponding set in the output dictionary. Since the keys must be unique, we can use a `dict` to represent the output, where the keys are the un... | def transform_dictionary(keys, values):
'Write a Python function to convert a list of keys and values into a dictionary. Keys must be unique and values may be duplicated. The function should transform the dictionary by grouping duplicate values into a set for each key. For example, given keys=[1, 2, 3, 4], values=[... | output = dict()
for key, value in zip(keys, values):
if key in output:
output[key].add(value)
else:
output[key] = {value}
return output
| 210 | 63c31573ebb75a7a21798c999d5a890afdfe5cb3b4013bec30a26227e15eb69b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
83,645 | 14 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1c8c98aea22c880aed2b2269b4077118b0782ab5 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `unwrap_string` that takes in a wrapped string and unwrapped it into a single string. Each line of the wrapped string is separated by a newline character, and the words in the wrapped string are separated by a single space.
For example, given the wrapped string `"Hello\nWorld"`, the output shou... | Here is an implementation of the `unwrap_string` function in Python:
```python
def unwrap_string(wrapped_string: str) -> str:
unwrapped_string = ''
for line in wrapped_string.split('\n'):
for word in line.split(' '):
unwrapped_string += word + ' '
return unwrapped_string.strip()
```
Th... | def unwrap_string(wrapped_string: str) -> str:
'Write a Python function `unwrap_string` that takes in a wrapped string and unwrapped it into a single string. Each line of the wrapped string is separated by a newline character, and the words in the wrapped string are separated by a single space.\n\nFor example, give... | unwrapped_string = ''
for line in wrapped_string.split('\n'):
for word in line.split(' '):
unwrapped_string += word + ' '
return unwrapped_string.strip()
| 187 | 05a21f03f41033df63fec413eaa42ed36e032f871505bd4479feb1a041ba32ec | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
685,252 | 16 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | ce93cdeeacd8de5eb1d752300c738212ed84bd25 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to calculate the sum of the first `n` natural numbers. Implement the function using a list comprehension and arithmetic operations.
Your code should pass the following assertions:
```python
assert sum_of_natural_numbers(1) == 1
assert sum_of_natural_numbers(5) == 15
``` | Here's how you can implement this:
```python
def sum_of_natural_numbers(n):
return sum(x for x in range(1, n + 1))
```
The `sum()` function calculates the sum of the elements in the range generated by the `range()` function, which is a list comprehension. | def sum_of_natural_numbers(n):
'Write a Python function to calculate the sum of the first `n` natural numbers. Implement the function using a list comprehension and arithmetic operations.\n\nYour code should pass the following assertions:\n```python\nassert sum_of_natural_numbers(1) == 1\nassert sum_of_natural_numb... | return sum((x for x in range(1, n + 1)))
| 119 | fd797b73349d8afa27b9b5556c3977fe857f68ab9ff21a11daba1d5655c38ac9 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
308,607 | 17 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | e71011b4ab911714ad4758a54fdc40814c9f65ec | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function that takes two strings, `s1` and `s2`, and return their numerical difference. If either string cannot be converted to a valid number, return 0.
Your code should pass the following assertions:
```python
assert numerical_difference("123", "100") == 23
assert numerical_difference("abc", "100") ==... | You can use the `int()` function to convert strings to integers and the `try-except` block to catch the `ValueError` exception when a string cannot be converted to an integer. A simple way to find the numerical difference is to subtract `s2` from `s1`.
Here's how you can do it in Python:
```python
def numerical_diffe... | def numerical_difference(s1, s2):
'Create a Python function that takes two strings, `s1` and `s2`, and return their numerical difference. If either string cannot be converted to a valid number, return 0.\n\nYour code should pass the following assertions:\n```python\nassert numerical_difference("123", "100") == 23\n... | try:
num1 = int(s1)
num2 = int(s2)
return num1 - num2
except ValueError:
return 0
| 178 | b20d5cf02122f6af7c1b2827566e72db81afb383de1d19c45078b1958cf2edab | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
341,460 | 19 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | cb0cf03efa3e97bfae8f62f0a1c9c0a1332240b9 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a function `sum_dict` that takes two dictionaries, `d1` and `d2`, as input, and returns a new dictionary that contains the sum of the values of the two dictionaries. If a key exists in both dictionaries, then the value of the key in the resulting dictionary should be the sum of the values from the two dictionarie... | To create a new dictionary that contains the sum of the values of the two input dictionaries, you can follow these steps:
1. Create an empty dictionary to store the resulting dictionary.
2. Iterate through each key-value pair in the first dictionary, `d1`.
3. If the key exists in the second dictionary, `d2`, then add ... | def sum_dict(d1, d2):
'Write a function `sum_dict` that takes two dictionaries, `d1` and `d2`, as input, and returns a new dictionary that contains the sum of the values of the two dictionaries. If a key exists in both dictionaries, then the value of the key in the resulting dictionary should be the sum of the valu... | result = {}
for key, value in d1.items():
if key in d2:
result[key] = value + d2[key]
else:
result[key] = value
for key, value in d2.items():
if key not in d1:
result[key] = value
return result
| 415 | c61697bb4b4aff04f6e55d32c9d716159eb62ae4ed7793d4b36251467e3efcf8 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
573,825 | 21 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 8c5e07915785588e3f17774111e7eadc3641eb89 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | I have a Python script that generates a nested data structure to represent a company's organizational structure. The data structure is a dictionary where each key-value pair represents a department and its employees, respectively. Here's an example:
```python
{
'Engineering': [
'Alice',
'Bob',
... | Here's a Python function that implements this approach:
```python
def get_all_employees(departments):
employees = []
for department, employees_list in departments.items():
employees.extend(employees_list)
for employee in employees_list:
if isinstance(employee, dict):
... | def get_all_employees(departments):
"I have a Python script that generates a nested data structure to represent a company's organizational structure. The data structure is a dictionary where each key-value pair represents a department and its employees, respectively. Here's an example:\n\n```python\n{\n 'Enginee... | employees = []
for department, employees_list in departments.items():
employees.extend(employees_list)
for employee in employees_list:
if isinstance(employee, dict):
employees.extend(get_all_employees(employee))
return employees
| 422 | 99fc971f6b71e990f35d20d5a329e3a507f3101d4c56aa6a1994450026369bd5 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
405,938 | 22 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | bd4d372abdd2b338538c17f55bc115ba001974ba | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to calculate the intersection of union (IoU) metric between two bounding boxes represented as dictionaries with the following structure: `{ 'x': <float>, 'y': <float>, 'width': <float>, 'height': <float> }`. | Here is how you could implement the IoU metric function in Python:
```python
def calculate_iou(box1, box2):
x1 = max(box1['x'], box2['x'])
y1 = max(box1['y'], box2['y'])
x2 = min(box1['x'] + box1['width'], box2['x'] + box2['width'])
y2 = min(box1['y'] + box1['height'], box2['y'] + box2['height'])
i... | def calculate_iou(box1, box2):
"Write a Python function to calculate the intersection of union (IoU) metric between two bounding boxes represented as dictionaries with the following structure: `{ 'x': <float>, 'y': <float>, 'width': <float>, 'height': <float> }`."
| x1 = max(box1['x'], box2['x'])
y1 = max(box1['y'], box2['y'])
x2 = min(box1['x'] + box1['width'], box2['x'] + box2['width'])
y2 = min(box1['y'] + box1['height'], box2['y'] + box2['height'])
if x1 > x2 or y1 > y2:
return 0.0
intersection_area = (x2 - x1) * (y2 - y1)
box1_area = box1['... | 320 | 3da01bfbb8dd5efbdd5428d2e125d8b665ed94bc22b704192387fbd39d2a9a8a | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
308,824 | 23 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | bba510fc27918e09f10ee5d5825828fd7421eb2b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to initialize a table of 0s, where the table size is determined by the input. The input is a list of two integers, `row` and `col`, indicating the number of rows and columns of the table.
For example, if the input is `[2, 3]`, the function should return `[[0, 0, 0], [0, 0, 0]]`. | Here is the implementation:
```python
def initialize_table(row, col):
return [[0 for _ in range(col)] for _ in range(row)]
``` | def initialize_table(row, col):
'Write a Python function to initialize a table of 0s, where the table size is determined by the input. The input is a list of two integers, `row` and `col`, indicating the number of rows and columns of the table.\n\nFor example, if the input is `[2, 3]`, the function should return `[... | return [[0 for _ in range(col)] for _ in range(row)]
| 125 | 0ae2d1feb3dc4e08a3702bb5a9ddc99debb7d7be65cc165043e561ff2965887d | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
499,120 | 26 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | b528d132ac85fa1b81bd872360a8f6e946e50252 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Given a list that contains some empty elements, write a Python function to filter out these empty elements and return a new list with only non-empty elements.
Your code should pass the following test case:
```python
lst = [1, 2, 3, None, 4, None, 5]
expected_result = [1, 2, 3, 4, 5]
assert remove_empty(lst) == expecte... | To filter out empty elements from a list in Python, we can leverage the `filter` function and provide a predicate function that checks if the element is not empty. The `filter` function will return a generator object, which we can convert into a list using the `list` function.
Here is the implementation of the `remove... | def remove_empty(lst: list) -> list:
'Given a list that contains some empty elements, write a Python function to filter out these empty elements and return a new list with only non-empty elements.\n\nYour code should pass the following test case:\n```python\nlst = [1, 2, 3, None, 4, None, 5]\nexpected_result = [1, ... | return list(filter(None, lst))
| 136 | d4b5fd9bde792a8eba0d6840cfde305e3c461348f57e5415ba4005844d23da6b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
286,053 | 28 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c16fa2f74d00d030f4822f8187d11b1eeefa1ecf | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a non-negative integer, representing a number of seconds, and converts it to a string representing the time in hours:minutes:seconds format.
For example, 120 seconds should be converted to "0:02:00". | To accomplish this, we'll need to divide the given number of seconds into hours, minutes, and seconds. Then, we'll convert each component to a string and concatenate them with ":" between them.
Here's a possible implementation:
```python
def seconds_to_time(seconds):
hours = seconds // 3600
seconds %= 3600
... | def seconds_to_time(seconds):
'Write a Python function that takes a non-negative integer, representing a number of seconds, and converts it to a string representing the time in hours:minutes:seconds format.\n\nFor example, 120 seconds should be converted to "0:02:00".'
| hours = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return f'{hours}:{minutes:02}:{seconds:02}'
| 131 | 988aaf27b1e8c6bb5990a25f627b1539832fa031ca0b06e57367bda7fa240898 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
425,915 | 29 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 49506f86c0c41810308f6a1f73bf13251a32ee60 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Given a dictionary `d`, write a Python function that returns a shallow copy of `d` by omitting entries with missing keys. Let's call this new dictionary `d_copy`.
If any of the entries of `d_copy` has a value type of dictionary, then delete the entire dictionary entry from `d_copy`. For example, if `d = {'a': 1, 'b': ... | To solve this problem, we can use a dictionary comprehension to iterate over the keys and values of the given dictionary `d`. We can check if the value of each entry is a dictionary and delete it from the dictionary comprehension, otherwise return the value. Finally, we can use the dictionary comprehension to return th... | def copy_omit_missing(d: dict) -> dict:
"Given a dictionary `d`, write a Python function that returns a shallow copy of `d` by omitting entries with missing keys. Let's call this new dictionary `d_copy`.\n\nIf any of the entries of `d_copy` has a value type of dictionary, then delete the entire dictionary entry fro... | return {k: v for k, v in d.items() if not isinstance(v, dict)}
| 173 | aac394ef39cc596a429d7c0aca585e824ab609298a6f1d2753ab743c4909904c | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
138,396 | 31 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | daaa898afff0d0476adf8e258089073555ec1565 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function named `filter_and_update_dict`. This function takes two dictionaries as input parameters: `input_dict` and `update_dict`. The function filters the `update_dict` based on the keys that exist in `input_dict` and updates the values of the `input_dict` with the filtered `update_dict`. The function s... | To implement this function, we can iterate through the keys of `input_dict` and check if they exist in `update_dict`. If they do, we update the corresponding values in `input_dict` with the values from `update_dict`. We can use a `for` loop to iterate through the keys of `input_dict`, and use the `in` operator to check... | def filter_and_update_dict(input_dict, update_dict):
"Write a Python function named `filter_and_update_dict`. This function takes two dictionaries as input parameters: `input_dict` and `update_dict`. The function filters the `update_dict` based on the keys that exist in `input_dict` and updates the values of the `i... | for key in input_dict:
if key in update_dict:
input_dict[key] = update_dict[key]
return input_dict
| 279 | 4f7b883c48c9a94f9da9ac8153dd23a26367b4e2ceac440d4f32de6d697e631b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
678,255 | 32 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 059f200a22ca2c6cfa40e5562f7a9beb12222a8f | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `intersection` that takes two lists `A` and `B` and returns a new list `C` that contains only the elements that are common between the two lists. Use a list comprehension to construct the list `C`. The function should not modify the input lists. | Here is the implementation of the `intersection` function:
```python
def intersection(A, B):
C = [x for x in A if x in B]
return C
```
This implementation uses a list comprehension to construct the desired list `C`. The list comprehension iterates over elements `x` in `A` and checks if `x` is also present in ... | def intersection(A, B):
'Write a Python function `intersection` that takes two lists `A` and `B` and returns a new list `C` that contains only the elements that are common between the two lists. Use a list comprehension to construct the list `C`. The function should not modify the input lists.'
| C = [x for x in A if x in B]
return C
| 97 | b43fdb494305c0bc1141a5d0b72b7e1350bc2e4945ca8fc8050568b3e6f45cb2 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
194,606 | 33 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | f1bd02ac89c24f44bfff990e4ca278d175e92938 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Implement a Python function `compare_integers(n1, n2)` that compares two integers and returns their comparison status as a string. The input integers can be of any type (int, float, or string). The function should handle input validation to ensure that the inputs are valid integers (or can be converted to valid integer... | ```python
def compare_integers(n1, n2):
if not isinstance(n1, (int, float)) or not isinstance(n2, (int, float)):
try:
n1 = int(n1)
n2 = int(n2)
except ValueError:
raise ValueError("Inputs must be integers or convertible to integers.")
if n1 == n2:
ret... | def compare_integers(n1, n2):
'Implement a Python function `compare_integers(n1, n2)` that compares two integers and returns their comparison status as a string. The input integers can be of any type (int, float, or string). The function should handle input validation to ensure that the inputs are valid integers (o... | if not isinstance(n1, (int, float)) or not isinstance(n2, (int, float)):
try:
n1 = int(n1)
n2 = int(n2)
except ValueError:
raise ValueError('Inputs must be integers or convertible to integers.')
if n1 == n2:
return 'equal'
elif n1 > n2:
ret... | 310 | f309c7739a5f8c6fbcae44c3c1f0bd54d44fd1e1b89a7e4029dd65fcbe875e90 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
564,393 | 34 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1fd6596e16af1e73525efa7b8fe37c5b48c08996 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Develop a Python function `is_prime` that determines whether a given integer `n` is prime. The function should return a Boolean value indicating whether `n` is prime or not.
Your code should pass the following assertions:
```python
assert is_prime(8) == False
assert is_prime(2) == True
assert is_prime(3) == True
``` | To check if a given number `n` is prime, we can follow a well-known algorithm that checks for divisibility by all numbers between 2 and `n**0.5`. This is because any number greater than `n**0.5` will have a corresponding divisor less than or equal to `n**0.5`.
Here is the implementation of the `is_prime` function:
``... | def is_prime(n):
'Develop a Python function `is_prime` that determines whether a given integer `n` is prime. The function should return a Boolean value indicating whether `n` is prime or not.\n\nYour code should pass the following assertions:\n```python\nassert is_prime(8) == False\nassert is_prime(2) == True\nasse... | if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
| 182 | 00e4bbaeb31ab3ebb5fa5b8b2c8b2a437ae4ed6f0e14cd968e096c0688a22482 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
562,005 | 36 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 24e3b16ef8344ba3799fffb896060bc621939d75 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function to convert temperature data between Celsius and Fahrenheit. The function takes two arguments: the temperature value and the unit, which is either `'C'` for Celsius or `'F'` for Fahrenheit. The function should return the converted temperature in the chosen unit.
Here's the conversion formula:
$... | To satisfy the given instruction, you could write a Python function that takes two arguments, the temperature value and the unit. The function should return the converted temperature in the desired unit. Here is how you could achieve that:
1. Define a function `convert_temperature(value, unit)`
2. Check if the unit is... | def convert_temperature(value, unit):
"Write a Python function to convert temperature data between Celsius and Fahrenheit. The function takes two arguments: the temperature value and the unit, which is either `'C'` for Celsius or `'F'` for Fahrenheit. The function should return the converted temperature in the chos... | if unit == 'C':
return value * 9 / 5 + 32
elif unit == 'F':
return (value - 32) * 5 / 9
else:
raise ValueError("Invalid unit: must be 'C' or 'F'")
| 243 | 763881e5b2186ca7f200541fea8f957c01e9e1d771f6a5ba6dc4ba9b4032cb26 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
231,456 | 37 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | e546bbfe95b22c3f1a000584c94a7592a248a483 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function to convert a tuple of HSV (Hue, Saturation, Value) color values to a tuple of RGB (Red, Green, Blue) color values. The input tuple consists of 3 values between 0 and 1, where the first value represents the hue, the second the saturation, and the third the value. The output tuple should consist ... | The HSV color space is a cylindrical color model, while the RGB color space is a Cartesian color model. The HSV model is used in color selection tools such as color wheels and sliders.
To convert a tuple of HSV color values to RGB, you can use the following steps:
1. Normalize the input HSV values between 0 and 1.
2. ... | def hsv_to_rgb(h, s, v):
'Create a Python function to convert a tuple of HSV (Hue, Saturation, Value) color values to a tuple of RGB (Red, Green, Blue) color values. The input tuple consists of 3 values between 0 and 1, where the first value represents the hue, the second the saturation, and the third the value. Th... | h = h / 360.0
s = s / 100.0
v = v / 100.0
c = v * s
x = c * (1 - abs(h * 6.0 % 2 - 1))
m = v - c
if h < 1 / 6:
r, g, b = (c, x, 0)
elif h < 2 / 6:
r, g, b = (x, c, 0)
elif h < 3 / 6:
r, g, b = (0, c, x)
elif h < 4 / 6:
r, g, b = (0, x, c)
elif ... | 473 | aab2300964898063ad78934ee16d140f595749edda9b10f2fae804a75130d8a5 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
46,719 | 40 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 351ec07ed8e9c12728a6ae033eaaba7585ccf29d | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that calculates the interest rate on a loan. Your function should take as input the loan amount, interest rate, and number of years and return the interest.
Your code should pass the following test case:
```python
loan_amount = 10000
interest_rate = 5
number_of_years = 3
assert calculate_intere... | Here's how we can implement this in Python:
```python
def calculate_interest(loan_amount, interest_rate, number_of_years):
interest = loan_amount * (interest_rate / 100) * number_of_years
return interest
```
In this implementation, the `calculate_interest` function takes three arguments: `loan_amount`, `inter... | def calculate_interest(loan_amount, interest_rate, number_of_years):
'Write a Python function that calculates the interest rate on a loan. Your function should take as input the loan amount, interest rate, and number of years and return the interest.\n\nYour code should pass the following test case:\n```python\nloa... | interest = loan_amount * (interest_rate / 100) * number_of_years
return interest
| 161 | f28725fde8fe7cc29e8bc3e989e5ef3ee71409afbd966482fa057bcfbdb5a55d | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
352,426 | 41 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 6621d6a12ed2b43038bf5fc59278f3148557b5a0 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function that returns a list of all the keys in a dictionary that start with a given prefix. For instance, given prefix "a", the function should return ["apple", "aardvark", "avocado"] for the following dictionary:
```python
{"apple": 1, "aardvark": 3, "avocado": 2, "banana": 5}
```
Your code should p... | To create a function that returns a list of all keys in a dictionary that start with a given prefix, you can iterate over the dictionary keys and check if each key starts with the prefix.
Here's how you could do it:
```python
def get_keys_with_prefix(dictionary, prefix):
keys_with_prefix = []
for key in dict... | def get_keys_with_prefix(dictionary, prefix):
'Create a Python function that returns a list of all the keys in a dictionary that start with a given prefix. For instance, given prefix "a", the function should return ["apple", "aardvark", "avocado"] for the following dictionary:\n\n```python\n{"apple": 1, "aardvark":... | keys_with_prefix = []
for key in dictionary:
if key.startswith(prefix):
keys_with_prefix.append(key)
return keys_with_prefix
| 272 | 320ced5012c214d80651028eb4f7964d0b12e3329caa27a7c2b476d2ef6a55f2 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
98,467 | 42 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0b5ade96aa4b5fd3c55969aa22a0501549600d6b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that checks if an object is a subclass of a given class. The function should safely handle exceptions and return `False` if an exception is raised. | To check if an object is a subclass of a given class, we can use the `issubclass()` function. This function checks if a given object is a subclass of another class. It returns `True` if it is a subclass, and `False` otherwise.
However, there is a potential corner case where an exception can be raised when checking if ... | def is_subclass(object, class_):
'Write a Python function that checks if an object is a subclass of a given class. The function should safely handle exceptions and return `False` if an exception is raised.'
| try:
return issubclass(object, class_)
except TypeError:
return False
| 94 | a2fa1edaf4df5cda1baeb443832ddb5caa7696bc19337b80f2df69e140b0562f | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
153,541 | 43 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 888a92fdec286699e9582be367fe64681ee4de3d | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that accepts a single parameter `tuple_of_lists` representing a tuple of lists. The function should merge these lists into a single list, preserving the order of elements from the original lists. If a list is None or empty, it should be ignored. The function should return the merged list. | To merge a tuple of lists into a single list, we can use a loop to traverse each list in the tuple and add its elements to the merged list. We need to check if the list is not None or empty, and only add its elements if it is valid.
```python
def merge_lists(tuple_of_lists):
merged_list = []
for lst in tuple_... | def merge_lists(tuple_of_lists):
'Write a Python function that accepts a single parameter `tuple_of_lists` representing a tuple of lists. The function should merge these lists into a single list, preserving the order of elements from the original lists. If a list is None or empty, it should be ignored. The function... | merged_list = []
for lst in tuple_of_lists:
if lst is not None and len(lst) > 0:
merged_list.extend(lst)
return merged_list
| 160 | bf0e3f3a1c7df62c369bd5c965369db211a5ca0c6ea095e70ccf463eed72907c | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
439,509 | 46 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0dfe72b32b05cba042da4e0c58957da7a32ed5b8 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Code a Python function that takes a string as input and returns an integer denoting the total number of times the string's first character occurs anywhere in the string.
For example, given the string `aaab`, the function should return `3` because the first character `a` occurs three times in the string. | Here's a Python implementation of a function that takes a string as input and returns the total number of times the string's first character occurs anywhere in the string:
```python
def count_first_character(string):
first_char = string[0]
count = 0
for char in string:
if char == first_char:
... | def count_first_character(string):
"Code a Python function that takes a string as input and returns an integer denoting the total number of times the string's first character occurs anywhere in the string.\n\nFor example, given the string `aaab`, the function should return `3` because the first character `a` occurs... | first_char = string[0]
count = 0
for char in string:
if char == first_char:
count += 1
return count
| 147 | 9138aeefc97f00c94e8d77de2c9cc16052fb46c8e19073e09d67dbd7dc7add31 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
373,709 | 52 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 44233f41e689443e44f401ce518e7e1ef4cc4023 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Define a Python function `sum_ints_as_strings` that takes two strings representing integers, and returns their sum. It should handle input errors like non-numeric inputs, integer overflow, and handle all possible exceptions. | ```python
def sum_ints_as_strings(s1, s2):
try:
i1 = int(s1)
i2 = int(s2)
return str(i1 + i2)
except ValueError:
raise ValueError('Invalid input, non-numeric value')
except OverflowError:
raise OverflowError('Integer overflow')
```
This function uses `int()` to conve... | def sum_ints_as_strings(s1, s2):
'Define a Python function `sum_ints_as_strings` that takes two strings representing integers, and returns their sum. It should handle input errors like non-numeric inputs, integer overflow, and handle all possible exceptions.'
| try:
i1 = int(s1)
i2 = int(s2)
return str(i1 + i2)
except ValueError:
raise ValueError('Invalid input, non-numeric value')
except OverflowError:
raise OverflowError('Integer overflow')
| 178 | 9c730bb38b35b15ac709a95d87bfd6af441335dd14fa53d00f41910900565468 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
667,865 | 53 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 84bcb62a73a13f10aafea59772d2186013e2fe0b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `query_replace` that replaces the values in an object that contains a mix of strings, integers, and floats. The function should take two arguments: `query_obj`, an object that contains objects, strings, and arrays, and `replacement`, the string to replace with. The function should recursively tr... | To write a Python function `query_replace` that replaces the values in an object that contains a mix of strings, integers, and floats, we can leverage the power of Python's dynamic typing and recursion. Python provides us with the flexibility to handle different data types dynamically, and as a language, it is particul... | def query_replace(query_obj, replacement):
'Write a Python function `query_replace` that replaces the values in an object that contains a mix of strings, integers, and floats. The function should take two arguments: `query_obj`, an object that contains objects, strings, and arrays, and `replacement`, the string to ... | if isinstance(query_obj, str):
return replacement
elif isinstance(query_obj, list):
return [query_replace(item, replacement) for item in query_obj]
elif isinstance(query_obj, dict):
return {key: query_replace(value, replacement) for key, value in query_obj.items()}
else:
... | 281 | 98c4a9c2a7bfb03a71f534665a8d8eb996aadbaaf20f2cab87b1749008406fbd | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
205,886 | 54 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 7ec98ea81252e692cc20d3204ef7346a0a573174 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes an array and returns `True` if all its elements are unique, or `False` if there is at least one duplicate.
Your code should pass the following test case:
```python
arr1 = [1, 2, 3, 4, 5]
arr2 = [1, 1, 2, 2, 3]
assert has_duplicates(arr1) == False
assert has_duplicates(arr2) == True
`... | Here's how we can implement this using a set:
```python
def has_duplicates(arr):
unique_elements = set(arr)
return len(arr) != len(unique_elements)
``` | def has_duplicates(arr):
'Write a Python function that takes an array and returns `True` if all its elements are unique, or `False` if there is at least one duplicate.\n\nYour code should pass the following test case:\n```python\narr1 = [1, 2, 3, 4, 5]\narr2 = [1, 1, 2, 2, 3]\nassert has_duplicates(arr1) == False\n... | unique_elements = set(arr)
return len(arr) != len(unique_elements)
| 160 | b1eff1ca592469f777d46c1024449a0ebf03ee45328fe659ae582a6f10a4ef6b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
265,257 | 55 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 9e5c2c417969f293ee4d89119cd173b512e2ff2b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function named `simple_cmp` that compares two objects by the result of a custom comparison function.
Input: Two objects to compare, and a comparison function that takes two objects as arguments and returns -1, 0, or 1 depending on whether the first object is less than, equal to, or greater than the seco... | To compare two objects by the result of a custom comparison function, you can define a function named `simple_cmp` that takes two objects and a comparison function as arguments. The function will then call the comparison function on the two objects and return the result.
Here's how you could implement the `simple_cmp`... | def simple_cmp(obj1, obj2, cmp_func):
'Write a Python function named `simple_cmp` that compares two objects by the result of a custom comparison function.\n\nInput: Two objects to compare, and a comparison function that takes two objects as arguments and returns -1, 0, or 1 depending on whether the first object is ... | return cmp_func(obj1, obj2)
| 145 | 9aa16baa707110b552fe1e334dfc0b7c201b55d42b7b060a8ee1b468931d4f4c | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
231,465 | 56 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0b9098b026b4fa2a96c7eb24c4e6bedd12cb5853 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `process_data` to process a list of data objects, each of which has a `name` and a `value` property, into a single string. The string should concatenate the `name` and `value` properties for each object, separated by colons and then a newline. | This is how you can implement the function in Python:
```python
def process_data(data_list):
processed_data = []
for data in data_list:
processed_data.append(f"{data.name}:{data.value}")
return "\n".join(processed_data)
```
The function iterates through the list of data objects, extracts the `name... | def process_data(data_list):
'Write a Python function `process_data` to process a list of data objects, each of which has a `name` and a `value` property, into a single string. The string should concatenate the `name` and `value` properties for each object, separated by colons and then a newline.'
| processed_data = []
for data in data_list:
processed_data.append(f'{data.name}:{data.value}')
return '\n'.join(processed_data)
| 145 | 5db9af0403de41e579e03a94935274bdac9b556e75fd51f81dabc5e8efa6a8d4 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
502,052 | 57 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1874d20da5f44587fb292ae8a899d0eadffe32dd | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a dictionary d and a list l as parameters and returns a dictionary containing all the key-value pairs from d whose keys are in l. That is, the function should return a dictionary with keys from l and the corresponding values from d. The function should return an empty dictionary if d ... | For this task, we want to create a Python function that takes a dictionary `d` and a list `l` as parameters and returns a dictionary containing all the key-value pairs from `d` whose keys are in `l`.
To accomplish this, we can use a dictionary comprehension to construct the result dictionary. We can iterate over the k... | def filter_dict_by_keys(d: dict, l: list) -> dict:
'Write a Python function that takes a dictionary d and a list l as parameters and returns a dictionary containing all the key-value pairs from d whose keys are in l. That is, the function should return a dictionary with keys from l and the corresponding values from... | if not d or not l:
return {}
return {k: d[k] for k in l if k in d}
| 146 | 831fc0cd062e981bd3fa61929801c1061d18abd5b140c8a59421d99ed092be3f | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
517,200 | 58 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 9e0728f0a1881fd40e9f754f8745c0ef35d28b90 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | I am writing a bittorrent client, and I need a function to encode an integer into a byte string in bencode format. Here are the rules:
- if the value is an integer, it is represented as `i{value}e`.
- if the value is a string, it is represented as `{length}:{value}`, where `{length}` is the length of the string in byt... | For the bittorrent client, you need to encode an integer into a byte string in bencode format. Bencode is a binary-based encoding format used in the BitTorrent protocol to represent different data types, including integers, strings, lists, and dictionaries. Here's how to encode an integer in bencode format:
1. Determi... | def encode_integer(value: int) -> bytes:
'I am writing a bittorrent client, and I need a function to encode an integer into a byte string in bencode format. Here are the rules:\n\n- if the value is an integer, it is represented as `i{value}e`.\n- if the value is a string, it is represented as `{length}:{value}`, wh... | if not isinstance(value, int):
raise TypeError('Value must be an integer')
return f'i{value}e'.encode()
| 228 | d5aa43b7772ee210ceb99fc8093e321b534c702da82acf1cfc7b48fecd12e1ab | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
157,454 | 60 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 3df28fbc71a64c5c51c4a6ea9b0f8e98d001b04f | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `all_true` that accepts a list or tuple of boolean values and returns True if and only if all values are True. You should solve this problem using only one line of code and without using any conditional statements (if, else, and/or for-loops). Your solution should use Python's `all` function as ... | Here is the implementation of the `all_true` function using only one line of code and without using any conditional statements:
```python
def all_true(values):
return all(value is True for value in values)
``` | def all_true(values):
"Write a Python function `all_true` that accepts a list or tuple of boolean values and returns True if and only if all values are True. You should solve this problem using only one line of code and without using any conditional statements (if, else, and/or for-loops). Your solution should use ... | return all((value is True for value in values))
| 222 | ea2d68cc3bca999555f7b80dda69092b71646bbf79fb69fbe2ae100232a907f0 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
447,357 | 63 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 53c3b3d1659832d3c4ac7bc8aae6e98786874ca6 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Develop a Python function named `sum_of_numbers()` that calculates the sum of all numbers in a given input list (either list of numbers or list of lists of numbers) recursively. The input can be a nested list containing integers and other nested lists.
Your task is to return the sum of all numbers in the input list. I... | Here is the implementation of the `sum_of_numbers()` function:
```python
def sum_of_numbers(input_list):
total = 0
for element in input_list:
if isinstance(element, list):
total += sum_of_numbers(element)
elif isinstance(element, int):
total += element
else:
... | def sum_of_numbers(input_list):
'Develop a Python function named `sum_of_numbers()` that calculates the sum of all numbers in a given input list (either list of numbers or list of lists of numbers) recursively. The input can be a nested list containing integers and other nested lists.\n\nYour task is to return the ... | total = 0
for element in input_list:
if isinstance(element, list):
total += sum_of_numbers(element)
elif isinstance(element, int):
total += element
else:
total += 0
return total
| 237 | 73946dab1261687d05bbe507659b558898f345c261272dbe8e001b60193f0144 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
45,658 | 64 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | dbb41e4d490bb6495fa1e3440472b72614a47075 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `convert` that accepts two arguments: `number` and `base` (a number between 2 and 16). The function should convert the given number to the corresponding value in the given base. Your solution should not use built-in functions that directly convert numbers to other bases, like `int.to_base()` or ... | You can create a Python function that takes in a `number` and `base` as arguments. The function should convert the given number to the corresponding value in the given base without using built-in functions that directly convert numbers to other bases.
Here's an implementation of the `convert` function:
```python
def ... | def convert(number, base):
"Write a Python function `convert` that accepts two arguments: `number` and `base` (a number between 2 and 16). The function should convert the given number to the corresponding value in the given base. Your solution should not use built-in functions that directly convert numbers to other... | digit_map = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15}
result = ''
quotient = number
while quotient > 0:
remainder = quotient % base
digit = digit_map[str(remainder)]
result = str(digit) +... | 385 | 3e7b6886cc72228b45e60fbabe8d83c56885d97e617fd9af92b586bdbd89f518 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
455,476 | 65 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | b8d15873c30ef8d412d242dfec7f3c1e01e9c628 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Implement a recursive quick sort algorithm in Python. If the input is already sorted, it should return the input without modification. If the input is not sorted, it should sort the input using a recursive algorithm. If the input is empty, it should return an empty list. If the input is invalid, it should raise a `Valu... | Here's an implementation of the quick sort algorithm using Python:
```python
def quick_sort(arr):
if len(arr) <= 1: # Base case: the array is already sorted
return arr
pivot = arr[0] # Choose the first element as the pivot
left = [x for x in arr[1:] if x < pivot] # Elements less than the pivot
... | def quick_sort(arr):
'Implement a recursive quick sort algorithm in Python. If the input is already sorted, it should return the input without modification. If the input is not sorted, it should sort the input using a recursive algorithm. If the input is empty, it should return an empty list. If the input is invali... | if len(arr) <= 1:
return arr
pivot = arr[0]
left = [x for x in arr[1:] if x < pivot]
right = [x for x in arr[1:] if x >= pivot]
return quick_sort(left) + [pivot] + quick_sort(right)
| 322 | 72b539e07724a6eea3d8b5412429a9afcc5cd1b8ee04c04b4dbb8766ff743e7d | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
252,539 | 68 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 046253aa6efec87af56ddf2d13710b9fbe3cc6a7 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `binarize_array` to binarize an array. The function takes a 2D array and a threshold value as the input. The function should return a binary array of the same shape as the input, where each element is either 0 or 1. An element in the output array is 1 if the corresponding element in the input ar... | To binarize an array, we need to validate its dimension and element values. If the array is not a 2D array, we raise an `InvalidArrayDimensionError` with a custom error message. If the array contains non-numeric values, we raise an `InvalidArrayElementError` with a custom error message indicating the invalid element va... | def binarize_array(array, threshold):
'Write a Python function `binarize_array` to binarize an array. The function takes a 2D array and a threshold value as the input. The function should return a binary array of the same shape as the input, where each element is either 0 or 1. An element in the output array is 1 i... | if not isinstance(array, list) or len(array) == 0 or (not all((isinstance(subarray, list) and len(subarray) == len(array[0]) for subarray in array))):
raise InvalidArrayDimensionError(f'Expected 2D array, got {type(array)}.')
for i, row in enumerate(array):
for j, element in enumerate(row):
... | 816 | bc909bd382110be54161836d3c2db2d98cc512c2002d9703a4c44425170c0cb5 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
246,348 | 72 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 2d615bd5c0869c487bcc19677db26f85ccd6487b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `flatten_paths` that takes a dictionary of paths and values and flattens it into a list of tuples, where each tuple consists of a single path string and its corresponding value. The path strings should be created by joining the dictionary's nested keys with a forward slash (/) separator. For exa... | To flatten a dictionary of paths and values, we can recursively traverse the dictionary and build the path strings as we go. When we encounter a leaf node (a value instead of a dictionary), we can add the path tuple to the result.
Here's a recursive implementation:
```python
def flatten_paths(input_dict, path=""):
... | def flatten_paths(input_dict, path=''):
"Write a Python function `flatten_paths` that takes a dictionary of paths and values and flattens it into a list of tuples, where each tuple consists of a single path string and its corresponding value. The path strings should be created by joining the dictionary's nested key... | result = []
for key, value in input_dict.items():
if isinstance(value, dict):
result.extend(flatten_paths(value, path + key + '/'))
else:
result.append((path + key, value))
return result
| 281 | 16aea31dddb4479d44127bd87e6e9008ff75610c0f16c5ed72ea7afa56a5783b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
345,145 | 73 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 51f13e51e0a4f3e4281d1593e13079943febeda1 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | For a given dictionary, recursively flatten all nested dictionaries to a single dictionary. For example, given `{'a': 1, 'b': {'c': 2, 'd': 3}}`, the output should be `{'a': 1, 'b.c': 2, 'b.d': 3}`. | To recursively flatten a nested dictionary, we can use a recursive function to traverse the dictionary and handle nested dictionaries. The function can take a dictionary as input and return a flattened dictionary.
Here is a Python function that implements this approach:
```python
def flatten_dictionary(d):
"""
... | def flatten_dictionary(d):
"For a given dictionary, recursively flatten all nested dictionaries to a single dictionary. For example, given `{'a': 1, 'b': {'c': 2, 'd': 3}}`, the output should be `{'a': 1, 'b.c': 2, 'b.d': 3}`."
| def _flatten(d, parent_key):
items = []
for k, v in d.items():
new_key = f'{parent_key}.{k}' if parent_key else k
if isinstance(v, dict):
items.extend(_flatten(v, new_key))
else:
items.append((new_key, v))
return items
r... | 278 | 181c4462aec08dcdd3187f40d4a0436992a246f5c2ce637a4b19a3eecd1d5868 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
426,811 | 74 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 05dc2f49a8319a7a9fabc1dc0a61262390d5ed98 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `select_only_allowed` that takes two arguments: `iterable`, a list of tuples of strings and integers, and `allowed`, a list of integers. The function should iterate through the tuples in `iterable` and return a list of the elements in the second position of each tuple if they are allowed by the ... | To solve this problem, we can use a set to keep track of the allowed integers and a list to store the second elements of the tuples that have allowed integers. Then, we can iterate through the tuples in `iterable`, and for each tuple, if the second element is in the allowed set, we add it to the list. Finally, we can r... | def select_only_allowed(iterable, allowed):
"Write a Python function `select_only_allowed` that takes two arguments: `iterable`, a list of tuples of strings and integers, and `allowed`, a list of integers. The function should iterate through the tuples in `iterable` and return a list of the elements in the second p... | allowed_set = set([i for i in allowed])
result = []
for i in iterable:
if i[1] in allowed_set:
result.append(i[1])
result = list(set(result))
result.sort()
return result
| 305 | 0f8bd2920f1686470711ed813799e6c55c27852af760969e073f924ec53bf691 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
61,100 | 75 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 5d3ddb24979d0718397d5160af37e0e1776d7ffb | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Define a Python function that takes a string and an optional parameter `sep` with a default value of `' '`. If `sep` is provided, the function should return the string split by the separator, otherwise the function should return a list of individual characters in the string.
Your code should pass the following asserti... | Here's how you can do it in two lines of Python code:
```python
def split_string(s, sep=' '):
return s.split(sep) if sep else list(s)
``` | def split_string(s, sep=' '):
"Define a Python function that takes a string and an optional parameter `sep` with a default value of `' '`. If `sep` is provided, the function should return the string split by the separator, otherwise the function should return a list of individual characters in the string.\n\nYour c... | return s.split(sep) if sep else list(s)
| 147 | 27c600dbff8fb6c4d3620d546870249bb0fd214e704173a821adbcfaee5582b5 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
547,095 | 77 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | a285e8f7391cdd5b6b83d0d80a06244297fe3e7f | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function that takes in a list of integers, sorts them in ascending order, and returns a new list containing the sorted elements. Write the docstring in the following format:
```
Parameters:
num_list (list): A list of integers.
Returns:
list: A sorted list of integers, with the smallest element... | You can create a Python function that uses the built-in `sorted()` function to sort the list in ascending order.
Here's how you could do it:
```python
def sort_list(num_list):
"""
Sorts a given list of integers in ascending order.
Parameters:
num_list (list): A list of integers.
Returns:
... | def sort_list(num_list):
'Create a Python function that takes in a list of integers, sorts them in ascending order, and returns a new list containing the sorted elements. Write the docstring in the following format:\n\n```\nParameters:\n num_list (list): A list of integers.\n\nReturns:\n list: A sorted list o... | return sorted(num_list)
| 204 | 12c0be1179f87d93f8b815aca5953b8482351c72957f410f495a47189a4f1f70 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
516,863 | 82 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1ce35acde732b76619444637770a6c2a6868e07b | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function, `clean_text(text, stopwords)`, that takes two arguments: `text` (a string) and `stopwords` (a list of stopwords). The function should return a cleaned string without any stopwords. The stopwords should be removed from the string and the remaining words should be joined together with spaces. | Here's the basic idea:
1. Split the text into individual words using `text.split()`
2. Filter out the stopwords from the list of words using `list comprehension`
3. Join the remaining words together with spaces
Here's a possible implementation of the function using this approach:
```python
def clean_text(text, stopwo... | def clean_text(text, stopwords):
'Write a Python function, `clean_text(text, stopwords)`, that takes two arguments: `text` (a string) and `stopwords` (a list of stopwords). The function should return a cleaned string without any stopwords. The stopwords should be removed from the string and the remaining words shou... | words = text.split()
cleaned_words = [word for word in words if word not in stopwords]
cleaned_text = ' '.join(cleaned_words)
return cleaned_text
| 145 | a38562fe348e598e115c2b4c7eb31378d5d870ee28d674cabb582f5a6d4c7d37 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
210,083 | 85 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | d15c6c0305c1abda21e97761ae8d8be5945ff032 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a list of JSON objects, each representing a user with a name, email, and a list of friends. The function should return a list of objects sorted by the number of friends, from the most friends to the least.
Here's an example input and the expected output (formatted for readability):
... | To solve this problem, you can use the `sorted()` function in Python with a custom key function that counts the number of friends for each user.
Here's how you can implement it:
```python
def sort_users_by_friends(users):
def count_friends(user):
return len(user['friends'])
return sorted(users, key=c... | def sort_users_by_friends(users):
'Write a Python function that takes a list of JSON objects, each representing a user with a name, email, and a list of friends. The function should return a list of objects sorted by the number of friends, from the most friends to the least.\n\nHere\'s an example input and the expe... | def count_friends(user):
return len(user['friends'])
return sorted(users, key=count_friends, reverse=True)
| 507 | aedecd62eea90e11d8bd7242e23785d030fe2c2abaeb8c95be7700565823ef10 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
308,810 | 90 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 242ca84d414f5cc4e95d6a8e67e1fde8da96b7ea | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function to convert a nested list with specific patterns into a nested tuple. For instance, given the following input list:
```python
input_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
```
The function should return a nested tuple as follows:
```python
output_tuple = ((1, 2, 3), (4, 5), (6, 7, 8, 9))
``` | Here's how you can implement the conversion function:
```python
def convert_list_to_tuple(nested_list):
if not isinstance(nested_list, list):
return nested_list
return tuple(convert_list_to_tuple(item) for item in nested_list)
```
This function uses a recursive approach to convert a nested list into ... | def convert_list_to_tuple(nested_list):
'Create a Python function to convert a nested list with specific patterns into a nested tuple. For instance, given the following input list:\n\n```python\ninput_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]\n```\n\nThe function should return a nested tuple as follows:\n\n```python... | if not isinstance(nested_list, list):
return nested_list
return tuple((convert_list_to_tuple(item) for item in nested_list))
| 192 | 1ffbc4947b21ad3e21d7c170381d0de95fd617af7f59eb0006fc0396075d0e91 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
97,448 | 91 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 58fb775aa90fe83f6678435a6dbe2a5a347ed679 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `convert_hex_to_dec` to convert an input string of hexadecimal numbers into a list of decimal numbers. The input string is a sequence of hexadecimal numbers separated by commas (','). Each hexadecimal number is between 0 and 255 (both inclusive), and the output list must have the same length as ... | Here's how we can implement this:
```python
def convert_hex_to_dec(input_string):
hex_numbers = input_string.split(',')
dec_numbers = []
for hex_number in hex_numbers:
dec_number = int(hex_number, base=16)
dec_numbers.append(dec_number)
return dec_numbers
```
In this implementation, w... | def convert_hex_to_dec(input_string):
'Write a Python function `convert_hex_to_dec` to convert an input string of hexadecimal numbers into a list of decimal numbers. The input string is a sequence of hexadecimal numbers separated by commas (\',\'). Each hexadecimal number is between 0 and 255 (both inclusive), and ... | hex_numbers = input_string.split(',')
dec_numbers = []
for hex_number in hex_numbers:
dec_number = int(hex_number, base=16)
dec_numbers.append(dec_number)
return dec_numbers
| 275 | 3f2070996cc12d83b9d81a48cbdcb8a800be204ca2c0d8363cdd4a727938e964 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
598,661 | 92 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | b4e20d7e6ae8c1824ba1350dacb7b266a9e7f96d | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Given a list of tuples `(index, value)` representing indexed values, create a dictionary such that for each unique value present in the list, a new entry is created in the dictionary, with the key being the unique value and the value a list of the indices corresponding to that value.
For example, given the list `[(0, ... | Here's an example implementation:
```python
def create_dictionary(tuples):
constructed_dictionary = {}
for index, value in tuples:
if value not in constructed_dictionary:
constructed_dictionary[value] = []
constructed_dictionary[value].append(index)
return constructed_dictionary... | def create_dictionary(tuples):
'Given a list of tuples `(index, value)` representing indexed values, create a dictionary such that for each unique value present in the list, a new entry is created in the dictionary, with the key being the unique value and the value a list of the indices corresponding to that value.... | constructed_dictionary = {}
for index, value in tuples:
if value not in constructed_dictionary:
constructed_dictionary[value] = []
constructed_dictionary[value].append(index)
return constructed_dictionary
| 238 | 4fe8777665bf83ee38ff46caebe5e3029e3bb5b583c20303a0ae14ef644e5fe5 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
469,148 | 94 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | f77fcf734a2b2b85dabd40c651aac77b82000d20 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function to update a dictionary with new keys and values. The function should take two parameters: the dictionary to be updated and a list of tuples, where each tuple contains a key and a value. The keys in the list should be checked against the dictionary's keys to see whether they already exist. If a ... | Here's a Python function that implements this logic:
```python
def update_dictionary(my_dict, tuples_list):
for key, value in tuples_list:
if key in my_dict:
my_dict[key] = value
else:
my_dict[key] = value
return my_dict
```
In this implementation:
- We iterate through ... | def update_dictionary(my_dict, tuples_list):
"Create a Python function to update a dictionary with new keys and values. The function should take two parameters: the dictionary to be updated and a list of tuples, where each tuple contains a key and a value. The keys in the list should be checked against the dictiona... | for key, value in tuples_list:
if key in my_dict:
my_dict[key] = value
else:
my_dict[key] = value
return my_dict
| 290 | 31dab338910c1c4dd7a47167baf8769619c7249749f6ce8438dca824ff0a9ec6 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
1,305 | 95 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 0068931868e214896f6263e58fc09215352d502c | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes an array of strings as input and returns a single string with the first letter of each string capitalized. Include documentation that describes the function, its parameters, and its return value. Be sure to use meaningful variable names, as well as a conditional expression to handle t... | ```python
def capitalize_first(strings):
"""
Capitalize the first letter of each string in the given list of strings.
Args:
strings (list): A list of strings to be capitalized.
Returns:
str: A string with the first letter of each string capitalized, separated by spaces.
"""
cap... | def capitalize_first(strings):
'Write a Python function that takes an array of strings as input and returns a single string with the first letter of each string capitalized. Include documentation that describes the function, its parameters, and its return value. Be sure to use meaningful variable names, as well as ... | capitalized_strings = [string.capitalize() for string in strings]
return ' '.join(capitalized_strings)
| 110 | 9cef45be75b7e050a3a163a16620c8b3c05256e5f1cc382281664ebc2cd154c8 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
646,808 | 98 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 576f2f0df6d7f54c659a1a315920e748d784f4be | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that concatenates two strings. If one of the strings is `None` or empty, return the other string.
Your code should pass the following assertions:
```python
assert concatenate_strings(None, "World") == "World"
assert concatenate_strings("Hello", None) == "Hello"
assert concatenate_strings("Hello... | Here is a Python function that implements this approach:
```python
def concatenate_strings(s1: str, s2: str) -> str:
if s1 is None or not s1:
return s2
elif s2 is None or not s2:
return s1
else:
return s1 + s2
```
This implementation checks whether `s1` or `s2` is `None` or empty. ... | def concatenate_strings(s1: str, s2: str) -> str:
'Write a Python function that concatenates two strings. If one of the strings is `None` or empty, return the other string.\n\nYour code should pass the following assertions:\n```python\nassert concatenate_strings(None, "World") == "World"\nassert concatenate_strings... | if s1 is None or not s1:
return s2
elif s2 is None or not s2:
return s1
else:
return s1 + s2
| 201 | fee0945509c24869ebba344148b290f75bb6e4c19b21f756f2c9119a15f84c10 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
119,170 | 99 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | dab7b6a0765dee718a562dbde62f011082e8ea84 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `is_int(s)` that takes a string `s` and returns `True` if `s` can be parsed as an integer, and `False` otherwise. Utilize exception handling to handle any potential errors and return `False` if an exception occurs.
Your code should pass the following assertions:
```python
assert is_int('123') i... | Here is a Python function that implements this functionality:
```python
def is_int(s):
try:
int(s)
return True
except ValueError:
return False
```
In this implementation:
- We use `int(s)` to try to convert the string to an integer.
- If the conversion is successful, the string can be ... | def is_int(s):
"Write a Python function `is_int(s)` that takes a string `s` and returns `True` if `s` can be parsed as an integer, and `False` otherwise. Utilize exception handling to handle any potential errors and return `False` if an exception occurs.\n\nYour code should pass the following assertions:\n```python... | try:
int(s)
return True
except ValueError:
return False
| 177 | 30f726b8532d7e6c6b636bfd6fcaa8d708e60327b524939d017e0efd1551a257 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
118,820 | 100 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 894649a98d12d88f7543e5ede9383ec3703148b3 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | You are given a nested dictionary where each key is a string and each value is either a string or a nested dictionary. Write a function that flattens the hierarchy of keys by joining them with a period ('.') and returns a new dictionary with the flattened keys and the same values. | Here is a Python implementation of the DFS approach:
```python
def flatten_dict(dictionary: dict) -> dict:
"""Flattens a dictionary with nested keys and returns a new dictionary with the flattened keys."""
flattened_dict = {}
def dfs(dictionary, current_key, flattened_dict):
for key, value in dict... | def flatten_dict(dictionary: dict) -> dict:
"You are given a nested dictionary where each key is a string and each value is either a string or a nested dictionary. Write a function that flattens the hierarchy of keys by joining them with a period ('.') and returns a new dictionary with the flattened keys and the sa... | flattened_dict = {}
def dfs(dictionary, current_key, flattened_dict):
for key, value in dictionary.items():
new_key = current_key + '.' + key if current_key else key
if isinstance(value, dict):
dfs(value, new_key, flattened_dict)
else:
... | 266 | 627e1954ed3b71c18387575d33db6a76f8f5f7c04e2324bc84839aaf012bfad3 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
546,674 | 102 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | f11ba457c6bd9c930cb6b90b97a5dbf5657d908e | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `flatten_dictionary` that takes a dictionary (possibly nested) as input and flattens it into a single-level dictionary, where the keys are dot-separated (e.g., 'a.b.c' for the key 'c' in sub-dictionary 'b' in dictionary 'a'). You can assume that the input dictionary will have string keys and val... | Here is a Python function that implements this approach:
```python
def flatten_dictionary(d):
"""
Flattens a nested dictionary into a single-level dictionary. The nested keys are separated by dots.
For example, a dictionary {'a': {'b': 1, 'c': 2}, 'd': 3} will be flattened to {'a.b': 1, 'a.c': 2, 'd': 3}.
... | def flatten_dictionary(d):
"Write a Python function `flatten_dictionary` that takes a dictionary (possibly nested) as input and flattens it into a single-level dictionary, where the keys are dot-separated (e.g., 'a.b.c' for the key 'c' in sub-dictionary 'b' in dictionary 'a'). You can assume that the input dictiona... | flattened = {}
for key, value in d.items():
if isinstance(value, dict):
nested_flattened = flatten_dictionary(value)
flattened.update({f'{key}.{nested_key}': nested_value for nested_key, nested_value in nested_flattened.items()})
else:
flattened[key] = value
... | 333 | 420c4b410c3212642c6b56803f13a7948197b87e1639de6db6b4962d438848bb | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
4,908 | 103 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | df3dc6507b8eae9d148ec9b2e664a427813d93a7 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `permute_data` for the purpose of data permuting in dimensionality reduction and other machine learning tasks. The function takes two arguments: `data`, an array of data points with shape (n, d), where n is the number of data points and d is the dimensionality of each point; and `permute_idx`, a... | Here's how you could implement this function in Python:
```python
def permute_data(data, permute_idx):
permuted_data = data[:, permute_idx]
return permuted_data
```
The `permute_data` function takes two arguments: `data`, an array of data points with shape (n, d) where n is the number of data points and d is ... | def permute_data(data, permute_idx):
'Write a Python function `permute_data` for the purpose of data permuting in dimensionality reduction and other machine learning tasks. The function takes two arguments: `data`, an array of data points with shape (n, d), where n is the number of data points and d is the dimensio... | permuted_data = data[:, permute_idx]
return permuted_data
| 162 | f4cbf303e86fa98ca9c376393c5ea734436873473660bd4c40fb628fd02aa99b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
444,584 | 104 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1d78b23875df12cef8c8356bfdbb879c67656d65 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | I have a list of objects `x_list`. Each object has an `x` attribute that can be accessed with `obj.x`. Write a Python function `my_func(x_list)` that returns a list containing the `x` attributes of all objects in `x_list`. If the `x` attribute for a given object is odd, you should double it, and if it is even, you shou... | The goal is to write a Python function `my_func` that takes a list of objects `x_list` as input and returns a list containing the `x` attributes of all objects in `x_list`. If the `x` attribute for a given object is odd, you should double it; if it is even, you should divide it by 2.
To achieve this, we'll create a ne... | def my_func(x_list):
'I have a list of objects `x_list`. Each object has an `x` attribute that can be accessed with `obj.x`. Write a Python function `my_func(x_list)` that returns a list containing the `x` attributes of all objects in `x_list`. If the `x` attribute for a given object is odd, you should double it, a... | assert x_list, 'x_list must not be empty'
assert all((obj.x > 0 and isinstance(obj.x, int) for obj in x_list)), 'x values must be positive integers'
transformed_list = []
for obj in x_list:
if obj.x % 2 == 1:
transformed_list.append(obj.x * 2)
else:
transformed_li... | 288 | 065c38294a89d1184415775f9bdfa3b6e03966c1c5118c07291ecb4a80a27596 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
444,500 | 109 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 47b33e7bf9d3e9bc1728d16d639be27004f517db | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `get_value_at(obj, path)` that takes an object and a path (a list of keys) as input. The function should traverse through the object by following the path and return the value located at the end.
If an error is encountered during traversal, raise a `KeyError` with the appropriate message. If a ... | Here is how you could implement such a function:
```python
def get_value_at(obj, path):
current = obj
for key in path:
if isinstance(current, dict):
if key not in current:
raise KeyError("Key not found: {}".format(key))
current = current[key]
elif isinsta... | def get_value_at(obj, path):
'Write a Python function `get_value_at(obj, path)` that takes an object and a path (a list of keys) as input. The function should traverse through the object by following the path and return the value located at the end.\n\nIf an error is encountered during traversal, raise a `KeyError`... | current = obj
for key in path:
if isinstance(current, dict):
if key not in current:
raise KeyError('Key not found: {}'.format(key))
current = current[key]
elif isinstance(current, list):
try:
key = int(key)
except Va... | 430 | 90d56289ee52cd67c4808dfddc959f38ddd3ceb60690f70083d706d1ba905551 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
190,830 | 111 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 1dd37261802ac72540a93f5ea9f2fdbf4344cfc1 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a string and returns its integer representation. Return `None` if the given string does not represent a valid integer. The function should support negative integers and ignore any leading and trailing spaces.
For example, `my_atoi("42")` should return `42`, `my_atoi(" -42")` should ... | You can create a Python function that iterates through each character of the given string to convert it to an integer. The function should also support negative integers, ignore any leading and trailing spaces, and return `None` if the given string does not represent a valid integer.
Here's how you could implement thi... | def my_atoi(string):
'Write a Python function that takes a string and returns its integer representation. Return `None` if the given string does not represent a valid integer. The function should support negative integers and ignore any leading and trailing spaces.\n\nFor example, `my_atoi("42")` should return `42`... | string = string.strip()
if not string:
return None
is_negative = string[0] == '-'
if is_negative:
string = string[1:]
for char in string:
if not char.isdigit():
return None
integer = int(string)
if is_negative:
integer = -integer
return integer... | 258 | 1154163edf663fce131c8d34cdf191711cc44a49334bbdd27bf6c3404393186c | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
191,582 | 112 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | b6a3f4bd0a73a3792bb7a9f839e73b7dedcfc6d2 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `error_measure(a, b)` that returns the absolute difference between two numbers without using any built-in math functions. The function should also be annotated for type hints. The function's docstring should make the reader understand the function's purpose.
Your code should pass the following ... | Here is an example implementation of the `error_measure` function, using type hints and a docstring to explain its purpose:
```python
def error_measure(a: float, b: float) -> float:
"""Return the absolute difference between two numbers without using any built-in math functions."""
if a > b:
return a - ... | def error_measure(a: float, b: float) -> float:
"Write a Python function `error_measure(a, b)` that returns the absolute difference between two numbers without using any built-in math functions. The function should also be annotated for type hints. The function's docstring should make the reader understand the func... | if a > b:
return a - b
else:
return b - a
| 170 | 6f37ffeb3583847df656ef6fabc4f1c66ed1a56327db93429bbeb72c86f4665b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
486,933 | 113 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 49c469381630ced54b5ff52f34ed9d8af98c100e | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes in a positive integer as an argument and returns a string that represents the integer in its binary form. The string should be padded with zeros to the left so that it always has 32 characters.
Your code should pass the following assertions:
```python
assert int_to_bin(10) == "000000... | Here's how you can implement this:
```python
def int_to_bin(num):
if not isinstance(num, int) or num < 0:
raise ValueError("Input must be a positive integer.")
bin_str = ""
while num > 0:
bin_str = str(num % 2) + bin_str
num //= 2
bin_str = (32 - len(bin_str)) * "0" + bin_str
... | def int_to_bin(num):
'Write a Python function that takes in a positive integer as an argument and returns a string that represents the integer in its binary form. The string should be padded with zeros to the left so that it always has 32 characters.\n\nYour code should pass the following assertions:\n```python\nas... | if not isinstance(num, int) or num < 0:
raise ValueError('Input must be a positive integer.')
bin_str = ''
while num > 0:
bin_str = str(num % 2) + bin_str
num //= 2
bin_str = (32 - len(bin_str)) * '0' + bin_str
return bin_str
| 242 | f3306b3cba4feadd8c62629896b9884108e963abe8ff717567a64444a9701ec0 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
6,877 | 115 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | ecf54fa40195ba4de7db13874e44388a04527bed | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | A code is a string of five characters. It is valid if it starts with "X" and contains only letters and numbers. Write a Python function to check if a code is valid.
Your code should pass the following assertions:
```python
assert is_valid_code("XABC5")
assert not is_valid_code("XABC5!")
assert not is_valid_code("Y1234... | To check if a code is valid, we need to check if it starts with "X" and contains only letters and numbers.
We can use the `startswith()` method of the `str` class to check if the code starts with "X" and the `isalnum()` method of the `str` class to check if the code contains only letters and numbers. Here's the implem... | def is_valid_code(code):
'A code is a string of five characters. It is valid if it starts with "X" and contains only letters and numbers. Write a Python function to check if a code is valid.\n\nYour code should pass the following assertions:\n```python\nassert is_valid_code("XABC5")\nassert not is_valid_code("XABC5... | return code.startswith('X') and code[1:].isalnum()
| 152 | 46d8f6ba7d47bbcf62270d3a1ad74e673275aa880b9de14130ff54d9a3093a35 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
579,931 | 116 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c6d3fde49662b1a83bc07655c9a3e914b27a60ff | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function `find_substrings(string, n)` that returns all substrings of length `n` from a given input `string`. For example, `find_substrings('abcde', 2)` should return `['ab', 'bc', 'cd', 'de']`. | Here's how you can do it in Python:
```python
def find_substrings(string, n):
return [string[i:i+n] for i in range(len(string)-n+1)]
```
The `range` function generates the starting indices for the substrings, and the list comprehension slices the string at each index to extract the substring of the desired length... | def find_substrings(string, n):
"Create a Python function `find_substrings(string, n)` that returns all substrings of length `n` from a given input `string`. For example, `find_substrings('abcde', 2)` should return `['ab', 'bc', 'cd', 'de']`."
| return [string[i:i + n] for i in range(len(string) - n + 1)]
| 109 | 0cf18377eb3b3b4bb7936f131332223117748e1eeb2ad2541d57c850ec3069ea | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
3,509 | 118 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 264f8cde11879be8ace938c777f546974383122c | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a dictionary and returns a list of unique values. If a key maps to an empty list, you should output an empty list. | To write a function that takes a dictionary and returns a list of unique values, you can follow these steps:
1. Create an empty list to store unique values.
2. Iterate over each key-value pair in the dictionary.
3. Check if the value is an empty list. If so, continue to the next iteration.
4. For non-empty values, ite... | def unique_values(d):
'Write a Python function that takes a dictionary and returns a list of unique values. If a key maps to an empty list, you should output an empty list.'
| unique_list = []
for key, value in d.items():
if not value:
continue
for element in value:
if element not in unique_list:
unique_list.append(element)
return unique_list
| 158 | 1e48da7719008bf38083361fdbd704182b73bf1955ccb3822d1da52c601aecc3 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
471,380 | 120 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 33551b91d854af6d07f8fa1c43bc7ba45b0bdeeb | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `convert_roman_numeral_to_number` that takes a Roman numeral as input and converts it to a number. The Roman numerals are represented with a combination of letters, each representing a unique number. The possible letters and their corresponding numbers are: I = 1, V = 5, X = 10, L = 50, C = 100,... | To solve this problem, we can follow the given conversion logic: read each character from left to right and add its value to the running total. If the current character has a smaller value than the previous character, subtract its value from the running total.
Here is a Python implementation of the `convert_roman_nume... | def convert_roman_numeral_to_number(roman_numeral: str) -> int:
'Write a Python function `convert_roman_numeral_to_number` that takes a Roman numeral as input and converts it to a number. The Roman numerals are represented with a combination of letters, each representing a unique number. The possible letters and th... | roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
result = 0
prev_char = ''
for char in roman_numeral:
curr_num = roman_dict[char]
if prev_char and curr_num > roman_dict[prev_char]:
result = result - 2 * roman_dict[prev_char] + curr_num
el... | 390 | 484bc3c6e908a94fbec3e12a2ef0cbc939b0d908e49ab322f6964537922e369f | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
432,635 | 121 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c6f2be8576e870d56c1125b98462d026f8206ade | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function `get_encoding_count` that takes a string as input and returns the number of bytes required to encode the string by the UTF-8 encoding.
Your code should pass the following test case:
```python
input_string = "Hello, world!"
expected_encoding_count = 13
actual_encoding_count = get_encoding_count(... | Here's how you can implement the `get_encoding_count` function in Python:
```python
def get_encoding_count(input_string):
return len(input_string.encode('utf-8'))
```
The `encode` method of a string encodes the string using the specified encoding, and returns a byte string. The number of bytes in the byte string ... | def get_encoding_count(input_string):
'Write a Python function `get_encoding_count` that takes a string as input and returns the number of bytes required to encode the string by the UTF-8 encoding.\n\nYour code should pass the following test case:\n```python\ninput_string = "Hello, world!"\nexpected_encoding_count ... | return len(input_string.encode('utf-8'))
| 179 | 920f6aac22168da1d0936b60226bb63d9eef6a3e8f7052bce9b44fdfdae639b2 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
26,478 | 122 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | bfb94655afabea3674105884d4d9b4da7eb861f3 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Design a Python function that takes a string of comma-separated key-value pairs as input and returns a dictionary representation of the same string. The input string is of the format `"key1=value1,key2=value2,...,keyn=valuen"`. The function should split the string into an array of pairs, clean each pair to remove any u... | ```python
def get_dictionary(string):
pairs = string.split(',')
dictionary = {}
for pair in pairs:
pair = pair.strip()
if '=' in pair:
key, value = pair.split('=')
dictionary[key] = value
return dictionary
```
This implementation separates the key-value pairs int... | def get_dictionary(string):
'Design a Python function that takes a string of comma-separated key-value pairs as input and returns a dictionary representation of the same string. The input string is of the format `"key1=value1,key2=value2,...,keyn=valuen"`. The function should split the string into an array of pairs... | pairs = string.split(',')
dictionary = {}
for pair in pairs:
pair = pair.strip()
if '=' in pair:
key, value = pair.split('=')
dictionary[key] = value
return dictionary
| 225 | 2daeea6111249647c0676df0e18caef53cacca51749d1d2a9e71270985851c96 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
337,226 | 123 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 72a4f5ea1ebbe9b0734cb3f6b4890e7e18c3e601 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Write a Python function that takes a function `f`, a string `s`, and a variable number of arguments `*args`, and return a new function that calls `f` with the argument `s` concatenated to the string representation of each argument in `*args`. Note that the `*args` arguments may not be strings, so you'll need to convert... | ```python
def curry(f, s):
return lambda *args: f(s, *(str(arg) for arg in args))
``` | def curry(f, s):
'Write a Python function that takes a function `f`, a string `s`, and a variable number of arguments `*args`, and return a new function that calls `f` with the argument `s` concatenated to the string representation of each argument in `*args`. Note that the `*args` arguments may not be strings, so ... | return lambda *args: f(s, *(str(arg) for arg in args))
| 233 | e119f71a7c9b2f450cd767eeea984fec73e2193708d5284e1ff2ab785b6b22a4 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
546,364 | 124 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 75f186d696283701060d91dbc91b1ab8b8ab15fc | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Design a Python function to check if a list of numbers is sorted in ascending order. It should return `True` if the list is sorted and `False` if it is not. The function should take a list of numbers and return a boolean value. The function should not modify the input list.
Here is the code skeleton:
```python
def is... | To check if a list of numbers is sorted in ascending order, you can use a linear scan to compare the current number with the previous one. If you find a number that is less than the previous one, you can immediately return `False` since the list is not sorted.
Here is how you could implement the function:
```python
d... | def is_sorted(nums):
'Design a Python function to check if a list of numbers is sorted in ascending order. It should return `True` if the list is sorted and `False` if it is not. The function should take a list of numbers and return a boolean value. The function should not modify the input list.\n\nHere is the code... | assert isinstance(nums, list)
if len(nums) == 0:
return True
for i in range(1, len(nums)):
if nums[i] < nums[i - 1]:
return False
return True
| 379 | d0fa9ffd83ffb69f4c882e8013d44a6c2617686e34b8a6ec49b56d4c794f6685 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
111,544 | 125 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | 442db43f4fdeb4d563f38b384a2ffa00cf0233ec | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Implement a function `same_attr` that takes two XML attributes as input and returns a boolean indicating whether they are equal. It should ignore the namespace prefix and consider only the local name and value. It should also ignore leading and trailing spaces in the value.
The function should return `True` if the att... | Here is the code for the `same_attr` function:
```python
def same_attr(attr1, attr2):
if attr1 is attr2:
return True
local_name1 = attr1.split('}')[-1]
local_name2 = attr2.split('}')[-1]
value1 = attr1[len(local_name1) + 1:]
value2 = attr2[len(local_name2) + 1:]
value1 = value1.strip()
... | def same_attr(attr1, attr2):
'Implement a function `same_attr` that takes two XML attributes as input and returns a boolean indicating whether they are equal. It should ignore the namespace prefix and consider only the local name and value. It should also ignore leading and trailing spaces in the value.\n\nThe func... | if attr1 is attr2:
return True
local_name1 = attr1.split('}')[-1]
local_name2 = attr2.split('}')[-1]
value1 = attr1[len(local_name1) + 1:]
value2 = attr2[len(local_name2) + 1:]
value1 = value1.strip()
value2 = value2.strip()
return local_name1 == local_name2 and value1 == value2
| 376 | 9d01c83f0faa8a01188655f976da528d7bdf4f8e3fa45fd70dce50559fbfc95b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
219,859 | 126 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c875bb6175c811a94614cbc68c00fbf961b25cc6 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | How would you sort this list of dictionaries based on the values of the name key?
```python
[
{'name': 'Alice', 'age': 25},
{'name': 'Bob', 'age': 30},
{'name': 'Charlie', 'age': 25},
{'name': 'Dave', 'age': 35},
]
```
Write a Python function to sort a list of dictionaries based on the values of a spe... | To sort a list of dictionaries by the values of a specific key, you can use the `sorted` function with a key function that returns the value of the desired key for each dictionary.
Here's how you can sort a list of dictionaries based on the values of a specific key using Python:
```python
def sort_by_key(input_list, ... | def sort_by_key(input_list, key):
"How would you sort this list of dictionaries based on the values of the name key?\n\n```python\n[\n {'name': 'Alice', 'age': 25},\n {'name': 'Bob', 'age': 30},\n {'name': 'Charlie', 'age': 25},\n {'name': 'Dave', 'age': 35},\n]\n```\n\nWrite a Python function to sort a... | return sorted(input_list, key=lambda x: x[key])
| 178 | 68d55175e0d9dfd87c4936ea51c53e5d3ed101ee31bef96e08d4aa0a4429de56 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
515,164 | 128 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | c5203087476a3d697cd38f43fe2fb209881a0bb2 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Create a Python function `get_fitness_score` that receives a `Person` object and returns the person's fitness score based on their age and height. The function should enforce the following criteria:
- If the person is less than 18 years old, their fitness score is 0.
- If the person is between 18 and 25 years old (inc... | ```python
def get_fitness_score(person):
fitness_score = 0
if person.age < 18:
return fitness_score
if person.age <= 25:
fitness_score += 5
elif person.age <= 35:
fitness_score += 10
elif person.age <= 45:
fitness_score += 15
elif person.age <= 55:
fitne... | def get_fitness_score(person):
"Create a Python function `get_fitness_score` that receives a `Person` object and returns the person's fitness score based on their age and height. The function should enforce the following criteria:\n\n- If the person is less than 18 years old, their fitness score is 0.\n- If the per... | fitness_score = 0
if person.age < 18:
return fitness_score
if person.age <= 25:
fitness_score += 5
elif person.age <= 35:
fitness_score += 10
elif person.age <= 45:
fitness_score += 15
elif person.age <= 55:
fitness_score += 20
else:
fitness_sc... | 469 | 3ced95976dfa97c2f16d49c4aa410dc8405260573f43e8d25c80aef9ea8f020b | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
408,562 | 130 | 356bb069eee815daa6e23e9a282eeefe1490ad44 | d8a9548c9b1a312f9789a4e9f3bdbe41507b4a69 | https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k/tree/356bb069eee815daa6e23e9a282eeefe1490ad44 | Implement a Python function `indices` that takes a list of booleans and returns the indices of the list elements that are `True`. Do this using list comprehension and `enumerate`. For example, `indices([True, False, True])` should return `[0, 2]`. | Here is an example implementation that implements the above steps:
```python
def indices(bool_list):
indices = []
for i, bool_value in enumerate(bool_list):
if bool_value:
indices.append(i)
return indices
```
The `enumerate` function is used to get both the index and the value of each ... | def indices(bool_list):
'Implement a Python function `indices` that takes a list of booleans and returns the indices of the list elements that are `True`. Do this using list comprehension and `enumerate`. For example, `indices([True, False, True])` should return `[0, 2]`.'
| indices = []
for i, bool_value in enumerate(bool_list):
if bool_value:
indices.append(i)
return indices
| 141 | 2c442f06da808fdae1f1e5c81ae736ab8eda1af4e3927ca57ba77a65d9429f25 | train | static_candidate_not_execution_verified | prompt=-100; completion+EOS=supervised |
BigCode GPT-J SFT curation preview
Inspection pilot, not a finished training dataset. The default viewer contains 100 static candidates (94 train / 6 development). Only three examples have received manual contract review and targeted execution checks. Two are in approved_preview; the rectangle example is held for ambiguity. All three passed their stated tests (17 assertions total); this is not comprehensive correctness certification.
Source and attribution
Derived from BigCode self-oss-instruct-sc2-exec-filter-50k, revision 356bb069eee815daa6e23e9a282eeefe1490ad44, made available under ODC-By. The pinned source has 50,661 rows. Preserve BigCode attribution and original source/license provenance on further redistribution. Source and benchmark file hashes are in manifest.json.
This preview inspects the first 500 rows, not a representative random sample. Static filters accepted 307; the first 100 are shown in the default viewer.
How examples were produced
No model generated new training solutions for this preview. Existing source rows were transformed deterministically:
instructionsupplies the task. Extract exactly one fenced Python block fromresponse.- Require exactly one undecorated standalone function. Reject imports, selected dynamic execution / file-I/O calls, multi-function snippets, and duplicate bodies.
- Keep the signature, insert the original instruction as its docstring, strip old solution docstrings and response explanations, and normalize the solution body using Python AST unparsing. Original responses are retained for audit.
- Screen exact normalized instruction/AST solution-body overlap against the pinned HumanEval reference. This does not rule out paraphrases or semantic contamination.
- Use GPT-J's pinned tokenizer and reject sequences exceeding 2,048 tokens including EOS.
- Group by source seed SHA1 for deterministic train/dev assignment. Near-duplicate families still require stronger screening before the split is frozen.
- For three selected examples, review the contract and run targeted assertions inside a disposable CPU sandbox. Never execute dataset code on the host.
The source seed is inspiration used by BigCode's generator, not our target answer. The source prompt is the generator's few-shot instruction template, not the prompt used for GPT-J training. Teacher explanations are omitted from code-only targets.
Viewer columns
source_id,source_row,source_revision,source_seed_sha1: traceability.instruction,original_response: unmodified source content.prompt,completion: transformed function-completion training pair.token_count,body_sha256,split: length and grouping metadata.validation_status: static candidate, targeted checks passed, or needs contract review.validation_json(reviewed configs): exact review scope and targeted-check results.
Examples inspected
| ID | Task | Status |
|---|---|---|
| 165808 | Retrieve a matrix value, handling invalid indexes | 7 checks passed; negative indexes treated as invalid |
| 81575 | Extract dictionary id values in order | 4 checks passed; assumes every dictionary has id |
| 533341 | Detect rectangle overlaps | 6 checks passed for positive dimensions and strict overlap; held because touching-edge behavior is unspecified |
Planned experiment
Both training arms will consume identical examples and token IDs. Prompt labels are masked with -100; code and EOS are supervised. Arm A uses ordinary next-token SFT. Arm B adds a NextLat-style future-state objective with detached latent targets. No training has run and no NextLat trainer is implemented in this preview.
HumanEval remains evaluation-only. Do not use its solutions or test feedback to create training targets or choose training hyperparameters.
Reproduction and limitations
build_preview.py and tokenize_preview.py perform local static processing. Download the pinned source parquet to source.parquet, install requirements.txt, and run them. validate_preview.py requires the CoreWeave SDK and a locally configured credential; it uses CPU-only remote execution with a three-minute cap. The preview was published as JSONL through the web editor.
Static candidates require execution checks, contract review, stronger overlap checks, and adequate development-set construction before training. The 94/6 candidate split is illustrative. Neither source execution filtering nor the targeted tests guarantee complete correctness.
The upload excludes credentials, virtual environments, model weights, the full upstream parquet, and the HumanEval benchmark file.
Readable example pairs
These transformed examples are displayed here because private dataset viewers may require a paid Hugging Face plan.
Source 165808 β reviewed_targeted_checks_passed
Prompt
def get_value(matrix, indices):
'Write a Python function named `get_value` that takes a matrix (represented by a list of lists) and a tuple of indices, and returns the value at that index in the matrix. The function should handle index out of range errors by returning None.'
Completion
row_index, col_index = indices
if row_index < 0 or row_index >= len(matrix) or col_index < 0 or (col_index >= len(matrix[row_index])):
return None
return matrix[row_index][col_index]
Source 533341 β needs_contract_review
Prompt
def check_collision(rectangles):
'Write a Python function `check_collision` that takes a list of `rectangles` as input and checks if there are any collisions between any two rectangles. A rectangle is represented as a tuple (x, y, w, h) where (x, y) is the top-left corner of the rectangle, `w` is the width, and `h` is the height.\n\nThe function should return True if any pair of rectangles collide, and False otherwise. Use an iterative approach and check for collisions based on the bounding box collision detection algorithm. If a collision is found, return True immediately without checking for more collisions.'
Completion
for i in range(len(rectangles)):
for j in range(i + 1, len(rectangles)):
x1, y1, w1, h1 = rectangles[i]
x2, y2, w2, h2 = rectangles[j]
if x1 + w1 > x2 and x1 < x2 + w2 and (y1 + h1 > y2) and (y1 < y2 + h2):
return True
return False
Source 81575 β reviewed_targeted_checks_passed
Prompt
def extract_id_values(data: list) -> list:
"Given a list of dictionaries, your goal is to traverse the list and create a new list with the value of the key `'id'` for each dictionary. For example, given `[{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Bob'}]`, the desired output would be `[1, 2]`. Make use of list comprehension and dictionary lookup to solve the problem in a single line of code."
Completion
return [dictionary['id'] for dictionary in data]
- Downloads last month
- 54