codefuse-ai/CodeExercise-Python-27k
收藏数据集概述
数据集描述
该数据集包含27,000道Python编程练习题(英文),涵盖了数百个Python相关的知识点,包括基础语法和数据结构、算法应用、数据库查询、机器学习等。
数据字段结构
数据集的每个样本包含以下字段:
dataset: 数据集名称id: 样本IDchat_rounds: 包含多个对话轮次的列表,每个轮次包含:role: 角色(human或bot)content: 内容(指令或答案)chat_round_id: 对话轮次ID
示例
json { "data_name": "CodeExercise-Py", "id": 27219, "chat_rounds": [ { "role": "human", "content": "Write a Python program to rotate an array by a given number of steps.", "chat_round_id": 0 }, { "role": "bot", "content": "Sure! Heres a Python program that rotates an array by a given number of steps.
python def rotate_array(arr, steps): """ Rotate an array by the given number of steps.
Parameters:
arr (list): The input array.
steps (int): The number of steps to rotate the array. Positive steps rotate it to the right,
while negative steps rotate it to the left.
Returns:
list: The rotated array.
Examples:
>>> rotate_array([1, 2, 3, 4, 5], 2)
[4, 5, 1, 2, 3]
>>> rotate_array([1, 2, 3, 4, 5], -1)
[2, 3, 4, 5, 1]
"""
arr_length = len(arr)
steps = steps % arr_length # Handle steps larger than array length
if steps == 0: # No rotation needed
return arr
rotated_arr = arr[-steps:] + arr[:-steps] # Split the list and concatenate in the desired order
return rotated_arr
Example usage
arr = [1, 2, 3, 4, 5] steps = 2 rotated_arr = rotate_array(arr, steps) print(rotated_arr)
The rotate_array() function takes an input array arr and the number of steps steps to rotate the array. It first calculates the actual number of rotations by performing a modulo operation on steps with the length of the input array. This ensures that even if steps is larger than the array length, we always perform the appropriate number of rotations.
If steps is 0, the function returns the input array as no rotation is needed.
Otherwise, the function splits the input array into two parts based on the number of steps: the last steps elements (using negative indexing) and the remaining elements. These two parts are then concatenated in the desired order to obtain the rotated array.
Finally, the program demonstrates an example usage by rotating an array [1, 2, 3, 4, 5] by 2 steps (to the right) and printing the resulting rotated array.",
"chat_round_id": 1
}]
}
数据生成过程
数据集的生成过程包括以下步骤:
- 整理Python知识点,作为初始种子集。
- 将每个种子嵌入到固定的任务模板中,获得固定模板的"Task Prompt"。
- 使用Camel对"Task Prompt"进行润色,以获得更加描述准确且多样的Task Prompt。
- 将获得的Task Prompt输入给教师模型,生成对应知识点的练习题问题(指令)。
- 对每个练习题问题(指令),借助教师模型生成对应的问题答案。
- 组装每个问题和其答案,并进行去重操作。




