version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | instruct | Filter | Filter_61496_I | Hey! How can I modify the size of uploaded images in a web application using Flask and Pillow? | from flask import Flask, request, jsonify
from PIL import Image
import os
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads/'
RESIZE_FOLDER = 'resized/'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['RESIZE_FOLDER'] = RESIZE_FOLDER
app.config['MAX_CONTENT_PATH'] = 16 * 1024 * 1024 # 16 MB
if not os.path.exist... | import os
import pytest
from io import BytesIO
from PIL import Image
from solution import app, UPLOAD_FOLDER, RESIZE_FOLDER
@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client
# Clean up upload and resize folders
for folder in [UPLOAD_FOLDER... | [
{
"docstring": null,
"function_declaration": "def resize_image(image_path, output_path, size):",
"function_name": "resize_image",
"parameter_list": "(image_path, output_path, size)"
},
{
"docstring": null,
"function_declaration": "def upload_image():",
"function_name": "upload_image"... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, redirect, url_for\nfrom werkzeug.utils import secure_filename\nfrom PIL import Image\nimport os\n\napp = Flask(__name__)\napp.config['UPLOAD_FOLDER'] = 'uploa... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061496",
"row_id": 61496,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124328']"
} | 0.429047 | Filter_61496 | I | [
"resize_image",
"upload_image"
] | 2 | [
[
"upload_image",
"resize_image"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL",
"flask"
] | false | 8a8926e7d0d0cac2ff3ea0fc06ef6b4378ae9aa3 | 9873e837aa386c0e0b2d93506a2dc5b9dde4e6e3 | |||
v1.0 | instruct | Filter | Filter_61550_I | Write a simple game in Python where a player can choose between three options: rock, paper, or scissors, and plays against the computer. The computer randomly selects one of the three options. The game ends after a series of rounds, and the player with the highest score wins. The player can choose how many rounds they ... | import random
def get_computer_choice():
"""
Randomly chooses between rock, paper or scissors for the computer.
"""
choices = ["rock", "paper", "scissors"]
return random.choice(choices)
def get_winner(player_choice, computer_choice):
"""
Determines the winner of a rock-paper-scissors round... | from solution import get_computer_choice, get_winner, play_game
def test_get_computer_choice():
choices = ["rock", "paper", "scissors"]
assert get_computer_choice() in choices
def test_get_winner():
assert get_winner("rock", "scissors") == "player"
assert get_winner("paper", "rock") == "player"
as... | [
{
"docstring": "Randomly chooses between rock, paper or scissors for the computer.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner of a rock-paper-scissors round.",
"function_d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Randomly chooses between rock, paper or scissors for the computer.\n \"\"\"\n choices = [\"rock\", \"paper\", \"scissors\"]\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061550",
"row_id": 61550,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124444']"
} | 0.552336 | Filter_61550 | I | [
"get_computer_choice",
"get_winner",
"play_game"
] | 3 | [
[
"play_game",
"get_computer_choice"
],
[
"play_game",
"get_winner"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 980094bfe77253e93ec35e581ba0635641eafef8 | 3b0e7c38ce71d2beb83041069cccb4c3b1a46635 | |||
v1.0 | instruct | Filter | Filter_61565_I | Can you provide a detailed explanation of how to use Python decorators with examples? | def my_decorator(func):
"""
A simple decorator that prints a message before and after the execution of the function.
"""
def wrapper(*args, **kwargs):
print("Something is happening before the function is called.")
result = func(*args, **kwargs)
print("Something is happening after... | from solution import my_decorator, say_hello, decoration_with_argument, say_python
# Mocking `print` to capture printed statements for assertion
def test_my_decorator(capsys):
say_hello()
captured = capsys.readouterr()
assert captured.out == "Something is happening before the function is called.\nHello!\n... | [
{
"docstring": "A simple decorator that prints a message before and after the execution of the function.",
"function_declaration": "def my_decorator(func):",
"function_name": "my_decorator",
"parameter_list": "(func)"
},
{
"docstring": null,
"function_declaration": "def say_hello():",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def my_decorator(func):\n \"\"\"\n A simple decorator that modifies the behavior of the function it wraps.\n \"\"\"\n def wrapper():\n print(\"Something is happening before ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061565",
"row_id": 61565,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124469']"
} | 0.456887 | Filter_61565 | I | [
"my_decorator",
"say_hello",
"decoration_with_argument",
"say_python"
] | 4 | [
[
"say_python",
"decoration_with_argument"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4338228c3631be1d3056e8ed027c07d5eff05df | 20e39b21bd111f30e27415488603a97d4e420a13 | |||
v1.0 | instruct | Filter | Filter_61584_I | How can I implement a calculator in Python that can handle complex mathematical expressions, including nested brackets and parentheses? | import re
def tokenize(expression):
"""
Convert the mathematical expression into a list of tokens.
"""
tokens = re.findall(r'\d+\.?\d*|[-+*/()]', expression)
return tokens
def evaluate_expression(tokens):
"""
Evaluate the provided tokens representing a mathematical expression.
"""
... | from solution import calculator
def test_calculator_simple_addition():
assert calculator("2 + 3") == 5
def test_calculator_simple_subtraction():
assert calculator("10 - 5") == 5
def test_calculator_simple_multiplication():
assert calculator("4 * 5") == 20
def test_calculator_simple_division():
asser... | [
{
"docstring": "Convert the mathematical expression into a list of tokens.",
"function_declaration": "def tokenize(expression):",
"function_name": "tokenize",
"parameter_list": "(expression)"
},
{
"docstring": "Evaluate the provided tokens representing a mathematical expression.",
"funct... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef tokenize(expression):\n \"\"\"\n Convert the mathematical expression into a list of tokens.\n \"\"\"\n tokens = re.findall(r'\\d+\\.?\\d*|[-+*/()]', expression)\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061584",
"row_id": 61584,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124510']"
} | 0.596873 | Filter_61584 | I | [
"tokenize",
"evaluate_expression",
"calculator"
] | 3 | [
[
"calculator",
"evaluate_expression"
],
[
"calculator",
"tokenize"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 460f35573b4748440a6dafd809c7dea1d69bb2d5 | 84487245ff7d2bbdc69fff8d23ebd06ab78624a1 | |||
v1.0 | instruct | Filter | Filter_61587_I | I need help with a Python script that processes a large set of text data. The task involves reading a CSV file with multiple rows and columns, where one column contains text data. I need to preprocess the text data by removing punctuation, converting all text to lowercase, and tokenizing the text into words. I then wan... | import csv
import string
from collections import Counter
def preprocess_text(text):
"""
Preprocesses the text by removing punctuation, converting to lowercase, and tokenizing.
"""
# Remove punctuation
text = text.translate(str.maketrans('', '', string.punctuation))
# Convert to lowercase
te... | import pytest
from solution import preprocess_text, read_and_process_csv
from collections import Counter
import os
def test_preprocess_text():
text = "Hello, World! This is a test."
expected_result = ["hello", "world", "this", "is", "a", "test"]
assert preprocess_text(text) == expected_result
def test_rea... | [
{
"docstring": "Preprocesses the text by removing punctuation, converting to lowercase, and tokenizing.",
"function_declaration": "def preprocess_text(text):",
"function_name": "preprocess_text",
"parameter_list": "(text)"
},
{
"docstring": "Reads a CSV file, preprocesses the text data, and ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pandas as pd\nimport string\nfrom collections import Counter\n\ndef preprocess_text(text):\n \"\"\"\n Preprocess the text by removing punctuation, converting to lowercase, and tok... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00061587",
"row_id": 61587,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124515']"
} | 0.737917 | Filter_61587 | I | [
"preprocess_text",
"read_and_process_csv"
] | 2 | [
[
"read_and_process_csv",
"preprocess_text"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2ac4f3b9774ec2deb615d62e855c974e96d66f2d | fc79e6b000ee6d18e0c69837cbed36accee89c30 | |||
v1.0 | instruct | Filter | Filter_61593_I | Generate a Python code snippet that demonstrates how to create a simple calculator that can perform addition, subtraction, multiplication, and division. This calculator should take user input from the command line and display the result. | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b != 0:
return a / b
else:
return "Error: Division by zero is not allowed."
def calculator():
print("Simple Calculator")
a = float(input("Enter the first num... | from solution import add, subtract, multiply, divide
def test_add():
assert add(3, 4) == 7
assert add(-1, -2) == -3
assert add(0, 0) == 0
assert add(7, -3) == 4
def test_subtract():
assert subtract(10, 4) == 6
assert subtract(4, 10) == -6
assert subtract(0, 0) == 0
assert subtract(-3, ... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061593",
"row_id": 61593,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124531']"
} | 0.577638 | Filter_61593 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | fe270b6badcd3c86ab4c2b734eb16b3038c1a2b9 | 0d1f8c8e1163c37a52f118f901d035af1534a3e2 | |||
v1.0 | instruct | Filter | Filter_61606_I | How can I implement a K-Means Clustering algorithm from scratch in Python without using any external libraries? | import random
import math
def euclidean_distance(point1, point2):
"""
Computes the Euclidean Distance between two points.
"""
return math.sqrt(sum((x1 - x2) ** 2 for x1, x2 in zip(point1, point2)))
def initialize_centroids(k, data):
"""
Randomly initializes the centroids from the data points.
... | from solution import euclidean_distance, initialize_centroids, assign_clusters, compute_centroids, k_means_clustering
def test_euclidean_distance():
assert euclidean_distance([1, 2], [4, 6]) == 5.0
assert euclidean_distance([1, 1], [1, 1]) == 0.0
def test_initialize_centroids():
data = [[1, 2], [3, 4], [5... | [
{
"docstring": "Computes the Euclidean Distance between two points.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Randomly initializes the centroids from the data points.",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt(sum((p1 - p2) ** 2... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061606",
"row_id": 61606,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124568']"
} | 0.63483 | Filter_61606 | I | [
"euclidean_distance",
"initialize_centroids",
"assign_clusters",
"compute_centroids",
"k_means_clustering"
] | 5 | [
[
"assign_clusters",
"euclidean_distance"
],
[
"k_means_clustering",
"assign_clusters"
],
[
"k_means_clustering",
"compute_centroids"
],
[
"k_means_clustering",
"initialize_centroids"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 1554f1cf4d937d7905d3e61558a1d74f95f692da | 775f54907b0aa32477a345d5d5c0b8baac282be6 | |||
v1.0 | instruct | Filter | Filter_61615_I | Write a Python script to create a simple calculator that can perform basic arithmetic operations like addition, subtraction, multiplication, and division. The script should take user input for the operation and the numbers involved, and display the result. | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero!")
return a / b
def calculator(operation, a, b):
if operation == 'add':
return add(a, b)
elif operation == 's... | import pytest
from solution import add, subtract, multiply, divide, calculator
def test_add():
assert add(2, 3) == 5
assert add(-1, -1) == -2
assert add(0, 5) == 5
def test_subtract():
assert subtract(3, 2) == 1
assert subtract(3, 5) == -2
assert subtract(3, 0) == 3
def test_multiply():
a... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00061615",
"row_id": 61615,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124589']"
} | 0.626297 | Filter_61615 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 54b1499dadb3f22993e8a17f9480e84c8221df4c | c06445010428d6631593f82913c8233703a62228 | |||
v1.0 | instruct | Filter | Filter_61652_I | Can you explain how the merge sort algorithm works in Python, and perhaps provide a simple implementation? | def merge_sort(arr):
"""
Sorts an array using the merge sort algorithm.
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[mid:]
# Recursively sort both halves
left_sorted = merge_sort(left_half)
right_sorted = merge_sort(right_h... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted():
assert merge_sort([5,... | [
{
"docstring": "Sorts an array using the merge sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"function_declaration": "def merge(left, right):",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array using the merge sort algorithm.\n\n Parameters:\n arr (list): The list of elements to be sorted.\n \n Returns:\n lis... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00061652",
"row_id": 61652,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124670']"
} | 0.540709 | Filter_61652 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9258ae4321c64915addc0e5afb0bf053ccc2a043 | 62067438706fe78bb2c08708726d41c3fd243f33 | |||
v1.0 | instruct | Filter | Filter_61664_I | Can you provide a Python script that checks for duplicate files based on their content in a given directory? | import os
import hashlib
def hash_file(file_path):
"""
Returns the SHA-256 hash of the file content.
"""
hasher = hashlib.sha256()
with open(file_path, 'rb') as f:
buf = f.read()
hasher.update(buf)
return hasher.hexdigest()
def find_duplicate_files(directory):
"""
Finds... | import os
import tempfile
from solution import find_duplicate_files
def create_temp_file(directory, filename, content):
with open(os.path.join(directory, filename), 'w') as file:
file.write(content)
def test_find_no_duplicates():
with tempfile.TemporaryDirectory() as tmpdir:
create_temp_file(t... | [
{
"docstring": "Returns the SHA-256 hash of the file content.",
"function_declaration": "def hash_file(file_path):",
"function_name": "hash_file",
"parameter_list": "(file_path)"
},
{
"docstring": "Finds duplicate files in the given directory based on their content hash.\nReturns a dictionar... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport hashlib\n\ndef get_file_hash(file_path):\n \"\"\"\n Returns the SHA-1 hash of the file content.\n \"\"\"\n hash_sha1 = hashlib.sha1()\n with open(file_path, 'r... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00061664",
"row_id": 61664,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124699']"
} | 0.628062 | Filter_61664 | I | [
"hash_file",
"find_duplicate_files"
] | 2 | [
[
"find_duplicate_files",
"hash_file"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e833daf6327a6475672c9d130643a29588e0e8a2 | c598031638a8c0f302202df227c7279177ec8f61 | |||
v1.0 | instruct | Filter | Filter_61678_I | How can I create a Python script that uses multiprocessing to process a large list of numbers and find the sum of each sublist in parallel? | from multiprocessing import Pool
def sum_sublist(sublist):
"""
Returns the sum of the sublist.
"""
return sum(sublist)
def parallel_sum_sublists(lists, num_processes):
"""
Uses multiprocessing to find the sum of each sublist.
Parameters:
lists (list of list of int): A list contain... | from solution import sum_sublist, parallel_sum_sublists
def test_sum_sublist():
assert sum_sublist([1, 2, 3]) == 6
assert sum_sublist([0, 0, 0]) == 0
assert sum_sublist([-1, -2, -3]) == -6
assert sum_sublist([]) == 0
def test_parallel_sum_sublists():
lists = [[1, 2], [3, 4], [5, 6]]
expected =... | [
{
"docstring": "Returns the sum of the sublist.",
"function_declaration": "def sum_sublist(sublist):",
"function_name": "sum_sublist",
"parameter_list": "(sublist)"
},
{
"docstring": "Uses multiprocessing to find the sum of each sublist.\n\nParameters:\nlists (list of list of int): A list co... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from multiprocessing import Pool\n\ndef sum_sublist(sublist):\n \"\"\"\n Returns the sum of a sublist.\n \"\"\"\n return sum(sublist)\n\ndef process_large_list_of_numbers(numbers, ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061678",
"row_id": 61678,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124728']"
} | 0.573105 | Filter_61678 | I | [
"sum_sublist",
"parallel_sum_sublists"
] | 2 | [
[
"parallel_sum_sublists",
"sum_sublist"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3429fe15129792ba092774927cf4a93ccdfc37aa | 3131f48eeae7faf6b1ffd7faf0da49c81b9993b9 | |||
v1.0 | instruct | Filter | Filter_61761_I | I have a list of integers and I need to find all the prime numbers in it. How can I do this in Python? | def is_prime(num):
"""
Returns True if the number is a prime number, otherwise returns False.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def find_primes(lst):
"""
Returns a list of prime numbe... | from solution import is_prime, find_primes
def test_is_prime():
assert not is_prime(-1)
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
def test_find_primes():
assert find_primes([]) == []
assert find_pri... | [
{
"docstring": "Returns True if the number is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers from the given list of integers.",
"function_de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \n Parameters:\n n (int): The number to check.\n \n Returns:\n bool: True if n is a prime number, False other... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061761",
"row_id": 61761,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124912']"
} | 0.651247 | Filter_61761 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9acdaa64ce3c6e759825b57bb1262dd88f208bce | e3258e7af91086fa4302f29f9ee322a41979376a | |||
v1.0 | instruct | Filter | Filter_61783_I | I'm trying to run a script that formats my JSON data into a CSV file. My JSON data contains nested objects and arrays. How can I handle nested structures in JSON when converting to CSV in Python? | import csv
import json
from collections.abc import MutableMapping
def flatten_json(nested_json, parent_key='', separator='_'):
"""
Flattens a nested JSON dictionary.
Parameters:
nested_json (dict): The JSON to flatten
parent_key (str): The base prefix for keys
separator (str): The separator be... | import json
import os
import csv
from solution import json_to_csv, flatten_json
def test_flatten_json():
nested_json = {
"name": "John",
"address": {
"city": "New York",
"postcode": 10001
},
"phones": ["123-456-7890", "987-654-3210"],
"is_active": Tru... | [
{
"docstring": "Flattens a nested JSON dictionary.\n\nParameters:\nnested_json (dict): The JSON to flatten\nparent_key (str): The base prefix for keys\nseparator (str): The separator between keys\n\nReturns:\ndict: A flattened dictionary",
"function_declaration": "def flatten_json(nested_json, parent_key=''... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nimport json\nfrom collections.abc import MutableMapping\n\ndef flatten_json(nested_json, parent_key='', separator='_'):\n \"\"\"\n Flattens a nested JSON dictionary.\n\n P... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061783",
"row_id": 61783,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124951']"
} | 0.653094 | Filter_61783 | I | [
"flatten_json",
"json_to_csv"
] | 2 | [
[
"json_to_csv",
"flatten_json"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c3b61c8c630b7357de674076768065f220245a1 | b8130ea087ec72d57455ea97167e12c270d32ad9 | |||
v1.0 | instruct | Filter | Filter_61790_I | I'm looking for a simple Python script to automate the process of downloading images from URLs listed in a CSV file. The CSV file should have a column named "Image URL" that contains the URLs of the images to be downloaded. The downloaded images should be saved in a specified directory. How can I achieve this? | import csv
import requests
import os
from urllib.parse import urlparse
def download_images_from_csv(csv_file_path, download_directory):
"""
Downloads images from URLs listed in a CSV file and saves them to a specified directory.
:param csv_file_path: Path to the CSV file containing image URLs.
:param ... | import os
import shutil
import pytest
from unittest.mock import patch, mock_open
from solution import download_images_from_csv, download_image
@pytest.fixture
def setup_csv(tmp_path):
# Setup a temporary CSV file with image URLs
csv_content = """Image URL
http://example.com/image1.jpg
http://example.com/image2... | [
{
"docstring": "Downloads images from URLs listed in a CSV file and saves them to a specified directory.\n\n:param csv_file_path: Path to the CSV file containing image URLs.\n:param download_directory: Directory where the images will be saved.",
"function_declaration": "def download_images_from_csv(csv_file... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nimport requests\nimport os\nfrom urllib.parse import urlparse\n\ndef download_images_from_csv(csv_file_path, download_directory):\n \"\"\"\n Downloads images from URLs listed... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061790",
"row_id": 61790,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124963']"
} | 0.568764 | Filter_61790 | I | [
"download_images_from_csv",
"download_image"
] | 2 | [
[
"download_images_from_csv",
"download_image"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | fc83596f7578406db9e5e2c426cdb50411dec78b | 517e6266faea2eb521e8d575d057fba24acb4145 | |||
v1.0 | instruct | Filter | Filter_61804_I | Can you provide a Python script that automatically personalizes email content based on recipient information and sends it to multiple recipients? | import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(sender, sender_password, recipient, subject, body):
"""
Sends an email to the given recipient.
Args:
sender (str): Sender's email address.
sender_password (str): Sender's email pas... | from solution import send_email, personalize_and_send_emails
def test_send_email(monkeypatch):
# Mock smtplib.SMTP to avoid sending real emails during tests
class MockSMTP:
def __init__(self, *args, **kwargs):
pass
def starttls(self):
pass
def login(self, user, p... | [
{
"docstring": "Sends an email to the given recipient.\n\nArgs:\nsender (str): Sender's email address.\nsender_password (str): Sender's email password.\nrecipient (str): Recipient's email address.\nsubject (str): Subject of the email.\nbody (str): Body of the email.",
"function_declaration": "def send_email... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ndef personalize_email_content(template, recipient_info):\n \"\"\"\n Personalizes t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061804",
"row_id": 61804,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_124989']"
} | 0.481517 | Filter_61804 | I | [
"send_email",
"personalize_and_send_emails"
] | 2 | [
[
"personalize_and_send_emails",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5772b542a0f20377b7319ac40d186de1422362d0 | 21c4949ac120e61bd1f4f080c5d1a0c0050699ab | |||
v1.0 | instruct | Filter | Filter_61864_I | Can you explain how to solve the problem of finding the largest palindrome product of two 3-digit numbers in Python? | def is_palindrome(n):
"""
Check if a given integer n is a palindrome.
"""
return str(n) == str(n)[::-1]
def largest_palindrome_product():
"""
Find the largest palindrome product of two 3-digit numbers.
"""
max_palindrome = 0
for i in range(100, 1000):
for j in range(100, 100... | from solution import is_palindrome, largest_palindrome_product
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(1001) == True
assert is_palindrome(1234321) == True
assert is_palindrome(1234432... | [
{
"docstring": "Check if a given integer n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find the largest palindrome product of two 3-digit numbers.",
"function_declaration": "def largest_p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Checks if a given number n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef largest_palindrome_product():\n \"\"\"\n Finds th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061864",
"row_id": 61864,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125112']"
} | 0.679875 | Filter_61864 | I | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3c94c2f064c46b4c2d8a0b025da46acb6d9fc5e | 7ff3a22893901a88c1769ba08ad22dbae03e5d93 | |||
v1.0 | instruct | Filter | Filter_61872_I | Write a Python script to compare two lists and find the elements that are common to both lists. The script should also handle cases where the lists contain nested lists and should find common elements at all levels of nesting. | def flatten_list(l):
"""
Flatten a nested list.
"""
flat_list = []
for item in l:
if isinstance(item, list):
flat_list.extend(flatten_list(item))
else:
flat_list.append(item)
return flat_list
def common_elements(list1, list2):
"""
Find common elem... | from solution import flatten_list, common_elements
def test_flatten_list_simple():
assert flatten_list([1, 2, 3]) == [1, 2, 3]
def test_flatten_list_nested():
assert flatten_list([1, [2, 3], [4, [5, 6]]]) == [1, 2, 3, 4, 5, 6]
def test_flatten_list_empty():
assert flatten_list([]) == []
def test_common_... | [
{
"docstring": "Flatten a nested list.",
"function_declaration": "def flatten_list(l):",
"function_name": "flatten_list",
"parameter_list": "(l)"
},
{
"docstring": "Find common elements between two lists, including nested lists.",
"function_declaration": "def common_elements(list1, list2... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def flatten_list(l):\n \"\"\"\n Flatten a nested list.\n \"\"\"\n flat_list = []\n for item in l:\n if isinstance(item, list):\n flat_list.extend(flatten_list(... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061872",
"row_id": 61872,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125137']"
} | 0.728073 | Filter_61872 | I | [
"flatten_list",
"common_elements"
] | 2 | [
[
"common_elements",
"flatten_list"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 619d9502239b17b8ecbc001ca9e5e1e01f939c14 | 9a7b428d85294a0d03484b40e3b8aa384f29953e | |||
v1.0 | instruct | Filter | Filter_61884_I | Given a string, generate all possible palindromic partitions of the string. | def is_palindrome(s):
"""
Check if the string s is a palindrome.
"""
return s == s[::-1]
def palindromic_partitions(s):
"""
Generate all possible palindromic partitions of the string s.
"""
result = []
def backtrack(start, path):
if start == len(s):
result.a... | from solution import is_palindrome, palindromic_partitions
def test_is_palindrome():
assert is_palindrome("madam")
assert is_palindrome("racecar")
assert is_palindrome("a")
assert is_palindrome("aa")
assert not is_palindrome("hello")
assert not is_palindrome("world")
assert is_palindrome(""... | [
{
"docstring": "Check if the string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Generate all possible palindromic partitions of the string s.",
"function_declaration": "def palindromic_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palindromic_partitions(s):\n \"\"\"\n Generate al... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00061884",
"row_id": 61884,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125161']"
} | 0.678457 | Filter_61884 | I | [
"is_palindrome",
"palindromic_partitions"
] | 2 | [
[
"palindromic_partitions",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 08ce1e69a6ca962d9fb36d018ff7554cb67f6c47 | b54c27473d0575c5f6a68f01c70d81c427f9f2b1 | |||
v1.0 | instruct | Filter | Filter_61903_I | Write a Python program that utilizes a generator to generate the first 'n' prime numbers. The program should include a helper function to check if a number is prime and the main function to generate the primes using a generator. Additionally, include a function to test the correctness of the prime generator by comparin... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tr... | from solution import is_prime, prime_generator, get_first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(19) == True
assert... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate the first 'n' prime numbers.",
"function_declaration": "def prime_generator(n):",
"function_name": "prime_generat... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if nu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00061903",
"row_id": 61903,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125196']"
} | 0.644872 | Filter_61903 | I | [
"is_prime",
"prime_generator",
"get_first_n_primes"
] | 3 | [
[
"get_first_n_primes",
"prime_generator"
],
[
"prime_generator",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 14cb4010bfecc9fa2cdfdfad145bf12114e2c0b1 | 89978c2f615af4e4fd6bfb49585176697275ad17 | |||
v1.0 | instruct | Filter | Filter_61914_I | Can you provide a Python function to check if a number is a prime number and also list all prime numbers up to a given number? | def is_prime(n):
"""
Check if a number is prime.
Params:
n (int): The number to check.
Returns:
bool: True if n is prime, False otherwise.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return Tr... | from solution import is_prime, list_primes_up_to
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-1) == False
def test_list_primes_u... | [
{
"docstring": "Check if a number is prime.\n\nParams:\nn (int): The number to check.\n\nReturns:\nbool: True if n is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "List all prime numbers up to a g... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \n Params:\n n (int): The number to check.\n \n Returns:\n bool: True if n is prime, False otherwise.\n \"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061914",
"row_id": 61914,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125220']"
} | 0.73156 | Filter_61914 | I | [
"is_prime",
"list_primes_up_to"
] | 2 | [
[
"list_primes_up_to",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efa00c5b738d42611f5c229f48a349594e145ed2 | fc8b8bdcea5e20d5e0cc0a9797107499dba594cb | |||
v1.0 | instruct | Filter | Filter_61957_I | Can I create a custom weather widget for my website using Python? | from flask import Flask, render_template, request
import requests
app = Flask(__name__)
def get_weather(city):
"""
Fetch weather data for a specified city using OpenWeatherMap API.
"""
API_KEY = 'your_openweathermap_api_key' # replace with your OpenWeatherMap API key
URL = f'http://api.openweathe... | import requests
from unittest.mock import patch
from solution import get_weather
def test_get_weather():
city = "London"
api_key = 'your_openweathermap_api_key'
URL = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric'
mock_response = {
"coord": {"lon": ... | [
{
"docstring": "Fetch weather data for a specified city using OpenWeatherMap API.",
"function_declaration": "def get_weather(city):",
"function_name": "get_weather",
"parameter_list": "(city)"
},
{
"docstring": null,
"function_declaration": "def home():",
"function_name": "home",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, render_template, request\nimport requests\n\napp = Flask(__name__)\n\ndef get_weather(city):\n \"\"\"\n Fetch weather data for a specified city using OpenWeather... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061957",
"row_id": 61957,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125305']"
} | 0.364568 | Filter_61957 | I | [
"get_weather",
"home",
"weather"
] | 3 | [
[
"weather",
"get_weather"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask",
"requests"
] | false | 6cc59cb5effaac58da5a1ffaf9e1521935222d1c | 330133245785bcfc6964bb59776337cc96aa17cc | |||
v1.0 | instruct | Filter | Filter_61975_I | Can you provide a Python code snippet that demonstrates a simple daily notification system using Python? | import datetime
import time
def send_daily_notification(notification_message):
"""
Sends a simple daily notification message.
"""
print(f"Notification: {notification_message}")
def daily_notification_system(notification_message, notification_time):
"""
Sends a daily notification at the specifi... | from solution import send_daily_notification, daily_notification_system
import datetime
import threading
import time
def test_send_daily_notification(capsys):
send_daily_notification("Test Notification")
captured = capsys.readouterr()
assert "Notification: Test Notification" in captured.out
def test_daily... | [
{
"docstring": "Sends a simple daily notification message.",
"function_declaration": "def send_daily_notification(notification_message):",
"function_name": "send_daily_notification",
"parameter_list": "(notification_message)"
},
{
"docstring": "Sends a daily notification at the specified tim... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import datetime\nimport time\n\ndef send_daily_notification(notification_message):\n \"\"\"\n Sends a simple daily notification message.\n \"\"\"\n print(f\"Notification: {notifica... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00061975",
"row_id": 61975,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125345']"
} | 0.436615 | Filter_61975 | I | [
"send_daily_notification",
"daily_notification_system"
] | 2 | [
[
"daily_notification_system",
"send_daily_notification"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4c25b78487940d3964ab7152b846c728b243e47 | 994f97107f6e07088461986c4ba31e6c1835f959 | |||
v1.0 | instruct | Filter | Filter_62022_I | I want to create an AI player for a 2D platform game using a simple neural network to learn and improve. The game has a simple layout with only three types of blocks: flat ground, walls, and bottomless pits. The player character can jump, move left, move right, or do nothing. The goal is to reach the end of the platfor... | import numpy as np
import random
class NeuralNetwork:
def __init__(self, input_size, hidden_size, output_size):
self.input_size = input_size
self.hidden_size = hidden_size
self.output_size = output_size
self.weights1 = np.random.randn(input_size, hidden_size)
self.weights2 =... | from solution import NeuralNetwork, create_ai_player_input, integrate_ai_player
import numpy as np
def test_neural_network_initialization():
nn = NeuralNetwork(input_size=5, hidden_size=5, output_size=4)
assert nn.input_size == 5
assert nn.hidden_size == 5
assert nn.output_size == 4
assert nn.weigh... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport random\n\nclass NeuralNetwork:\n def __init__(self, input_size, hidden_size, output_size):\n self.input_size = input_size\n self.hidden_size = hidde... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062022",
"row_id": 62022,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125431']"
} | 0.341077 | Filter_62022 | I | [
"create_ai_player_input",
"integrate_ai_player"
] | 2 | [
[
"integrate_ai_player",
"create_ai_player_input"
]
] | 1 | [] | false | [
"NeuralNetwork"
] | true | pytest | true | [
"numpy"
] | false | c1b8687d4f394d43e0466b4154f42bd5d75ed562 | 98db1a96984dedb9eb5ce00df61e082a0dbddf1b | |||
v1.0 | instruct | Filter | Filter_62027_I | Can you provide a Python code snippet that reads a CSV file, processes the data, and writes the processed data back to a new CSV file? Please include error handling and assume the CSV file has a header row. | import csv
def process_data(row):
"""
Process a row of data. Here we simply convert all string fields to uppercase.
Modify this function based on your specific processing needs.
"""
return [field.upper() for field in row]
def read_process_write_csv(input_filepath, output_filepath):
"""
Rea... | from solution import read_process_write_csv
import os
import csv
def create_csv(filepath, header, rows):
"""
Helper function to create a CSV file for testing purposes.
"""
with open(filepath, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow(head... | [
{
"docstring": "Process a row of data. Here we simply convert all string fields to uppercase.\nModify this function based on your specific processing needs.",
"function_declaration": "def process_data(row):",
"function_name": "process_data",
"parameter_list": "(row)"
},
{
"docstring": "Reads... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\n\ndef process_csv(input_file, output_file, process_row):\n \"\"\"\n Reads a CSV file, processes the data using a provided function, and writes the processed data to a new CSV... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062027",
"row_id": 62027,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125441']"
} | 0.634452 | Filter_62027 | I | [
"process_data",
"read_process_write_csv"
] | 2 | [
[
"read_process_write_csv",
"process_data"
]
] | 1 | [
"process_data"
] | false | [] | false | pytest | true | [] | true | 5abbc9e00027a539379f9b6bdf7a743c16386e76 | 5dd7467dc7d27afa8e6531f5d8fc43d62d489406 | |||
v1.0 | instruct | Filter | Filter_62031_I | Can you provide a Python code snippet that prints the first 10 prime numbers using a list comprehension? | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def first_n_primes(n):
"""
Returns the first n prime numbers.
"""
primes ... | from solution import is_prime, first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
def test_first_n_primes():
... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_na... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062031",
"row_id": 62031,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125450']"
} | 0.56657 | Filter_62031 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d6cc4fa716f71cd5c558906469f96ff70f53b961 | a33d696b1b10d2fed8b904b4e85ed3c9877de267 | |||
v1.0 | instruct | Filter | Filter_62033_I | How can I generate a sitemap for a website using Python? | import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
import xml.etree.ElementTree as ET
def is_valid_url(url):
parsed = urlparse(url)
return bool(parsed.netloc) and bool(parsed.scheme)
def get_all_website_links(url):
urls = set()
domain_name = urlparse(url).netloc
... | import os
import re
from solution import is_valid_url, get_all_website_links, generate_sitemap_xml
def test_is_valid_url():
assert is_valid_url("https://example.com") == True
assert is_valid_url("ftp://example.com") == True
assert is_valid_url("example.com") == False
assert is_valid_url("http:///exampl... | [
{
"docstring": null,
"function_declaration": "def is_valid_url(url):",
"function_name": "is_valid_url",
"parameter_list": "(url)"
},
{
"docstring": null,
"function_declaration": "def get_all_website_links(url):",
"function_name": "get_all_website_links",
"parameter_list": "(url)"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom bs4 import BeautifulSoup\n\ndef get_internal_links(url, domain):\n \"\"\"\n Returns a set of internal links found on the given URL.\n \"\"\"\n internal_links ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062033",
"row_id": 62033,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125454']"
} | 0.492511 | Filter_62033 | I | [
"is_valid_url",
"get_all_website_links",
"generate_sitemap_xml"
] | 3 | [
[
"generate_sitemap_xml",
"get_all_website_links"
],
[
"get_all_website_links",
"is_valid_url"
]
] | 2 | [] | false | [] | false | pytest | true | [
"bs4",
"requests"
] | false | 307577304e6bfd78f22b01a9824fed3f1b7b0670 | 58313a619cb16a03ec9169d2ca0422f324567246 | |||
v1.0 | instruct | Filter | Filter_62042_I | Can you help me create a Python code that generates a Koch curve using the turtle graphics library? | import turtle
def koch_curve(t, order, size):
"""
Draws a Koch curve using turtle graphics.
Parameters:
t (turtle.Turtle): The turtle object used to draw.
order (int): The recursion depth of the curve.
size (float): The length of each segment of the curve.
"""
if order ... | from solution import koch_curve, draw_koch_curve
from unittest.mock import Mock
def test_koch_curve_order_0():
t = Mock()
koch_curve(t, 0, 100)
t.forward.assert_called_once_with(100)
def test_koch_curve_order_1():
t = Mock()
koch_curve(t, 1, 100)
expected_calls = [
(t.forward, [33.3333... | [
{
"docstring": "Draws a Koch curve using turtle graphics.\n\nParameters:\n t (turtle.Turtle): The turtle object used to draw.\n order (int): The recursion depth of the curve.\n size (float): The length of each segment of the curve.",
"function_declaration": "def koch_curve(t, order, size):",
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import turtle\n\ndef koch_curve(t, order, size):\n \"\"\"\n Draws a Koch curve using turtle graphics.\n \n Parameters:\n t (turtle.Turtle): The turtle object used to draw.\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062042",
"row_id": 62042,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125471']"
} | 0.523897 | Filter_62042 | I | [
"koch_curve",
"draw_koch_curve"
] | 2 | [
[
"draw_koch_curve",
"koch_curve"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c74715b76e389659a05172158773f6e05f81f7e2 | 2560b0b27257136a6649ce3ac4d3d8a95ed6cfb2 | |||
v1.0 | instruct | Filter | Filter_62047_I | I need to write a Python script to filter and process files in two different directories. The script should move files that match a specific pattern from one directory to another. Additionally, it should log the process in a detailed log file. Could you provide a sample script to achieve this? | import os
import shutil
import re
import logging
def setup_logging(log_file):
"""
Sets up the logging configuration.
"""
logging.basicConfig(filename=log_file, level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
def move_files_with_pattern(src_dir, dst_dir,... | import os
import pytest
from solution import move_files_with_pattern
@pytest.fixture
def setup_directories(tmpdir):
src = tmpdir.mkdir("src")
dst = tmpdir.mkdir("dst")
return src, dst
def test_move_matching_files(setup_directories, tmpdir):
src, dst = setup_directories
log_file = tmpdir.join("proc... | [
{
"docstring": "Sets up the logging configuration.",
"function_declaration": "def setup_logging(log_file):",
"function_name": "setup_logging",
"parameter_list": "(log_file)"
},
{
"docstring": "Moves files that match a specific pattern from src_dir to dst_dir and logs the process.",
"func... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\nimport re\nimport logging\n\ndef setup_logging(log_file):\n \"\"\"\n Sets up the logging configuration.\n \"\"\"\n logging.basicConfig(filename=log_file, ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062047",
"row_id": 62047,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125489']"
} | 0.694189 | Filter_62047 | I | [
"setup_logging",
"move_files_with_pattern"
] | 2 | [
[
"move_files_with_pattern",
"setup_logging"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2e1cb91a9f7dba499782f403e9fc973f3191986e | 98ba15ab32499fc1bd0272e9730c308bdf138008 | |||
v1.0 | instruct | Filter | Filter_62050_I | Can you provide a Python code snippet that demonstrates how to use a generator expression to find all prime numbers between 1 and 100? | def is_prime(n):
"""
Helper function to determine if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes_between_1_and_100():
"""
Generator expression to find all prime numbers ... | from solution import is_prime, primes_between_1_and_100
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_primes_be... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generator expression to find all prime numbers between 1 and 100.",
"function_declaration": "def primes... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number `n` is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062050",
"row_id": 62050,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125493']"
} | 0.545554 | Filter_62050 | I | [
"is_prime",
"primes_between_1_and_100"
] | 2 | [
[
"primes_between_1_and_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2816856a8ed2b70ad8a4af25e7228480745f4a7b | 3009cc2c4723769514d0f1a29c9e9d5ab284167d | |||
v1.0 | instruct | Filter | Filter_62061_I | How can I implement an efficient algorithm to solve the 8-puzzle problem using the A* search algorithm in Python? | import heapq
class PuzzleState:
def __init__(self, board, parent=None, move=0, cost=0):
self.board = board
self.parent = parent
self.move = move
self.cost = cost
self.empty_pos = self.board.index(0)
if parent:
self.cost += parent.cost
def __lt__(self... | from solution import PuzzleState, a_star
def test_8_puzzle_solvable():
start_board = [1, 2, 3, 4, 0, 5, 6, 7, 8]
goal_board = [1, 2, 3, 4, 5, 6, 7, 8, 0]
start_state = PuzzleState(start_board)
goal_state = PuzzleState(goal_board)
solution_path = a_star(start_state, goal_state)
assert solution_p... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\nclass PuzzleState:\n def __init__(self, board, parent=None, move=0, cost=0):\n self.board = board\n self.parent = parent\n self.move = move\n sel... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062061",
"row_id": 62061,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125511']"
} | 0.458012 | Filter_62061 | I | [
"heuristic",
"a_star"
] | 2 | [
[
"a_star",
"heuristic"
]
] | 1 | [] | false | [
"PuzzleState"
] | true | pytest | true | [] | true | c2785bd2777e152ecc22d21e30452a2d97d997b2 | 0b5c62c9170b16b84e1a06801620aaa6fe05f379 | |||
v1.0 | instruct | Filter | Filter_62109_I | What is the correct syntax for defining and using a function in Python? | def function_name(parameters):
"""
This is a sample function that performs some operation.
parameters can be any number of arguments separated by a comma.
"""
# Function body: Perform some operations and optionally return a value
result = operation(parameters)
return result
def operati... | from solution import function_name
def test_function_with_no_parameters():
assert function_name([]) == 0 # Assuming the function defined in the solution works with a list of parameters and returns their sum
def test_function_with_positive_numbers():
assert function_name([1, 2, 3]) == 6 # The expected result... | [
{
"docstring": "This is a sample function that performs some operation.\n\nparameters can be any number of arguments separated by a comma.",
"function_declaration": "def function_name(parameters):",
"function_name": "function_name",
"parameter_list": "(parameters)"
},
{
"docstring": null,
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def greet(name):\n \"\"\"\n Returns a greeting string for the given name.\n \"\"\"\n return f\"Hello, {name}!\"",
"test_code": "from solution import greet\n\ndef test_greet_per... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062109",
"row_id": 62109,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125600']"
} | 0.472976 | Filter_62109 | I | [
"function_name",
"operation"
] | 2 | [
[
"function_name",
"operation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ce04b58b28ef0467996f67aa1c2af911ea7633a1 | 0b5dbc106099721e2109ec961ad31fe5d81dadec | |||
v1.0 | instruct | Filter | Filter_62116_I | Can you provide a code snippet for simulating a DHCP server in Python that responds to DHCPDISCOVER messages? | import socket
def send_dhcp_offer(client_socket, client_address, transaction_id):
"""
This function sends a DHCPOFFER message to the client.
"""
dhcp_offer = create_dhcp_offer(transaction_id)
client_socket.sendto(dhcp_offer, client_address)
def create_dhcp_offer(transaction_id):
"""
Create... | # Since this is a network service and involves UDP communication, providing a simple unit test isn't straightforward.
# However, we'll provide tests for the auxiliary functions.
from solution import create_dhcp_offer, is_dhcp_discover, get_transaction_id
def test_create_dhcp_offer():
transaction_id = b'1234'
... | [
{
"docstring": "This function sends a DHCPOFFER message to the client.",
"function_declaration": "def send_dhcp_offer(client_socket, client_address, transaction_id):",
"function_name": "send_dhcp_offer",
"parameter_list": "(client_socket, client_address, transaction_id)"
},
{
"docstring": "C... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import socket\nimport struct\n\ndef create_dhcp_discover():\n \"\"\"\n Create a DHCPDISCOVER message to simulate a client request.\n \"\"\"\n # Ethernet frame header\n eth_heade... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062116",
"row_id": 62116,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125609']"
} | 0.492403 | Filter_62116 | I | [
"send_dhcp_offer",
"create_dhcp_offer",
"simulate_dhcp_server",
"is_dhcp_discover",
"get_transaction_id"
] | 5 | [
[
"send_dhcp_offer",
"create_dhcp_offer"
],
[
"simulate_dhcp_server",
"get_transaction_id"
],
[
"simulate_dhcp_server",
"is_dhcp_discover"
],
[
"simulate_dhcp_server",
"send_dhcp_offer"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 755c297eb03c9336ec65eb6acc22744651ed3cd4 | cb8bf86a18d3fe5098d82ed625edb95a52fb93af | |||
v1.0 | instruct | Filter | Filter_62148_I | I need to create a script in Python that periodically checks if a specific process is running and restarts it if it is not. This script needs to be scheduled to run at regular intervals, say every 5 minutes. How can I achieve this? | import os
import time
import subprocess
def is_process_running(process_name):
"""
Checks if a process with the given name is running.
"""
try:
# Use pgrep to check if the process is running
output = subprocess.check_output(["pgrep", "-f", process_name]).decode().strip()
return l... | import pytest
from solution import is_process_running, restart_process, monitor_process
def test_is_process_running(monkeypatch):
# Mocking subprocess.check_output
def mock_check_output(cmd, *args, **kwargs):
if "pgrep" in cmd:
if cmd[-1] == "existing_process":
return "1234\... | [
{
"docstring": "Checks if a process with the given name is running.",
"function_declaration": "def is_process_running(process_name):",
"function_name": "is_process_running",
"parameter_list": "(process_name)"
},
{
"docstring": "Restarts the process by executing the provided command.",
"f... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport time\nimport subprocess\n\ndef is_process_running(process_name):\n try:\n # Check for the existence of the process\n output = subprocess.check_output(f\"pgre... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062148",
"row_id": 62148,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125668']"
} | 0.668954 | Filter_62148 | I | [
"is_process_running",
"restart_process",
"monitor_process"
] | 3 | [
[
"monitor_process",
"is_process_running"
],
[
"monitor_process",
"restart_process"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9fa9f4576d8f16916bed3da9928cb861d70fd7f8 | b86b76826a050ce084627d046b6acba4a2b3cc22 | |||
v1.0 | instruct | Filter | Filter_62169_I | Sure, here's a question for you: How can I generate a data library for a tire tread pattern classification problem using Python? | import cv2
import os
import numpy as np
from sklearn.model_selection import train_test_split
def load_images_from_folder(folder):
images = []
labels = []
for subdir in os.listdir(folder):
subdir_path = os.path.join(folder, subdir)
if os.path.isdir(subdir_path):
label = subdir
... | import os
import numpy as np
from solution import load_images_from_folder, preprocess_images, create_data_library
def test_load_images_from_folder():
# Setup
test_folder = 'test_dataset'
os.makedirs(test_folder, exist_ok=True)
class_folder = os.path.join(test_folder, 'class1')
os.makedirs(class_fol... | [
{
"docstring": null,
"function_declaration": "def load_images_from_folder(folder):",
"function_name": "load_images_from_folder",
"parameter_list": "(folder)"
},
{
"docstring": null,
"function_declaration": "def preprocess_images(images):",
"function_name": "preprocess_images",
"p... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\n\ndef organize_tire_tread_images(src_dir, dest_dir, image_label_mapping):\n \"\"\"\n Organizes tire tread images into category folders.\n \n Parameters:\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062169",
"row_id": 62169,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125705']"
} | 0.332131 | Filter_62169 | I | [
"load_images_from_folder",
"preprocess_images",
"create_data_library"
] | 3 | [
[
"create_data_library",
"load_images_from_folder"
],
[
"create_data_library",
"preprocess_images"
]
] | 2 | [] | false | [] | false | pytest | true | [
"cv2",
"numpy",
"sklearn"
] | false | d2eb89ffa9863b7a604a666310207e1cd2e3f452 | 89fe307a4f09f6290222ea441e5664c61f543b55 | |||
v1.0 | instruct | Filter | Filter_62184_I | I want to create a Python script that acts as a command-line interface (CLI) tool for managing a simple to-do list. The tool should be able to add, view, update, and delete tasks. Each task will have an ID, name, and description. How can I structure this script? | import sys
import json
TODO_LIST_FILE = "todo_list.json"
def load_tasks():
try:
with open(TODO_LIST_FILE, 'r') as file:
return json.load(file)
except FileNotFoundError:
return []
def save_tasks(tasks):
with open(TODO_LIST_FILE, 'w') as file:
json.dump(tasks, file, inde... | import pytest
import json
import os
from solution import add_task, view_tasks, update_task, delete_task, load_tasks
TODO_LIST_FILE = "todo_list.json"
def setup_module(module):
""" setup any state specific to the execution of the given module."""
if os.path.exists(TODO_LIST_FILE):
os.rename(TODO_LIST_F... | [
{
"docstring": null,
"function_declaration": "def load_tasks():",
"function_name": "load_tasks",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def save_tasks(tasks):",
"function_name": "save_tasks",
"parameter_list": "(tasks)"
},
{
"docstring": n... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nimport json\nimport os\n\nTODO_FILE = 'todos.json'\n\ndef load_todos():\n if os.path.exists(TODO_FILE):\n with open(TODO_FILE, 'r') as f:\n return json.load(f)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062184",
"row_id": 62184,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125728']"
} | 0.450924 | Filter_62184 | I | [
"load_tasks",
"save_tasks",
"add_task",
"view_tasks",
"update_task",
"delete_task",
"main"
] | 7 | [
[
"add_task",
"load_tasks"
],
[
"add_task",
"save_tasks"
],
[
"delete_task",
"load_tasks"
],
[
"delete_task",
"save_tasks"
],
[
"update_task",
"load_tasks"
],
[
"update_task",
"save_tasks"
],
[
"view_tasks",
"load_tasks"
]
] | 7 | [] | false | [] | false | pytest | true | [] | true | cc2064e36848b1a694019889e980a2676efbe0e8 | 76ee5a6a8109e76da13ae45c179dd94c2655e1ef | |||
v1.0 | instruct | Filter | Filter_62217_I | Can you explain the difference between a merge sort and a quick sort, and provide a simple implementation of each in Python? | def merge_sort(arr):
"""
Merge sort implementation.
"""
if len(arr) > 1:
mid = len(arr) // 2
left_half = arr[:mid]
right_half = arr[mid:]
merge_sort(left_half)
merge_sort(right_half)
i, j, k = 0, 0, 0
while i < len(left_half) and j < len(right_ha... | from solution import merge_sort, quick_sort
def test_merge_sort_sorted_array():
arr = [1, 2, 3, 4, 5]
merge_sort(arr)
assert arr == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_array():
arr = [5, 4, 3, 2, 1]
merge_sort(arr)
assert arr == [1, 2, 3, 4, 5]
def test_merge_sort_random_array():
... | [
{
"docstring": "Merge sort implementation.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Quick sort implementation.",
"function_declaration": "def quick_sort(arr):",
"function_name": "quick_sort",
"pa... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on an array.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half = arr[mi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062217",
"row_id": 62217,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125800']"
} | 0.47374 | Filter_62217 | I | [
"merge_sort",
"quick_sort",
"quick_sort_helper",
"partition"
] | 4 | [
[
"quick_sort",
"quick_sort_helper"
],
[
"quick_sort_helper",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 99664fd7250d3250d7f30a72ce0b393af91377ac | 6938c8f75cc9525a8ccb92ed110bd3d80fcff5d1 | |||
v1.0 | instruct | Filter | Filter_62219_I | Can you provide a Python implementation of a WebSocket server that can handle multiple clients and broadcast messages received from one client to all other connected clients? | import asyncio
import websockets
from websockets.exceptions import ConnectionClosedError
connected_clients = set()
async def broadcast(message, sender_socket):
for client in connected_clients:
if client != sender_socket:
try:
await client.send(message)
except Connec... | import asyncio
import websockets
import pytest
# Using pytest-asyncio to run the test
@pytest.mark.asyncio
async def test_websocket_server():
uri = "ws://localhost:6789"
async with websockets.serve(handle_client, "localhost", 6789):
async with websockets.connect(uri) as websocket1:
async w... | [] | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import asyncio\nimport websockets\nfrom websockets.exceptions import ConnectionClosedError\n\nconnected_clients = set()\n\nasync def broadcast(message, sender_socket):\n for client in conne... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062219",
"row_id": 62219,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125809']"
} | 0.525825 | Filter_62219 | I | [
"broadcast",
"handle_client",
"main"
] | 3 | [
[
"handle_client",
"broadcast"
]
] | 1 | [] | false | [] | false | pytest | false | [
"websockets"
] | false | e14ec0f2702968147fe350eaed34162a4205fa91 | 86d49a285a706159a41303991aeadfd6dd739618 | |||
v1.0 | instruct | Filter | Filter_62252_I | Provide a Python function that reads a CSV file and returns a dictionary where each key is a column name and the corresponding value is a list of values from that column. How can I modify the function to handle large CSV files efficiently? | import csv
def read_csv_to_dict(file_path):
"""
Reads a CSV file and returns a dictionary where each key is a column name
and the corresponding value is a list of values from that column.
Parameters:
file_path (str): Path to the CSV file.
Returns:
dict: Dictionary with column name... | import os
import csv
from solution import read_csv_to_dict, read_csv_to_dict_large
# Sample CSV content
csv_content = """name,age,city
John,28,New York
Jane,31,Los Angeles
Doe,22,Miami
"""
file_path = "test.csv"
def setup_module(module):
# Setup a sample CSV file for testing
with open(file_path, 'w', newline... | [
{
"docstring": "Reads a CSV file and returns a dictionary where each key is a column name\nand the corresponding value is a list of values from that column.\n\nParameters:\nfile_path (str): Path to the CSV file.\n\nReturns:\ndict: Dictionary with column names as keys and column values as lists.",
"function_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\n\ndef read_csv_to_dict(filepath):\n \"\"\"\n Reads a CSV file and returns a dictionary where each key is a column name\n and the corresponding value is a list of values fr... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062252",
"row_id": 62252,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125884']"
} | 0.633519 | Filter_62252 | I | [
"read_csv_to_dict",
"read_csv_to_dict_large",
"_process_chunk"
] | 3 | [
[
"read_csv_to_dict_large",
"_process_chunk"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 55c63c2e109e052ad0920b38f41777a786481404 | a7a8a76c127b98c4dceab0eb0ba18031e36a76e3 | |||
v1.0 | instruct | Filter | Filter_62270_I | How can I implement a simple cryptocurrency trading bot using Python? | import requests
import time
import hmac
import hashlib
# Constants
API_KEY = 'your_binance_api_key'
SECRET_KEY = 'your_binance_secret_key'
BASE_URL = 'https://api.binance.com'
SYMBOL = 'BTCUSDT' # Trading pair
QUANTITY = 0.001 # Quantity to trade
SMA_PERIOD = 5 # Simple moving average period
def get_headers(api_ke... | import pytest
from unittest.mock import patch
from solution import calculate_sma, get_price, create_order, BASE_URL
# Define test data
test_prices = [100, 105, 110, 115, 120]
expected_sma = sum(test_prices) / len(test_prices)
def test_calculate_sma():
assert calculate_sma(test_prices, len(test_prices)) == expecte... | [
{
"docstring": null,
"function_declaration": "def get_headers(api_key):",
"function_name": "get_headers",
"parameter_list": "(api_key)"
},
{
"docstring": null,
"function_declaration": "def get_signature(query_string, secret_key):",
"function_name": "get_signature",
"parameter_lis... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nfrom binance.client import Client\nfrom binance.enums import *\n\n# Define API key and Secret\nAPI_KEY = 'your_api_key'\nAPI_SECRET = 'your_api_secret'\n\n# Initialize the client\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062270",
"row_id": 62270,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125921']"
} | 0.451425 | Filter_62270 | I | [
"get_headers",
"get_signature",
"get_price",
"get_klines",
"create_order",
"calculate_sma",
"trading_bot"
] | 7 | [
[
"create_order",
"get_headers"
],
[
"create_order",
"get_signature"
],
[
"trading_bot",
"calculate_sma"
],
[
"trading_bot",
"create_order"
],
[
"trading_bot",
"get_klines"
],
[
"trading_bot",
"get_price"
]
] | 6 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 46a887fae7c2f9b066d4549b3b736e4fd460f3ed | 55a8790588a18475a0cb1ccf8e2e33b4adf8af71 | |||
v1.0 | instruct | Filter | Filter_62288_I | Write a Python code snippet that calculates the sum of all prime numbers below a given number `n`. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | from solution import is_prime, sum_of_primes_below
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(25) == False
def test_sum_of_primes_below_10():
assert sum_of_primes_below(10) == 17 # primes: ... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers below the given number `n`.",
"function_declaration": "def sum_of_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062288",
"row_id": 62288,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_125958']"
} | 0.767559 | Filter_62288 | I | [
"is_prime",
"sum_of_primes_below"
] | 2 | [
[
"sum_of_primes_below",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c898a7cf76a138ad6766d06bec3ff6c291604474 | 9d9161de0d432f2aef39d1e0c8928190fb833579 | |||
v1.0 | instruct | Filter | Filter_62346_I | I have a set of images that I want to compress using JPEG. How can I do this using Python? | from PIL import Image
import os
def compress_image(image_path, output_path, quality=85):
"""
Compress an image using the JPEG format.
:param image_path: Path to the input image.
:param output_path: Path to save the compressed image.
:param quality: Quality of the output JPEG image (1-100).
... | from solution import compress_image, compress_images_in_directory
import os
from PIL import Image
import pytest
def create_test_image(image_path, size=(100, 100), color=(155, 0, 0)):
"""
Utility function to create a simple image for testing.
"""
img = Image.new('RGB', size, color)
img.save(image_pa... | [
{
"docstring": "Compress an image using the JPEG format.\n\n:param image_path: Path to the input image.\n:param output_path: Path to save the compressed image.\n:param quality: Quality of the output JPEG image (1-100).",
"function_declaration": "def compress_image(image_path, output_path, quality=85):",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from PIL import Image\nimport os\n\ndef compress_image(input_path, output_path, quality=85):\n \"\"\"\n Compresses an image using JPEG compression.\n\n Parameters:\n input_path (st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062346",
"row_id": 62346,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126093']"
} | 0.561389 | Filter_62346 | I | [
"compress_image",
"compress_images_in_directory"
] | 2 | [
[
"compress_images_in_directory",
"compress_image"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | cb58a1226858b343ce672a016551c8becfb11264 | 64fd81ae6c0a60e6a306e7f9134e337fca373c11 | |||
v1.0 | instruct | Filter | Filter_62347_I | Can you help me with a Python script that can check the connectivity of multiple hosts using ICMP (ping)? | import os
import platform
import subprocess
def ping(host):
"""
Returns True if the host is responding to ICMP (ping), False otherwise.
"""
# Determine the parameter for the number of packets
param = '-n' if platform.system().lower() == 'windows' else '-c'
# Building the ping command
c... | from solution import ping, check_connectivity
def test_ping_localhost():
assert ping("127.0.0.1") == True
def test_check_connectivity_all_reachable():
hosts = ["127.0.0.1", "localhost"]
results = check_connectivity(hosts)
for host in hosts:
assert results[host] == True
def test_check_connecti... | [
{
"docstring": "Returns True if the host is responding to ICMP (ping), False otherwise.",
"function_declaration": "def ping(host):",
"function_name": "ping",
"parameter_list": "(host)"
},
{
"docstring": "Checks the connectivity of multiple hosts.\n\nParameters:\nhosts (list): A list of hostn... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import subprocess\nimport platform\n\ndef ping_host(host):\n \"\"\"\n Ping a host to check its connectivity.\n \n Args:\n host (str): Hostname or IP address of the host to be pi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062347",
"row_id": 62347,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126095']"
} | 0.673041 | Filter_62347 | I | [
"ping",
"check_connectivity"
] | 2 | [
[
"check_connectivity",
"ping"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f2a3f610d628fd46f366370ba8239a017f7322c6 | adc77243200c3b8cf5896976e3ecf0286fc9967d | |||
v1.0 | instruct | Filter | Filter_62355_I | Can you provide a Python code to solve the two-dimensional Poisson equation using the finite element method (FEM)? | import numpy as np
def generate_mesh(nx, ny, length, width):
"""
Generate a mesh grid for a 2D domain.
"""
x = np.linspace(0, length, nx)
y = np.linspace(0, width, ny)
X, Y = np.meshgrid(x, y)
return X, Y
def assemble_stiffness_matrix(nx, ny, dx, dy):
"""
Assemble the stiffness mat... | from solution import solve_poisson_2d
import numpy as np
def test_solve_poisson_2d():
nx, ny = 5, 5
length, width = 1.0, 1.0
boundary_value = 0.0
u = solve_poisson_2d(nx, ny, length, width, boundary_value)
# Check the shape of the output
assert u.shape == (ny, nx)
# Check that all... | [
{
"docstring": "Generate a mesh grid for a 2D domain.",
"function_declaration": "def generate_mesh(nx, ny, length, width):",
"function_name": "generate_mesh",
"parameter_list": "(nx, ny, length, width)"
},
{
"docstring": "Assemble the stiffness matrix for a 2D Poisson equation.",
"functi... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport scipy.sparse as sp\nimport scipy.sparse.linalg as sp_linalg\n\ndef solve_poisson_2d_fem(n):\n \"\"\"\n Solves the 2D Poisson equation using the Finite Element ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062355",
"row_id": 62355,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126113']"
} | 0.313586 | Filter_62355 | I | [
"generate_mesh",
"assemble_stiffness_matrix",
"apply_boundary_conditions",
"solve_poisson_2d"
] | 4 | [
[
"solve_poisson_2d",
"apply_boundary_conditions"
],
[
"solve_poisson_2d",
"assemble_stiffness_matrix"
],
[
"solve_poisson_2d",
"generate_mesh"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | efc2122b6fa460422ba53749be8676e1736ea13f | 3b6ee084144ac8de69b56885ecdcc015c5130e33 | |||
v1.0 | instruct | Filter | Filter_62459_I | Can you explain the concept of a functional programming language and provide an example in Python? | from functools import reduce
# A pure function: does not depend on / modify the outside state
def add(x, y):
return x + y
# A higher-order function: takes a function as an argument
def apply_operation(numbers, operation):
return [operation(x) for x in numbers]
# A function using higher-order functions and im... | from solution import add, apply_operation, sum_of_squares
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_apply_operation():
assert apply_operation([1, 2, 3], lambda x: x * 2) == [2, 4, 6]
assert apply_operation([1, 2, 3], lambda x: x + 1) == [2, 3, 4]
... | [
{
"docstring": null,
"function_declaration": "def add(x, y):",
"function_name": "add",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def apply_operation(numbers, operation):",
"function_name": "apply_operation",
"parameter_list": "(numbers, operation... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import reduce\n\ndef add(x, y):\n return x + y\n\ndef multiply(x, y):\n return x * y\n\n# A higher-order function that takes a function and a list as arguments.\ndef apply... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062459",
"row_id": 62459,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126306']"
} | 0.493121 | Filter_62459 | I | [
"add",
"apply_operation",
"sum_of_squares"
] | 3 | [
[
"sum_of_squares",
"add"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 63745868c9d41e9a6160a61fe26f98626e0f3e68 | 16d5ebf457d058132ca0275393305035a4a2b456 | |||
v1.0 | instruct | Filter | Filter_62478_I | I need to create a script that monitors the availability of a specific website using ping and records the results in a CSV file. How can I do this in Python? | import csv
import os
import subprocess
import datetime
def ping_website(hostname):
"""
Pings the given hostname and returns True if the host is reachable, else False.
"""
try:
# On Windows, use '-n' for ping count; on Linux/Mac, use '-c'
param = '-n' if os.name == 'nt' else '-c'
... | import os
import csv
from datetime import datetime
from unittest.mock import patch
from solution import ping_website, record_ping_results
@patch("subprocess.run")
def test_ping_website_success(mock_subproc_run):
mock_subproc_run.return_value.returncode = 0
assert ping_website("google.com") == True
@patch(... | [
{
"docstring": "Pings the given hostname and returns True if the host is reachable, else False.",
"function_declaration": "def ping_website(hostname):",
"function_name": "ping_website",
"parameter_list": "(hostname)"
},
{
"docstring": "Records the ping result of the given hostname in the spe... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport csv\nimport subprocess\nfrom datetime import datetime\n\ndef ping_website(url):\n \"\"\"\n Pings the specified website and checks if the ping is successful.\n Return... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062478",
"row_id": 62478,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126341']"
} | 0.655398 | Filter_62478 | I | [
"ping_website",
"record_ping_results"
] | 2 | [
[
"record_ping_results",
"ping_website"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ff45730e1795a474ce0d5aa97cd88750b1d8ad9 | d982525f9f7ed87f016abb4a1977c014bcf87392 | |||
v1.0 | instruct | Filter | Filter_62493_I | How does the iterative deepening depth-first search (IDDFS) algorithm work, and can you provide a Python implementation? | def depth_limited_search(graph, start, goal, limit):
"""
Performs depth-limited search from the start node to the goal node within the given limit.
"""
if start == goal:
return [start]
if limit <= 0:
return None
for neighbor in graph.get(start, []):
path = depth... | from solution import iddfs
def test_iddfs_basic():
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
assert iddfs(graph, 'A', 'F', 3) == ['A', 'C', 'F']
def test_iddfs_no_path():
graph = {
'A': ['B', 'C'],
... | [
{
"docstring": "Performs depth-limited search from the start node to the goal node within the given limit.",
"function_declaration": "def depth_limited_search(graph, start, goal, limit):",
"function_name": "depth_limited_search",
"parameter_list": "(graph, start, goal, limit)"
},
{
"docstrin... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def iddfs(graph, start, goal):\n \"\"\"\n Perform an Iterative Deepening Depth-First Search (IDDFS) on the given graph.\n\n :param graph: Dictionary representing the adjacency list of... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062493",
"row_id": 62493,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126375']"
} | 0.305344 | Filter_62493 | I | [
"depth_limited_search",
"iddfs"
] | 2 | [
[
"iddfs",
"depth_limited_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e88599860b972506b3db41592c69f4e9766a5d42 | a45651f96da23aad0388534f939165af6fccc9de | |||
v1.0 | instruct | Filter | Filter_62499_I | Write a Python code to simulate a simple game of rock-paper-scissors where the user plays against the computer. The game should run until the user decides to quit by entering 'q'. The computer's choice should be randomly generated. After each round, the score should be displayed, and the user can choose to play again o... | import random
def get_computer_choice():
"""
Returns the computer's random choice: 'rock', 'paper', or 'scissors'.
"""
choices = ['rock', 'paper', 'scissors']
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
"""
Determines the winner between user and comput... | from solution import get_computer_choice, determine_winner
def test_get_computer_choice():
choices = ['rock', 'paper', 'scissors']
for _ in range(100):
assert get_computer_choice() in choices
def test_determine_winner():
assert determine_winner('rock', 'scissors') == 'user'
assert determine_wi... | [
{
"docstring": "Returns the computer's random choice: 'rock', 'paper', or 'scissors'.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner between user and computer. Returns 'user', 'co... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Returns the computer's random choice: 'rock', 'paper', or 'scissors'.\n \"\"\"\n choices = ['rock', 'paper', 'scissors']\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062499",
"row_id": 62499,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126387']"
} | 0.46308 | Filter_62499 | I | [
"get_computer_choice",
"determine_winner",
"rock_paper_scissors"
] | 3 | [
[
"rock_paper_scissors",
"determine_winner"
],
[
"rock_paper_scissors",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b0e253330e2c7d8ccd6bc3ba59000974f1b88538 | e8b22c0168ef4dd2d3cf65284755411a3510744a | |||
v1.0 | instruct | Filter | Filter_62513_I | Can you provide a Python script that takes a directory of text files, processes each file to remove stopwords, and then outputs the cleaned text to new files in a specified output directory? | import os
def load_stopwords(filepath="stopwords.txt"):
"""
Load stopwords from a file.
Each line in the file should contain one stopword.
"""
with open(filepath, 'r') as file:
stopwords = set(word.strip() for word in file.readlines())
return stopwords
def clean_text(text, stopwords):
... | import os
import pytest
from solution import load_stopwords, clean_text, process_files
def test_load_stopwords(tmpdir):
stopwords_file = tmpdir.join("stopwords.txt")
stopwords_file.write("a\nan\nthe\n")
stopwords = load_stopwords(str(stopwords_file))
assert stopwords == {"a", "an", "the"}
def test_cl... | [
{
"docstring": "Load stopwords from a file.\nEach line in the file should contain one stopword.",
"function_declaration": "def load_stopwords(filepath='stopwords.txt'):",
"function_name": "load_stopwords",
"parameter_list": "(filepath='stopwords.txt')"
},
{
"docstring": "Removes stopwords fr... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nfrom nltk.corpus import stopwords\nfrom nltk.tokenize import word_tokenize\n\n# Ensure you have the stopwords and punkt datasets downloaded\nimport nltk\nnltk.download('stopwords')\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062513",
"row_id": 62513,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126415']"
} | 0.594054 | Filter_62513 | I | [
"load_stopwords",
"clean_text",
"process_files"
] | 3 | [
[
"process_files",
"clean_text"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71ff68634dd22224729706b3bea68829e352c01c | 3efdbdddd8f74f61af573fff0248f3c8ec4bb086 | |||
v1.0 | instruct | Filter | Filter_62521_I | Can you explain how to create a custom function in Python that can be used in SQL queries with SQLite? | import sqlite3
def custom_upper(text):
"""
Custom function to convert text to uppercase.
"""
return text.upper()
def create_and_register_function(db_path):
"""
Create SQLite connection, register custom function, and return the connection.
"""
conn = sqlite3.connect(db_path)
conn.cr... | import sqlite3
from solution import custom_upper, create_and_register_function
def test_custom_upper():
assert custom_upper('hello') == 'HELLO'
assert custom_upper('World') == 'WORLD'
assert custom_upper('Sqlite') == 'SQLITE'
def test_create_and_register_function(tmpdir):
# Create a temporary database... | [
{
"docstring": "Custom function to convert text to uppercase.",
"function_declaration": "def custom_upper(text):",
"function_name": "custom_upper",
"parameter_list": "(text)"
},
{
"docstring": "Create SQLite connection, register custom function, and return the connection.",
"function_dec... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sqlite3\n\ndef custom_square(x):\n \"\"\"\n Returns the square of x.\n \"\"\"\n return x * x\n\n# Create a connection to the SQLite database\nconn = sqlite3.connect(':memory... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062521",
"row_id": 62521,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126432']"
} | 0.642482 | Filter_62521 | I | [
"custom_upper",
"create_and_register_function"
] | 2 | [
[
"create_and_register_function",
"custom_upper"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cdf31c01775c1c7bcc93ba92075da70cca536d53 | e5c344a183374c802b4da672cb09a4064beea6f5 | |||
v1.0 | instruct | Filter | Filter_62587_I | Can you provide a Python code to simulate a simple dice game? In this game, two players take turns rolling a fair six-sided die. The first player to reach a score of 20 wins the game. The game should output the result after each roll, showing the current scores of both players. | import random
def roll_die():
"""
Simulates rolling a six-sided die and returns the result.
"""
return random.randint(1, 6)
def dice_game():
"""
Simulates a simple dice game where two players roll a die until one reaches a score
of 20 or more. Outputs the result after each roll.
"""
... | from solution import roll_die, dice_game
import random
def test_roll_die():
random.seed(0)
results = [roll_die() for _ in range(100)]
# Check if all results are in the range of a six-sided die
for result in results:
assert 1 <= result <= 6
def test_dice_game_winner():
random.seed(0)
# ... | [
{
"docstring": "Simulates rolling a six-sided die and returns the result.",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Simulates a simple dice game where two players roll a die until one reaches a score \nof 20 or more. O... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulate rolling a six-sided die.\n Returns a random number between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef simulate_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062587",
"row_id": 62587,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126587']"
} | 0.532771 | Filter_62587 | I | [
"roll_die",
"dice_game"
] | 2 | [
[
"dice_game",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0a997a99c028761e473d0a6fb77cea41825187e0 | 958609902263461015da533b98500a3fe8d239fd | |||
v1.0 | instruct | Filter | Filter_62608_I | How can I develop a Python script to monitor and log disk usage for a specific directory, and send an alert when the usage exceeds a certain threshold? | import os
import shutil
import logging
import smtplib
from email.mime.text import MIMEText
def monitor_disk_usage(directory, threshold_percent, alert_email):
"""
Monitors the disk usage for a specific directory and sends an alert email
if the usage exceeds the specified threshold percentage.
:param di... | import os
import shutil
from unittest import mock
from solution import monitor_disk_usage, send_alert_email
@mock.patch('solution.shutil.disk_usage')
@mock.patch('solution.send_alert_email')
def test_monitor_disk_usage_above_threshold(mock_send_email, mock_disk_usage):
# Setup mock for disk usage
mock_disk_usa... | [
{
"docstring": "Monitors the disk usage for a specific directory and sends an alert email\nif the usage exceeds the specified threshold percentage.\n\n:param directory: The directory to monitor\n:param threshold_percent: The threshold percentage for disk usage\n:param alert_email: The email to send the alert to... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\nimport logging\nimport smtplib\nfrom email.mime.text import MIMEText\n\ndef get_disk_usage(directory):\n \"\"\"\n Returns the disk usage of the specified direct... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062608",
"row_id": 62608,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126619']"
} | 0.570803 | Filter_62608 | I | [
"monitor_disk_usage",
"send_alert_email"
] | 2 | [
[
"monitor_disk_usage",
"send_alert_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3e5bb334054f2000adc30125793baace09ae8d7 | fdb63f7cea6c0b3c8e491289d5a3892e0aebdc19 | |||
v1.0 | instruct | Filter | Filter_62625_I | Write a Python program to simulate a simple calculator that performs basic arithmetic operations like addition, subtraction, multiplication, and division. The program should be able to handle user input and display results for each operation. The calculator should continuously prompt the user to perform operations unti... | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
return "Cannot divide by zero"
return a / b
def calculator():
while True:
print("Select operation:")
print("1. Add")
print("2. Subtract")... | from solution import add, subtract, multiply, divide
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
assert add(1.5, 2.5) == 4.0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(-1, 1) == -2
assert subtract(0, 0) == 0
assert subtract(2.... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062625",
"row_id": 62625,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126646']"
} | 0.5996 | Filter_62625 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 6b87547491f1655f3b13c9778ecb88839a75a9a2 | b2adbadb360bbc64fbb13f4ef0c3ae34694e2860 | |||
v1.0 | instruct | Filter | Filter_62635_I | Can you provide Python code to generate a list of all prime numbers up to a given number, say 100? | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, generate_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
assert is_prime(1) == False
assert is_prime(0) == Fa... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of all prime numbers up to the given number.\n\nParameters:\nup_to (int): The upper lim... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(n):\n \"\"\"\n Generate a list of all prime numbers up to a given number n.\n \"\"\"\n if n < 2:\n return []\n\n primes = []\n sieve = [True] * (n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062635",
"row_id": 62635,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126667']"
} | 0.609731 | Filter_62635 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d5f25f28485b3eba58a66b66d575cb43a82b5743 | dc4c6d4f078df9434bdb294e6232b6ecc30a856b | |||
v1.0 | instruct | Filter | Filter_62656_I | Can you provide a Python script that can export symbols from a dynamic link library (DLL) on Windows? To be specific, I need a script that lists all the functions exported by a DLL and writes them to a file in the format `function_name ordinal_number`. | import os
import subprocess
def dumpbin_symbols(dll_path):
"""
This function runs the `dumpbin /exports` command on the provided DLL file.
"""
result = subprocess.run(['dumpbin', '/exports', dll_path], stdout=subprocess.PIPE, text=True)
return result.stdout
def extract_symbols(dumpbin_output):
... | import os
from solution import extract_symbols
def test_extract_symbols():
dumpbin_output = """
Microsoft (R) COFF/PE Dumper Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file example.dll
File Type: DLL
Section contains the following e... | [
{
"docstring": "This function runs the `dumpbin /exports` command on the provided DLL file.",
"function_declaration": "def dumpbin_symbols(dll_path):",
"function_name": "dumpbin_symbols",
"parameter_list": "(dll_path)"
},
{
"docstring": "This function extracts the function names and their or... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport subprocess\n\ndef list_dll_exports(dll_path, output_file):\n \"\"\"\n Extracts and lists all functions exported by a DLL and writes them to a file.\n \n Parameter... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062656",
"row_id": 62656,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126709']"
} | 0.509212 | Filter_62656 | I | [
"dumpbin_symbols",
"extract_symbols",
"export_symbols_to_file"
] | 3 | [
[
"export_symbols_to_file",
"dumpbin_symbols"
],
[
"export_symbols_to_file",
"extract_symbols"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 807811f411e4e3e3d4fb10e9da8d6a0b4f9a6b56 | f50ca153922de448715181b72ae8fec3e5fa9e93 | |||
v1.0 | instruct | Filter | Filter_62727_I | Can you provide a Python function that checks if a given number is a prime number? How can I use this function to check a list of numbers for primality? | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, check_primes_in_list
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(-3) == False
assert is_prime(0) =... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a list of numbers, returns a list of boolean values indicating \nwhether each number is prime or n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n %... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062727",
"row_id": 62727,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126862']"
} | 0.806964 | Filter_62727 | I | [
"is_prime",
"check_primes_in_list"
] | 2 | [
[
"check_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6a2e80629a14d0ac1ca7971b1ff4a8d6c7285370 | 4bdd55b6c3a9ace2849a7a79da4ae9d87ff19dcc | |||
v1.0 | instruct | Filter | Filter_62734_I | I want to create a Python script that simulates a simple dice game where two players roll a dice and the player with the higher roll wins. If the rolls are equal, it's a draw. Can you provide a Python script for this game? | import random
def roll_dice():
"""
Simulates rolling a six-sided dice and returns the result.
"""
return random.randint(1, 6)
def play_game():
"""
Simulates a dice game between two players. Each player rolls a die,
and the function returns the outcome.
"""
player1_roll = roll_dice(... | from solution import roll_dice, play_game
def test_roll_dice():
for _ in range(1000):
roll = roll_dice()
assert 1 <= roll <= 6
def test_play_game():
outcomes = {"Player 1 wins": 0, "Player 2 wins": 0, "It's a draw": 0}
for _ in range(1000):
result, roll1, roll2 = play_game()
... | [
{
"docstring": "Simulates rolling a six-sided dice and returns the result.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a dice game between two players. Each player rolls a die,\nand the function returns the o... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a 6-sided dice and returns a value between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_game():\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062734",
"row_id": 62734,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126877']"
} | 0.459571 | Filter_62734 | I | [
"roll_dice",
"play_game"
] | 2 | [
[
"play_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ef09aa5b5fe86870face1d2b2e0f1647e9a442f5 | 4741645af73eb3632d5e3ea69a98c244611828f4 | |||
v1.0 | instruct | Filter | Filter_62758_I | Can you provide a simple example of a Davis-Putnam-Logemann-Loveland (DPLL) algorithm in Python? | def dpll(clauses, assignment):
"""
DPLL algorithm implementation.
Parameters:
clauses - List of clauses (list of lists of integers).
assignment - Current variable assignment (dictionary of variable: Bool).
Returns:
Bool - True if the formula is satisfiable, False otherwise.
Ass... | import pytest
from solution import dpll
def test_dpll_satisfiable():
clauses = [[1, -3], [-1, 2, 3], [-2, -3], [-1, -2]]
assignment = {}
satisfiable, solution = dpll(clauses, assignment)
assert satisfiable == True
assert all(clause_satisfied(clause, solution) for clause in clauses)
def test_dpll_u... | [
{
"docstring": "DPLL algorithm implementation.\n\nParameters:\nclauses - List of clauses (list of lists of integers).\nassignment - Current variable assignment (dictionary of variable: Bool).\n\nReturns:\nBool - True if the formula is satisfiable, False otherwise.\nAssignment - Dictionary containing the final v... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def dpll(clauses, assignment=None):\n if assignment is None:\n assignment = {}\n\n # Check if all clauses are satisfied\n satisfied = all(any(lit in assignment and assignment[l... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062758",
"row_id": 62758,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_126921']"
} | 0.388957 | Filter_62758 | I | [
"dpll",
"select_literal",
"simplify"
] | 3 | [
[
"dpll",
"select_literal"
],
[
"dpll",
"simplify"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2faa80e9033fc41e9b850fb2fed7268683438c7b | b140a57f282a881f42b37874b68987f16e756ac3 | |||
v1.0 | instruct | Filter | Filter_62811_I | I want to build a neural network for a regression task in PyTorch. Can you guide me through the process step-by-step? | import torch
import torch.nn as nn
import torch.optim as optim
class SimpleRegressionNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(SimpleRegressionNN, self).__init__()
self.hidden = nn.Linear(input_size, hidden_size)
self.relu = nn.ReLU()
self.output... | import torch
from torch.utils.data import DataLoader, TensorDataset
from solution import SimpleRegressionNN, build_and_train_regression_nn
def test_model_structure():
input_size = 1
hidden_size = 10
output_size = 1
model = SimpleRegressionNN(input_size, hidden_size, output_size)
assert isinstance(m... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\n\nclass SimpleRegressor(nn.Module):\n def __init__(self, input_dim, output_dim):\n super(SimpleRegressor, self).__in... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062811",
"row_id": 62811,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127020']"
} | 0.378663 | Filter_62811 | I | [
"train_model",
"build_and_train_regression_nn"
] | 2 | [
[
"build_and_train_regression_nn",
"train_model"
]
] | 1 | [] | false | [
"SimpleRegressionNN"
] | true | pytest | true | [
"torch"
] | false | f6b0807dc0fa02b9fc325ac5723aab96511bfb62 | ef341288c7a522aa19a117b09c5ad22ff8e0d653 | |||
v1.0 | instruct | Filter | Filter_62820_I | Can you create a Python script that simulates a simple dice game where two players roll a dice and the player with the higher number wins? If the numbers are the same, it's a tie. The script should allow for multiple rounds and should keep track of the score for each player. | import random
def roll_dice():
return random.randint(1, 6)
def play_round():
player1_score = roll_dice()
player2_score = roll_dice()
if player1_score > player2_score:
return "Player 1", player1_score, player2_score
elif player2_score > player1_score:
return "Player 2", player1... | from solution import play_round, play_game
def test_play_round():
result, player1_score, player2_score = play_round()
assert result in ["Player 1", "Player 2", "Tie"], f"Unexpected result: {result}"
assert 1 <= player1_score <= 6, f"Player 1 score out of range: {player1_score}"
assert 1 <= player2... | [
{
"docstring": null,
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def play_round():",
"function_name": "play_round",
"parameter_list": "()"
},
{
"docstring": null,
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n return random.randint(1, 6)\n\ndef play_round():\n player1_roll = roll_dice()\n player2_roll = roll_dice()\n\n if player1_roll > player2_roll:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062820",
"row_id": 62820,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127043']"
} | 0.460726 | Filter_62820 | I | [
"roll_dice",
"play_round",
"play_game"
] | 3 | [
[
"play_game",
"play_round"
],
[
"play_round",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f926f4ff7cf5d1edd873101a0a0c5c51ea063ac0 | 9a51cd9c783c455a1f0389043d78f668d85d8bcd | |||
v1.0 | instruct | Filter | Filter_62870_I | How can we handle complex data structures in configuration files when using Flask, especially for data types like lists, dictionaries, and nested structures? | import json
from flask import Flask
def load_config(app, config_file):
"""
Loads configuration from a JSON file into the Flask app instance.
"""
with open(config_file, 'r') as f:
config_data = json.load(f)
app.config.update(config_data)
def create_app(config_file):
"""
Creates a Fl... | import json
import os
import pytest
from flask import Flask
from solution import load_config, create_app
@pytest.fixture
def temp_config_file():
config_data = {
"DEBUG": True,
"DATABASES": {
"default": {
"ENGINE": "sqlite",
"NAME": "test.db"
}... | [
{
"docstring": "Loads configuration from a JSON file into the Flask app instance.",
"function_declaration": "def load_config(app, config_file):",
"function_name": "load_config",
"parameter_list": "(app, config_file)"
},
{
"docstring": "Creates a Flask app and loads the given configuration fi... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport os\nfrom flask import Flask\n\ndef create_app(config_path):\n app = Flask(__name__)\n \n def load_config():\n with open(config_path, 'r') as f:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062870",
"row_id": 62870,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127151']"
} | 0.53711 | Filter_62870 | I | [
"load_config",
"create_app"
] | 2 | [
[
"create_app",
"load_config"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | ce8f080367364ff676cf572c286c90f3670e11c0 | 31a1f8d69ccf8a2ba8d53822ff5484d54521e075 | |||
v1.0 | instruct | Filter | Filter_62897_I | What is the concept of modular programming in Python, and how can it be implemented? | def calculate_total_price(price, quantity):
"""
Returns the total price of the items.
"""
return price * quantity
def calculate_discounted_price(total_price, discount_percent):
"""
Returns the total price after applying the discount.
"""
return total_price - (total_price * discount_perc... | from solution import calculate_total_price, calculate_discounted_price, calculate_final_price
def test_calculate_total_price():
assert calculate_total_price(10, 5) == 50
assert calculate_total_price(0, 10) == 0
assert calculate_total_price(7.5, 4) == 30.0
def test_calculate_discounted_price():
assert ... | [
{
"docstring": "Returns the total price of the items.",
"function_declaration": "def calculate_total_price(price, quantity):",
"function_name": "calculate_total_price",
"parameter_list": "(price, quantity)"
},
{
"docstring": "Returns the total price after applying the discount.",
"functi... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# math_operations.py\ndef add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise Val... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062897",
"row_id": 62897,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127215']"
} | 0.429303 | Filter_62897 | I | [
"calculate_total_price",
"calculate_discounted_price",
"calculate_final_price"
] | 3 | [
[
"calculate_final_price",
"calculate_discounted_price"
],
[
"calculate_final_price",
"calculate_total_price"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 681a9ba3e7e98402d4698ceda69f8d4dd93fe6f1 | 8020da959030bc5c45a1b035525f9400b4ab1124 | |||
v1.0 | instruct | Filter | Filter_62899_I | Given a string `s` containing only digits, return all possible palindromic partitions of `s`. A palindromic partition is a partitioning of the string such that each part is a palindrome. For example, given `s = "aab"`, the possible palindromic partitions are `["a", "a", "b"]` and `["aa", "b"]`. | def is_palindrome(s):
return s == s[::-1]
def partition(s):
"""
Returns all possible palindromic partitions of the string `s`.
"""
def helper(start, path):
if start == len(s):
result.append(path)
return
for end in range(start + 1, len(s) + 1):
if ... | from solution import partition
def test_partition_single_character():
assert partition("a") == [["a"]]
def test_partition_two_characters():
assert partition("aa") == [["a", "a"], ["aa"]]
assert partition("ab") == [["a", "b"]]
def test_partition_three_characters():
assert partition("aab") == [["a", "a... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all possible palindromic partitions of the string `s`.",
"function_declaration": "def partition(s):",
"function_name": "partition... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n return s == s[::-1]\n\ndef partition(s):\n def dfs(start):\n if start == len(s):\n result.append(path[:])\n return\n for end i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062899",
"row_id": 62899,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127219']"
} | 0.706939 | Filter_62899 | I | [
"is_palindrome",
"partition"
] | 2 | [
[
"partition",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 968d06c3aee77d71ee172db73139ad58ec81f74f | 3eeae402abd1141f6597b2eae98b3446af2298d6 | |||
v1.0 | instruct | Filter | Filter_62908_I | How can I compare two JSON files and find the differences between them using Python? | import json
def compare_json_files(file1_path, file2_path):
"""
Compare two JSON files and find the differences.
:param file1_path: Path to the first JSON file.
:param file2_path: Path to the second JSON file.
:return: Dictionary of differences. If a key-value pair exists in one file and ... | import pytest
import json
from io import StringIO
from solution import compare_json_files, find_differences
def test_compare_json_files(tmpdir):
file1_path = tmpdir.join("file1.json")
file2_path = tmpdir.join("file2.json")
json1 = {
"name": "John",
"age": 30,
"city": "New York"... | [
{
"docstring": "Compare two JSON files and find the differences.\n\n:param file1_path: Path to the first JSON file.\n:param file2_path: Path to the second JSON file.\n\n:return: Dictionary of differences. If a key-value pair exists in one file and not in the other,\n it will be listed under the 'added' ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\n\ndef find_differences(json1, json2):\n \"\"\"\n Compare two JSON objects and find the differences.\n \n Args:\n json1 (dict): The first JSON object.\n json2 (di... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062908",
"row_id": 62908,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127233']"
} | 0.621952 | Filter_62908 | I | [
"compare_json_files",
"find_differences"
] | 2 | [
[
"compare_json_files",
"find_differences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2c7c21bbed1058696b6d5b3108a146e2486d1dd | 9c6a1925a07991980fbe6658a42c13201149e2d9 | |||
v1.0 | instruct | Filter | Filter_62926_I | Hello, I want to learn about fractals and chaos in programming. Could you provide a simple example of how to generate a fractal in Python? | import matplotlib.pyplot as plt
def mandelbrot(c, max_iter):
"""
Determines whether a point is in the Mandelbrot set.
"""
z = 0.0j
for n in range(max_iter):
z = z*z + c
if z.real*z.real + z.imag*z.imag >= 4:
return n
return max_iter
def generate_mandelbrot(width, he... | from solution import mandelbrot, generate_mandelbrot
def test_mandelbrot_point_in_set():
c = complex(0, 0)
max_iter = 100
assert mandelbrot(c, max_iter) == max_iter
def test_mandelbrot_point_out_of_set():
c = complex(2, 2)
max_iter = 100
assert mandelbrot(c, max_iter) < max_iter
def test_gene... | [
{
"docstring": "Determines whether a point is in the Mandelbrot set.",
"function_declaration": "def mandelbrot(c, max_iter):",
"function_name": "mandelbrot",
"parameter_list": "(c, max_iter)"
},
{
"docstring": "Generates the Mandelbrot fractal.",
"function_declaration": "def generate_man... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import matplotlib.pyplot as plt\n\ndef mandelbrot(c, max_iter):\n \"\"\"\n Determines whether a point is in the Mandelbrot set.\n \"\"\"\n z = 0.0j\n for n in range(max_iter):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062926",
"row_id": 62926,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127282']"
} | 0.406597 | Filter_62926 | I | [
"mandelbrot",
"generate_mandelbrot",
"plot_mandelbrot"
] | 3 | [
[
"generate_mandelbrot",
"mandelbrot"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib"
] | false | 555d2daeab414106cfc7213185641c9fce33b7f3 | 84edbedb53cb8b68419c734b8b1936e647181cd5 | |||
v1.0 | instruct | Filter | Filter_62936_I | Write a Python script that converts a JSON file to a CSV file. The JSON file contains an array of objects, where each object represents a record with key-value pairs. The CSV file should have headers corresponding to the keys of the JSON objects. The script should handle nested JSON objects by flattening them into a si... | import json
import csv
def flatten_json(json_obj, delimiter='_'):
def _flatten(obj, parent_key=''):
items = []
for k, v in obj.items():
new_key = f"{parent_key}{delimiter}{k}" if parent_key else k
if isinstance(v, dict):
items.extend(_flatten(v, new_key).item... | import os
import tempfile
import json
import csv
from solution import convert_json_to_csv
def test_convert_json_to_csv_simple():
# Prepare test data
json_data = [
{"name": "John", "age": 30},
{"name": "Jane", "age": 25}
]
# Write the input JSON to a temporary file
with tempfil... | [
{
"docstring": null,
"function_declaration": "def flatten_json(json_obj, delimiter='_'):",
"function_name": "flatten_json",
"parameter_list": "(json_obj, delimiter='_')"
},
{
"docstring": null,
"function_declaration": "def convert_json_to_csv(json_filepath, csv_filepath, delimiter='_'):"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport csv\n\ndef flatten_json(json_obj, delimiter='_'):\n \"\"\"\n Flattens a nested JSON object.\n \"\"\"\n def flatten(obj, parent_key='', sep=delimiter):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00062936",
"row_id": 62936,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127296']"
} | 0.730301 | Filter_62936 | I | [
"flatten_json",
"convert_json_to_csv"
] | 2 | [
[
"convert_json_to_csv",
"flatten_json"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65a3f0681b6486a9ddb4fc69434572581b263e4b | 75e050cb5809dec1878231635f99a5c0614caae6 | |||
v1.0 | instruct | Filter | Filter_62943_I | Can you provide a Python script that convolves a 2D image with a 3x3 Gaussian filter and then applies a median filter to the result? First, it should normalize the Gaussian filter, then apply it to the image. The median filter should be applied to the convolved image. | import numpy as np
from scipy.ndimage import convolve, median_filter
def gaussian_filter_3x3():
"""
Generates a 3x3 Gaussian filter with sigma=1.
"""
filter_ = np.array([[1, 2, 1],
[2, 4, 2],
[1, 2, 1]])
return filter_ / filter_.sum()
def apply_filte... | import numpy as np
from solution import gaussian_filter_3x3, apply_filters
def test_gaussian_filter_3x3():
expected_filter = np.array([[1, 2, 1],
[2, 4, 2],
[1, 2, 1]]) / 16.0
assert np.allclose(gaussian_filter_3x3(), expected_filter)
def test_ap... | [
{
"docstring": "Generates a 3x3 Gaussian filter with sigma=1.",
"function_declaration": "def gaussian_filter_3x3():",
"function_name": "gaussian_filter_3x3",
"parameter_list": "()"
},
{
"docstring": "Applies a 3x3 Gaussian filter followed by a median filter to the input image.\n\nParameters:... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.ndimage import convolve, median_filter\n\ndef gaussian_kernel(size, sigma=1.0):\n \"\"\"Function to generate a 2D Gaussian Kernel.\"\"\"\n kernel = np.from... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062943",
"row_id": 62943,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127310']"
} | 0.491997 | Filter_62943 | I | [
"gaussian_filter_3x3",
"apply_filters"
] | 2 | [
[
"apply_filters",
"gaussian_filter_3x3"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 6ca52ebf55e1217412dbe8b362cd261f48490aa4 | 4aedb4af4d14b3b3510572e4dc29e5c61a7a406b | |||
v1.0 | instruct | Filter | Filter_62988_I | Can you provide me with a detailed explanation of how to implement a tic-tac-toe game in Python, including the user interface and game logic? | def initialize_board():
"""
Initialize the game board as a 3x3 grid of empty strings.
"""
return [[' ' for _ in range(3)] for _ in range(3)]
def print_board(board):
"""
Prints the game board.
"""
for row in board:
print("|".join(row))
print("-----")
def check_winner(boa... | from solution import initialize_board, print_board, check_winner, check_tie, make_move, switch_player
def test_initialize_board():
board = initialize_board()
assert board == [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
def test_check_winner():
board = [['X', 'X', 'X'], [' ', 'O', ' '], [' ', 'O', '... | [
{
"docstring": "Initialize the game board as a 3x3 grid of empty strings.",
"function_declaration": "def initialize_board():",
"function_name": "initialize_board",
"parameter_list": "()"
},
{
"docstring": "Prints the game board.",
"function_declaration": "def print_board(board):",
"f... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def initialize_board():\n \"\"\"\n Initialize the game board as a 3x3 grid of empty strings.\n \"\"\"\n return [[' ' for _ in range(3)] for _ in range(3)]\n\ndef print_board(board)... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00062988",
"row_id": 62988,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127394']"
} | 0.365728 | Filter_62988 | I | [
"initialize_board",
"print_board",
"check_winner",
"check_tie",
"make_move",
"switch_player",
"play_game"
] | 7 | [
[
"check_tie",
"check_winner"
],
[
"play_game",
"check_tie"
],
[
"play_game",
"check_winner"
],
[
"play_game",
"initialize_board"
],
[
"play_game",
"make_move"
],
[
"play_game",
"print_board"
],
[
"play_game",
"switch_player"
]
] | 7 | [] | false | [] | false | pytest | true | [] | true | 95348a89ee9975f78531f502aa1a09044df6885f | 26c349394b6e1bde7be3a5bd11bf08d94b5d3207 | |||
v1.0 | instruct | Filter | Filter_62992_I | I need to write a Python function that identifies all the prime numbers within a given range. How can I create this function? | def is_prime(n):
"""
Check if a number is prime.
Returns True if the number is prime, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == ... | from solution import is_prime, primes_in_range
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_primes_in_range():
... | [
{
"docstring": "Check if a number is prime.\nReturns True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers in the given range [start, end].",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_primes_in_range(start, end):\n \"\"\"\n Returns a list of all prime numbers in the range [start, end).\n\n Args:\n start (int): Start of the range (inclusive).\n end (i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062992",
"row_id": 62992,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127398']"
} | 0.712996 | Filter_62992 | I | [
"is_prime",
"primes_in_range"
] | 2 | [
[
"primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 293932ddb3aa70797e89ec998dc8e35c4c01fd07 | cb153044b4a323b08f516000062ce378455070d2 | |||
v1.0 | instruct | Filter | Filter_62998_I | Can you provide a Python script that prints the first 100 prime numbers? | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def first_n_prime... | from solution import is_prime, first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(30) == False
def test_first_n_primes():
first_5_primes = [2, 3, 5, 7, 11]
first_10_primes = [2, 3... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_name":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00062998",
"row_id": 62998,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127408']"
} | 0.587247 | Filter_62998 | I | [
"is_prime",
"first_n_primes",
"print_first_100_primes"
] | 3 | [
[
"first_n_primes",
"is_prime"
],
[
"print_first_100_primes",
"first_n_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 80b71961f856821a401971ba743773ee10c56dcb | 7c8b6ba2be31e743893236ebc2faedb119a30432 | |||
v1.0 | instruct | Filter | Filter_63010_I | Write a Python script to load data from a JSON file, filter the data based on specific conditions, and save the filtered data to a new JSON file. The script should handle potential errors such as file not found and JSON decoding errors. | import json
import os
def load_json(file_path):
try:
with open(file_path, 'r') as file:
return json.load(file)
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
return None
except json.JSONDecodeError:
print(f"Error: File '{file_path}' is n... | import pytest
import json
from unittest import mock
from solution import load_json, filter_data, save_json, process_json
def test_load_json_file_not_found():
file_path = 'non_existent_file.json'
assert load_json(file_path) == None
def test_load_json_invalid_json():
invalid_json_content = "{ invalid json }... | [
{
"docstring": null,
"function_declaration": "def load_json(file_path):",
"function_name": "load_json",
"parameter_list": "(file_path)"
},
{
"docstring": "Filters data based on a specific condition.\nThe condition should be a function that takes an element of the data and returns True or Fal... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport os\n\ndef load_json(file_path):\n try:\n with open(file_path, 'r') as file:\n data = json.load(file)\n return data\n except FileNotFoundError... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063010",
"row_id": 63010,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127436']"
} | 0.617418 | Filter_63010 | I | [
"load_json",
"filter_data",
"save_json",
"process_json"
] | 4 | [
[
"process_json",
"filter_data"
],
[
"process_json",
"load_json"
],
[
"process_json",
"save_json"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | eff9267a1eb4ac754e770731ad86c234b18befa9 | 9622961dad303432eba078a6f55356eee5ae9963 | |||
v1.0 | instruct | Filter | Filter_63111_I | I have a list of numbers from 1 to 100. I want to write a program that can find and print all the prime numbers in this range. How can I do this in Python? | def is_prime(n):
"""
Check if a number is prime.
Parameters:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return... | from solution import is_prime, find_primes_in_range
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
def test_find_primes_in_range():
assert find_p... | [
{
"docstring": "Check if a number is prime.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if the number is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numb... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063111",
"row_id": 63111,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127674']"
} | 0.628326 | Filter_63111 | I | [
"is_prime",
"find_primes_in_range"
] | 2 | [
[
"find_primes_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d77615f3db58ef27ab1b08516cd7d2227693aaa8 | 128a70eaf9526ab2bc49a99c4d949becee991655 | |||
v1.0 | instruct | Filter | Filter_63122_I | Can you provide a Python function to calculate the factorial of a number in a parallel and efficient manner? | import concurrent.futures
def factorial_part(start, end):
result = 1
for i in range(start, end + 1):
result *= i
return result
def parallel_factorial(n, num_workers=4):
if n == 0 or n == 1:
return 1
# Determine the chunk sizes for each worker
chunk_size = (n + num_workers ... | from solution import parallel_factorial
def test_parallel_factorial_zero():
assert parallel_factorial(0) == 1
def test_parallel_factorial_one():
assert parallel_factorial(1) == 1
def test_parallel_factorial_five():
assert parallel_factorial(5) == 120
def test_parallel_factorial_ten():
assert paralle... | [
{
"docstring": null,
"function_declaration": "def factorial_part(start, end):",
"function_name": "factorial_part",
"parameter_list": "(start, end)"
},
{
"docstring": null,
"function_declaration": "def parallel_factorial(n, num_workers=4):",
"function_name": "parallel_factorial",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from concurrent.futures import ThreadPoolExecutor\n\ndef factorial_segment(start, end):\n \"\"\"\n Helper function to calculate the product of numbers in a segment [start, end].\n \"\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063122",
"row_id": 63122,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127696']"
} | 0.666431 | Filter_63122 | I | [
"factorial_part",
"parallel_factorial"
] | 2 | [
[
"parallel_factorial",
"factorial_part"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 82d5df08e62d060c00b14b782fcd955b2e27973b | 6d30d6c2c650b27df02540b758dbcece2e55a80b | |||
v1.0 | instruct | Filter | Filter_63140_I | How can I create a Python program to monitor and log network traffic using Raw Sockets? | import socket
import struct
import textwrap
def ethernet_frame(data):
'''Unpacking ethernet frame'''
dest_mac, src_mac, proto = struct.unpack('! 6s 6s H', data[:14])
return get_mac_addr(dest_mac), get_mac_addr(src_mac), socket.htons(proto), data[14:]
def get_mac_addr(mac_addr):
'''Convert a MAC addres... | import struct
from solution import ethernet_frame, get_mac_addr
def test_get_mac_addr():
assert get_mac_addr(b'\x00\x0c)\xd0(\x8e') == "00:0C:29:D0:28:8E"
assert get_mac_addr(b'\xff\xff\xff\xff\xff\xff') == "FF:FF:FF:FF:FF:FF"
def test_ethernet_frame():
# Data: Destination MAC (6 bytes) + Source MAC (6 by... | [
{
"docstring": "Unpacking ethernet frame",
"function_declaration": "def ethernet_frame(data):",
"function_name": "ethernet_frame",
"parameter_list": "(data)"
},
{
"docstring": "Convert a MAC address to a readable format",
"function_declaration": "def get_mac_addr(mac_addr):",
"functi... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import socket\nimport struct\nimport textwrap\n\ndef ethernet_frame(data):\n \"\"\"\n Unpacks the Ethernet frame.\n \"\"\"\n dest_mac, src_mac, proto = struct.unpack('! 6s 6s H', d... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063140",
"row_id": 63140,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127746']"
} | 0.56789 | Filter_63140 | I | [
"ethernet_frame",
"get_mac_addr",
"log_traffic",
"main"
] | 4 | [
[
"ethernet_frame",
"get_mac_addr"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 815f4ac79bd020445e5349659e5d0d49ecb695b1 | cf805a3977089bfceca44f5a4813bb5e29d6223f | |||
v1.0 | instruct | Filter | Filter_63142_I | I need to integrate a function in Python that performs numerical integration. Can you provide a simple example using the `scipy.integrate` module? | from scipy.integrate import quad
def integrand(x):
"""
Function to be integrated.
For example, returns the value of x^2.
"""
return x**2
def perform_integration():
"""
Performs the numerical integration of `integrand` from 0 to 1.
"""
result, error = quad(integrand, 0, 1)
retur... | from solution import integrand, perform_integration
def test_integrand():
assert integrand(2) == 4
assert integrand(0) == 0
assert integrand(-2) == 4
def test_perform_integration():
result, error = perform_integration()
assert abs(result - 1/3) < 1e-6 # The integral of x^2 from 0 to 1 is 1/3
... | [
{
"docstring": "Function to be integrated.\nFor example, returns the value of x^2.",
"function_declaration": "def integrand(x):",
"function_name": "integrand",
"parameter_list": "(x)"
},
{
"docstring": "Performs the numerical integration of `integrand` from 0 to 1.",
"function_declaratio... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy import integrate\n\ndef integrate_function(f, a, b):\n \"\"\"\n Numerically integrate the function f from a to b using scipy's quad function.\n \n Parameters:\n f (fu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063142",
"row_id": 63142,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127749']"
} | 0.545921 | Filter_63142 | I | [
"integrand",
"perform_integration"
] | 2 | [
[
"perform_integration",
"integrand"
]
] | 1 | [] | false | [] | false | pytest | true | [
"scipy"
] | false | 2e8222beef89690fadf970332a754a6753fbaa24 | 9c186fbd2a6c9070c4117b34c06a84156c6efeb5 | |||
v1.0 | instruct | Filter | Filter_63163_I | Please provide the code to create a simple calculator in Python that can perform basic arithmetic operations: addition, subtraction, multiplication, and division. The calculator should display a menu for the user to choose the operation and continue to prompt for input until the user decides to exit. | def add(a, b):
"""
Returns the sum of a and b.
"""
return a + b
def subtract(a, b):
"""
Returns the difference of a and b.
"""
return a - b
def multiply(a, b):
"""
Returns the product of a and b.
"""
return a * b
def divide(a, b):
"""
Returns the quotient of a ... | from solution import add, subtract, multiply, divide
def test_add():
assert add(3, 4) == 7
assert add(-1, -1) == -2
assert add(0, 0) == 0
assert add(1, -1) == 0
def test_subtract():
assert subtract(10, 5) == 5
assert subtract(-1, 1) == -2
assert subtract(0, 0) == 0
assert subtract(7, 1... | [
{
"docstring": "Returns the sum of a and b.",
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the difference of a and b.",
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\ndef subtract(a, b):\n \"\"\"\n Returns the difference of a and b.\n \"\"\"\n return a -... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00063163",
"row_id": 63163,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127786']"
} | 0.613339 | Filter_63163 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 39a32a25a0e12a2a8afd3435b6f54f19ab2db067 | 7a92be860314c440234d5f4d0a8f78b701ca9b31 | |||
v1.0 | instruct | Filter | Filter_63170_I | How can I create a Python generator function to yield prime numbers indefinitely? | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tru... | from solution import prime_generator
def test_prime_generator():
gen = prime_generator()
primes = [next(gen) for _ in range(10)]
assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_indefinite_primes():
gen = prime_generator()
for _ in range(1000):
prime = next(gen)
asser... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Yields prime numbers indefinitely.",
"function_declaration": "def prime_generator():",
"function_name": "prime_generator"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00063170",
"row_id": 63170,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127797']"
} | 0.550933 | Filter_63170 | I | [
"is_prime",
"prime_generator"
] | 2 | [
[
"prime_generator",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a26b3d1a9c56d4b98713e27f22a7f0c0dcccee66 | 6d779151721cc20db1c15f1ec28ea096bd3649f1 | |||
v1.0 | instruct | Filter | Filter_63181_I | Can you provide a Python script that takes a list of strings and returns a new list containing only the strings that are palindromes? | def is_palindrome(s):
"""
Checks if the given string is a palindrome.
"""
return s == s[::-1]
def filter_palindromes(strings):
"""
Takes a list of strings and returns a new list containing only the strings that are palindromes.
"""
return [s for s in strings if is_palindrome(s)] | from solution import filter_palindromes, is_palindrome
def test_is_palindrome():
assert is_palindrome("madonna") == False
assert is_palindrome("madam") == True
assert is_palindrome("racecar") == True
assert is_palindrome("palindrome") == False
assert is_palindrome("") == True
def test_filter_palin... | [
{
"docstring": "Checks if the given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a new list containing only the strings that are palindromes.",
"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Check if a given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef filter_palindromes(lst):\n \"\"\"\n Given a list of strings,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063181",
"row_id": 63181,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127828']"
} | 0.708755 | Filter_63181 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6aae8409a252cdd6aa51884e1aa920d969abfa28 | 06a820e25f00422bc3037f192877840bee4987fa | |||
v1.0 | instruct | Filter | Filter_63191_I | Can you provide a Python code to implement a simple genetic algorithm for optimizing a function, say f(x) = x^2? | import random
def fitness(individual):
"""Evaluate the fitness of an individual based on the function f(x) = x^2."""
return individual ** 2
def select_pair(population, fitnesses):
"""Select a pair of individuals from the population based on their fitnesses."""
total_fitness = sum(fitnesses)
select... | from solution import genetic_algorithm, fitness
def test_best_individual():
best_individual = genetic_algorithm(population_size=100, generations=50, mutation_rate=0.1, mutation_range=1.0)
assert isinstance(best_individual, float)
assert -10 <= best_individual <= 10
def test_fitness_function():
assert ... | [
{
"docstring": "Evaluate the fitness of an individual based on the function f(x) = x^2.",
"function_declaration": "def fitness(individual):",
"function_name": "fitness",
"parameter_list": "(individual)"
},
{
"docstring": "Select a pair of individuals from the population based on their fitnes... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef f(x):\n return x**2\n\ndef create_individual(lower_bound, upper_bound):\n return random.uniform(lower_bound, upper_bound)\n\ndef create_population(size, lower_bound,... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063191",
"row_id": 63191,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127847']"
} | 0.387121 | Filter_63191 | I | [
"fitness",
"select_pair",
"crossover",
"mutate",
"genetic_algorithm"
] | 5 | [
[
"genetic_algorithm",
"crossover"
],
[
"genetic_algorithm",
"fitness"
],
[
"genetic_algorithm",
"mutate"
],
[
"genetic_algorithm",
"select_pair"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 5461d394d1accc646e8d510e9a9cc61aebafc850 | b2a0d3a2a598d8aa38df361f4cb6c4d396bf39a5 | |||
v1.0 | instruct | Filter | Filter_63194_I | Can you provide a Python function to check if a number is prime? How can I use this function to check multiple numbers at once? | def is_prime(n):
"""
Check if a number is prime.
Args:
n (int): the number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i =... | from solution import is_prime, check_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime(25) == False... | [
{
"docstring": "Check if a number is prime.\n\nArgs:\nn (int): the number to check.\n\nReturns:\nbool: True if the number is prime, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check a list of numbers f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063194",
"row_id": 63194,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127854']"
} | 0.818322 | Filter_63194 | I | [
"is_prime",
"check_primes"
] | 2 | [
[
"check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 490bad6bbafeea8c066453d34bd97f4ba842f967 | ffd3cf31bb59e3947e8a6e516414489b0f25295c | |||
v1.0 | instruct | Filter | Filter_63217_I | Write a Python code snippet that demonstrates how to calculate the sum of all prime numbers within a given range, from `m` to `n` (inclusive). The range is provided by the user as input. The code should include a function to check if a number is prime and another function to calculate the sum of primes in the specified... | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def sum_of_primes(m, n):
"""
Calculate the sum of all prime numbers in the range from m t... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-3) == False
def test_sum_of_primes():
... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Calculate the sum of all prime numbers in the range from m to n (inclusive).",
"function_declaration": "def sum_o... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063217",
"row_id": 63217,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127890']"
} | 0.642156 | Filter_63217 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 666cc33172c3ff91d11f2ab2c643d92c87368fe8 | 05f381cce8047fc3e082d8de50fe052e9afa0498 | |||
v1.0 | instruct | Filter | Filter_63259_I | Can you help me with a Python code to simulate a simple dice game where two players roll a six-sided die and the player with the higher number wins? If the numbers are the same, it's a draw. The game continues until one player wins three rounds. | import random
def roll_die():
"""
Simulates rolling a six-sided die.
Returns a number between 1 and 6.
"""
return random.randint(1, 6)
def play_round():
"""
Simulates a round of the dice game where two players roll a die.
Returns the winner of the round: 1 if player 1 wins, 2 if player... | from solution import roll_die, play_round, play_game
def test_roll_die_within_range():
for _ in range(100):
roll = roll_die()
assert 1 <= roll <= 6
def test_play_round_winner():
results = {1: 0, 2: 0, 0: 0}
for _ in range(100):
result = play_round()
results[result] += 1
... | [
{
"docstring": "Simulates rolling a six-sided die.\nReturns a number between 1 and 6.",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Simulates a round of the dice game where two players roll a die.\nReturns the winner of th... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef simulate_game():\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063259",
"row_id": 63259,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_127986']"
} | 0.499545 | Filter_63259 | I | [
"roll_die",
"play_round",
"play_game"
] | 3 | [
[
"play_game",
"play_round"
],
[
"play_round",
"roll_die"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3bd21c7cf7c9eef9b326e0473dee037687505bb1 | 916659490ea4af0af909dec6a58e0edab77615d6 | |||
v1.0 | instruct | Filter | Filter_63273_I | I have a Python script that simulates a simple dice game. The game involves rolling a six-sided die, and the player wins if the die shows a 6. The script uses the `random` module to generate random numbers for the die roll. However, I want to modify the game so that the player has three attempts to roll a 6. If the pla... | import random
def roll_die():
return random.randint(1, 6)
def dice_game():
attempts = 3
for _ in range(attempts):
if roll_die() == 6:
return "You win!"
return "You lose!"
# Example usage:
# result = dice_game()
# print(result) | import pytest
from solution import roll_die, dice_game
def test_roll_die():
roll = roll_die()
assert 1 <= roll <= 6
def test_dice_game_win(monkeypatch):
sequence_of_rolls = [6, 3, 2]
monkeypatch.setattr('random.randint', lambda x, y: sequence_of_rolls.pop(0))
assert dice_game() == "You win!"
def ... | [
{
"docstring": null,
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def dice_game():",
"function_name": "dice_game",
"parameter_list": "()"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef game():\n \"\"\"\n Simulat... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063273",
"row_id": 63273,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128014']"
} | 0.500323 | Filter_63273 | I | [
"roll_die",
"dice_game"
] | 2 | [
[
"dice_game",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 12730ad472154373307dda5c5f56693dba59b994 | 7fc971f8af8a9df3ce3935553c1eaf7122087480 | |||
v1.0 | instruct | Filter | Filter_63285_I | Write a Python code snippet that finds and prints all prime numbers within a given range, say from 1 to 50. | def is_prime(num):
"""
Checks if a number is prime.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def find_primes(start, end):
"""
Returns a list of prime numbers in the given range [start, end].... | from solution import is_prime, find_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-7) == False
def test_find_primes():
ass... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of prime numbers in the given range [start, end].",
"function_declaration": "def find_primes(start, end):"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063285",
"row_id": 63285,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128030']"
} | 0.650846 | Filter_63285 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c3297f2facd7325daad3fff8e334950eb5a59cf9 | 9800329768b88964cf2d481c4e3d2b72a29158ad | |||
v1.0 | instruct | Filter | Filter_63295_I | Can you explain how to implement a parallel processing-based frequency counter in Python using the multiprocessing module? A frequency counter is a tool that counts the frequency of elements in a list. How can I make it parallel to improve performance on large datasets? | from collections import Counter
from multiprocessing import Pool
def count_frequencies(chunk):
"""
Counts the frequency of elements in a chunk of data.
Args:
chunk (list): A portion of the data list.
Returns:
Counter: A Counter object with frequencies of elements in the chunk.
"""... | from solution import parallel_frequency_counter
def test_parallel_frequency_counter_empty():
data = []
result = parallel_frequency_counter(data)
assert result == {}
def test_parallel_frequency_counter_single_element():
data = ['a']
result = parallel_frequency_counter(data)
assert result == {'a... | [
{
"docstring": "Counts the frequency of elements in a chunk of data.\n\nArgs:\nchunk (list): A portion of the data list.\n\nReturns:\nCounter: A Counter object with frequencies of elements in the chunk.",
"function_declaration": "def count_frequencies(chunk):",
"function_name": "count_frequencies",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import multiprocessing\nfrom collections import Counter\n\ndef count_frequencies(data_chunk):\n \"\"\"\n Counts the frequency of elements in a given chunk of data.\n \"\"\"\n retur... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063295",
"row_id": 63295,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128050']"
} | 0.510719 | Filter_63295 | I | [
"count_frequencies",
"parallel_frequency_counter"
] | 2 | [
[
"parallel_frequency_counter",
"count_frequencies"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2dcdea103125c8d63ff1b6ee53a6fe27c4e0ddab | 8684bdc0d076c4915982f804c8b785ce89f77d05 | |||
v1.0 | instruct | Filter | Filter_63318_I | Can you help me with a Python script to print the first 10 prime numbers? | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def first_n_primes(n):
... | from solution import is_prime, first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == Fals... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_name": "first_n_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if number <= 1:\n return False\n for i in range(2, int(number ** 0.5) + 1):\n if number % ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063318",
"row_id": 63318,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128090']"
} | 0.610492 | Filter_63318 | I | [
"is_prime",
"first_n_primes",
"print_first_10_primes"
] | 3 | [
[
"first_n_primes",
"is_prime"
],
[
"print_first_10_primes",
"first_n_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2463a046c66ee7cd99d78ee84f27b37ded81732f | 6789d2894da659f0e54b5a64ae5dd412656a7d2e | |||
v1.0 | instruct | Filter | Filter_63339_I | Can you provide a Python version of the given algorithm that uses the sigmoid activation function in a simple neural network for binary classification? | import numpy as np
def sigmoid(z):
"""
Compute the sigmoid of z
Parameters:
z : A scalar or numpy array of any size.
Return:
s : sigmoid(z)
"""
return 1 / (1 + np.exp(-z))
def forward_propagation(X, W, b):
"""
Implements the forward propagation for the neural network (one la... | import numpy as np
from solution import sigmoid, forward_propagation
def test_sigmoid():
assert np.isclose(sigmoid(0), 0.5)
assert np.isclose(sigmoid(2), 1 / (1 + np.exp(-2)))
assert np.isclose(sigmoid(-2), 1 / (1 + np.exp(2)))
def test_forward_propagation():
X = np.array([[1, 2], [3, 4]])
W = np... | [
{
"docstring": "Compute the sigmoid of z\n\nParameters:\nz : A scalar or numpy array of any size.\n\nReturn:\ns : sigmoid(z)",
"function_declaration": "def sigmoid(z):",
"function_name": "sigmoid",
"parameter_list": "(z)"
},
{
"docstring": "Implements the forward propagation for the neural n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef sigmoid(z):\n \"\"\"\n Compute the sigmoid of z\n\n Parameters:\n z : A scalar or numpy array of any size.\n\n Return:\n s : sigmoid(z)\n \"\"\"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00063339",
"row_id": 63339,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128141']"
} | 0.424197 | Filter_63339 | I | [
"sigmoid",
"forward_propagation"
] | 2 | [
[
"forward_propagation",
"sigmoid"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | a21e30383219b7438ba8e1121cbe238c94243954 | 38e9dba1db4ee688e3aaed52e9c11b5da8e5bd62 | |||
v1.0 | instruct | Filter | Filter_63360_I | How can I create a Python program that can determine if a given number is within a specified range, including the boundaries, using the `functools` module? | from functools import partial
def is_in_range(number, start, end):
"""
Determins if the number is within the range [start, end].
"""
return start <= number <= end
# A function to generate a range checker for a specific range
def range_checker(start, end):
return partial(is_in_range, start=start, e... | from solution import is_in_range, range_checker
def test_is_in_range_within():
assert is_in_range(5, 1, 10) is True
def test_is_in_range_boundaries():
assert is_in_range(1, 1, 10) is True
assert is_in_range(10, 1, 10) is True
def test_is_in_range_outside():
assert is_in_range(0, 1, 10) is False
a... | [
{
"docstring": "Determins if the number is within the range [start, end].",
"function_declaration": "def is_in_range(number, start, end):",
"function_name": "is_in_range",
"parameter_list": "(number, start, end)"
},
{
"docstring": null,
"function_declaration": "def range_checker(start, e... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from functools import partial\n\ndef is_within_range(number, lower_bound, upper_bound):\n \"\"\"\n Returns True if the number is within the given range [lower_bound, upper_bound], inclus... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063360",
"row_id": 63360,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128199']"
} | 0.544496 | Filter_63360 | I | [
"is_in_range",
"range_checker"
] | 2 | [
[
"range_checker",
"is_in_range"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f294ed1c7b2b2aa289f6c29bc761a72d5f77a8f8 | a1c8ac7245e2dc572370ad73b9fa409ddaa88fd3 | |||
v1.0 | instruct | Filter | Filter_63364_I | How can I generate a list of prime numbers within a specific range in Python? | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | from solution import is_prime, generate_primes
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(17)
def test_generate_primes():
assert generate_p... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of prime numbers within a specific range [start, end].",
"function_declaration": "def generate_primes... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063364",
"row_id": 63364,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128203']"
} | 0.647719 | Filter_63364 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a9c5751ebd0b718fe81cbd28b8dc1947cbd644ea | 81efe8e4cf91d5bc9649e6a1db5eebf6ad67ceed | |||
v1.0 | instruct | Filter | Filter_63374_I | How can I create a Python script to monitor system resources and send an email alert if the CPU usage exceeds a certain threshold? | import psutil
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email_alert(subject, body, to_email, from_email, from_email_password, smtp_server, smtp_port):
"""
Sends an email alert with the specified subject and body to the specified recipient.
"... | import psutil
from solution import send_email_alert, monitor_cpu
def test_send_email_alert(monkeypatch):
class MockSMTP:
def __init__(self, smtp_server, smtp_port):
self.smtp_server = smtp_server
self.smtp_port = smtp_port
def starttls(self):
pass
def log... | [
{
"docstring": "Sends an email alert with the specified subject and body to the specified recipient.",
"function_declaration": "def send_email_alert(subject, body, to_email, from_email, from_email_password, smtp_server, smtp_port):",
"function_name": "send_email_alert",
"parameter_list": "(subject, ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport psutil\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ndef send_email_alert(cpu_usage, threshold, recipient_email):\n \"\"\"\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063374",
"row_id": 63374,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128225']"
} | 0.634167 | Filter_63374 | I | [
"send_email_alert",
"monitor_cpu"
] | 2 | [
[
"monitor_cpu",
"send_email_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | 6777224cd9a1c990f486361ebb688f43e101d4fe | df1697ab14cd98bf75185988c2df1f845b866876 | |||
v1.0 | instruct | Filter | Filter_63381_I | Can you provide a detailed explanation and a Python code snippet for the classic problem of finding the longest palindromic substring within a given string? The problem requires identifying the longest substring that reads the same backward as forward. | def longest_palindromic_substring(s):
"""
Finds the longest palindromic substring in the given string s.
Args:
s (str): The string to be checked.
Returns:
str: The longest palindromic substring.
"""
if len(s) < 2:
return s
start, max_length = 0, 1
for i in ran... | from solution import longest_palindromic_substring
def test_single_character():
assert longest_palindromic_substring("a") == "a"
def test_two_different_characters():
assert longest_palindromic_substring("ab") == "a" or longest_palindromic_substring("ab") == "b"
def test_simple_palindrome():
assert longes... | [
{
"docstring": "Finds the longest palindromic substring in the given string s.\n\nArgs:\ns (str): The string to be checked.\n\nReturns:\nstr: The longest palindromic substring.",
"function_declaration": "def longest_palindromic_substring(s):",
"function_name": "longest_palindromic_substring",
"param... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def longest_palindromic_substring(s):\n \"\"\"\n Returns the longest palindromic substring in the given string s.\n\n Args:\n s (string): The input string.\n\n Returns:\n str... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063381",
"row_id": 63381,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128242']"
} | 0.801973 | Filter_63381 | I | [
"longest_palindromic_substring",
"expand_around_center"
] | 2 | [
[
"longest_palindromic_substring",
"expand_around_center"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 85a0f037956859bde317fe5affb748941bf9c290 | f037ca7fc25d721ef394b82402a6b11710652fbf | |||
v1.0 | instruct | Filter | Filter_63406_I | Can you create a Python script to randomly select an item from a list of candidates and send an email notification to a specified recipient? You can use Python libraries such as `random` for selecting an item and `smtplib` for sending an email. For simplicity, let's assume the email server does not require authenticati... | import random
import smtplib
from email.mime.text import MIMEText
def select_random_candidate(candidates):
"""
Selects a random candidate from the list of candidates.
"""
if not candidates:
return None
return random.choice(candidates)
def send_email_notification(recipient_email, subject, b... | import pytest
from solution import select_random_candidate, send_email_notification, notify_selected_candidate
def test_select_random_candidate():
candidates = ['Alice', 'Bob', 'Charlie']
selected_candidate = select_random_candidate(candidates)
assert selected_candidate in candidates
assert select_ran... | [
{
"docstring": "Selects a random candidate from the list of candidates.",
"function_declaration": "def select_random_candidate(candidates):",
"function_name": "select_random_candidate",
"parameter_list": "(candidates)"
},
{
"docstring": "Sends an email notification to the specified recipient... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef select_random_candidate(candidates):\n \"\"\"\n Randomly select... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063406",
"row_id": 63406,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128294']"
} | 0.398603 | Filter_63406 | I | [
"select_random_candidate",
"send_email_notification",
"notify_selected_candidate"
] | 3 | [
[
"notify_selected_candidate",
"select_random_candidate"
],
[
"notify_selected_candidate",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5e4b80a8ee0a096ecbddb63e7134739f6f2c3036 | dabe5930a181c4dd53b17bc773c0381bf4ecec3a | |||
v1.0 | instruct | Filter | Filter_63541_I | I have a list of words in a text file, each on a new line. How can I create a Python script that reads this file and prints each word with its frequency? | def word_frequencies(file_path):
"""
Reads a text file and returns a dictionary with each word and its frequency.
"""
word_count = {}
with open(file_path, 'r') as file:
for line in file:
word = line.strip() # Remove newline characters and any surrounding whitespace
... | import os
import pytest
from solution import word_frequencies, print_word_frequencies
@pytest.fixture
def sample_file(tmp_path):
"""
Creates a temporary file with sample word data for testing.
"""
data = "apple\nbanana\napple\norange\nbanana\nbanana\napple"
sample_file_path = tmp_path / "sample_tex... | [
{
"docstring": "Reads a text file and returns a dictionary with each word and its frequency.",
"function_declaration": "def word_frequencies(file_path):",
"function_name": "word_frequencies",
"parameter_list": "(file_path)"
},
{
"docstring": "Reads a text file and prints each word with its f... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_word_frequencies(file_path):\n \"\"\"\n Reads a file and counts the frequency of each word in the file.\n \n :param file_path: Path to the text file\n :return: Diction... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063541",
"row_id": 63541,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128582']"
} | 0.623485 | Filter_63541 | I | [
"word_frequencies",
"print_word_frequencies"
] | 2 | [
[
"print_word_frequencies",
"word_frequencies"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6cedb04d6329a7e867f9690c84f7c600b9a9916b | e31814c0707f874b2c7667eb16beba86b4af0810 | |||
v1.0 | instruct | Filter | Filter_63549_I | Write a Python script to filter and display the dates from a given list of date strings in the format 'YYYY-MM-DD'. The script should include a function that checks if a given date string is valid. The function should consider leap years and the correct number of days in each month. The script should also filter out an... | import re
from datetime import datetime
def is_valid_date(date_str):
"""
Checks if the given date string is a valid date in the format 'YYYY-MM-DD'.
Considers leap years and the correct number of days in each month.
"""
# Regex pattern for date validation
pattern = r'^\d{4}-\d{2}-\d{2}$'
ma... | from solution import is_valid_date, filter_valid_dates
def test_is_valid_date():
assert is_valid_date("2023-04-15") == True
assert is_valid_date("2023-13-01") == False
assert is_valid_date("2023-02-29") == False
assert is_valid_date("2020-02-29") == True
assert is_valid_date("2021-02-28") == True
... | [
{
"docstring": "Checks if the given date string is a valid date in the format 'YYYY-MM-DD'.\nConsiders leap years and the correct number of days in each month.",
"function_declaration": "def is_valid_date(date_str):",
"function_name": "is_valid_date",
"parameter_list": "(date_str)"
},
{
"doc... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom datetime import datetime\n\ndef is_valid_date(date_str):\n \"\"\"\n Validates the date string in the format 'YYYY-MM-DD' considering leap years and correct number of days... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063549",
"row_id": 63549,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128596']"
} | 0.74065 | Filter_63549 | I | [
"is_valid_date",
"filter_valid_dates"
] | 2 | [
[
"filter_valid_dates",
"is_valid_date"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 741a37eb3fbf5cc67a29bb75c311583ae2aacf8a | 8c03ac880b7d480becd3ea039712b23634a10239 | |||
v1.0 | instruct | Filter | Filter_63604_I | Create a Python script that reads a text file, counts the frequency of each word, and then prints the top 10 most common words along with their frequencies. The script should ignore common stop words such as "the", "and", "is", etc. You should use appropriate libraries and make sure the script is well-documented with c... | import re
from collections import Counter
# List of common English stop words
STOP_WORDS = {"the", "and", "is", "in", "to", "it", "that", "of", "with", "a", "on", "for", "as", "was", "were", "be", "by", "are", "this"}
def read_file(filename):
"""
Reads the content of the text file.
Args:
filename... | import pytest
from solution import read_file, count_words, get_top_n_words, STOP_WORDS
def test_read_file(tmp_path):
d = tmp_path / "sub"
d.mkdir()
file_path = d / "testfile.txt"
file_path.write_text("Hello world. This is a test file.")
content = read_file(file_path)
assert content == "Hel... | [
{
"docstring": "Reads the content of the text file.\n\nArgs:\nfilename (str): The name of the file to read.\n\nReturns:\nstr: The content of the file.",
"function_declaration": "def read_file(filename):",
"function_name": "read_file",
"parameter_list": "(filename)"
},
{
"docstring": "Filters... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import Counter\nfrom typing import List, Tuple\n\n# Define a set of common stop words to ignore\nSTOP_WORDS = {\n \"the\", \"and\", \"is\", \"in\", \"it\", \"of\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063604",
"row_id": 63604,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128708']"
} | 0.736595 | Filter_63604 | I | [
"read_file",
"filter_stop_words",
"count_words",
"get_top_n_words",
"main"
] | 5 | [
[
"count_words",
"filter_stop_words"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 98d6391c7312fd4856212ae90d7d8215663c7af6 | 5f4d08beba5ea0ea7099ea82c29065e7189cc991 | |||
v1.0 | instruct | Filter | Filter_63607_I | How can I create a simple URL shortener in Python using Flask? | from flask import Flask, request, redirect
import string
import random
app = Flask(__name__)
# Store the mapping of short url to original url
url_map = {}
def generate_short_url():
"""Generates a random short URL"""
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters... | from solution import app, url_map, generate_short_url
import pytest
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_shorten_url(client):
response = client.post('/shorten', data={'original_url': 'https://example.com'})
assert response.status_code == 200
ass... | [
{
"docstring": "Generates a random short URL",
"function_declaration": "def generate_short_url():",
"function_name": "generate_short_url",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def shorten_url():",
"function_name": "shorten_url",
"parameter_list"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, redirect, url_for\nimport string\nimport random\n\napp = Flask(__name__)\n\n# Store urls in memory (simply as a dictionary for this simple example)\nurl_mappi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063607",
"row_id": 63607,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128712']"
} | 0.522955 | Filter_63607 | I | [
"generate_short_url",
"shorten_url",
"redirect_to_original"
] | 3 | [
[
"shorten_url",
"generate_short_url"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | aa76d82e71b034346264b8c3b58379e458c25a9e | 46666e3d4011b11a547bff08cc94be1ca9e577c0 | |||
v1.0 | instruct | Filter | Filter_63632_I | Could you provide a Python code snippet that demonstrates the use of a generator function to continuously generate prime numbers indefinitely? | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def generate_primes():
"""
Generator f... | import itertools
from solution import is_prime, generate_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(13) == True
def test_generate_primes():
prime_gen = ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generator function that yields prime numbers indefinitely.",
"function_declaration": "def generate_primes():",
"function_name": "generate_primes",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_generator():\n \"\"\"\n A generator function that yields prime numbers indefinitely.\n \"\"\"\n def is_prime(n):\n \"\"\"\n Helper function to check if a nu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00063632",
"row_id": 63632,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128756']"
} | 0.528793 | Filter_63632 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0142aa165a2791dc975b5f49205acfe69ccb4100 | d587d46203361891e8d92438243235cb222d29d0 | |||
v1.0 | instruct | Filter | Filter_63675_I | How can I identify duplicate files in a directory using Python? | import os
import hashlib
def get_file_hash(file_path, hash_algorithm=hashlib.sha256):
"""
Generates a hash for a given file.
:param file_path: Path to the file.
:param hash_algorithm: Hash algorithm to use (default: hashlib.sha256).
:return: Hash value as a hexadecimal string.
"""
hash... | import tempfile
import shutil
import os
from solution import get_file_hash, find_duplicate_files
# Helper function to create a file with specific content
def create_file_with_content(directory, filename, content):
file_path = os.path.join(directory, filename)
with open(file_path, 'w') as file:
file.wri... | [
{
"docstring": "Generates a hash for a given file.\n\n:param file_path: Path to the file.\n:param hash_algorithm: Hash algorithm to use (default: hashlib.sha256).\n:return: Hash value as a hexadecimal string.",
"function_declaration": "def get_file_hash(file_path, hash_algorithm=hashlib.sha256):",
"func... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport hashlib\n\ndef get_file_hash(file_path, hash_algorithm=hashlib.sha256):\n \"\"\"\n Generates a hash for a given file.\n \n :param file_path: Path to the file.\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00063675",
"row_id": 63675,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128835']"
} | 0.600704 | Filter_63675 | I | [
"get_file_hash",
"find_duplicate_files"
] | 2 | [
[
"find_duplicate_files",
"get_file_hash"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f59653a3e0c7b1698d15f8a6cdf4b8002d8345f8 | fc2f5d6a9b4440506a610a20f94179a04a138646 | |||
v1.0 | instruct | Filter | Filter_63680_I | Can you provide a Python code snippet to simulate a simple dice game between two players? In this game, each player rolls a six-sided dice once, and the player with the higher roll wins. If the rolls are equal, it's a tie. The game should output the result of each roll and declare the winner or a tie. | import random
def roll_dice():
"""Simulates rolling a six-sided dice."""
return random.randint(1, 6)
def play_dice_game():
"""Simulates a dice game between two players and returns the result."""
player1_roll = roll_dice()
player2_roll = roll_dice()
if player1_roll > player2_roll:
... | from solution import roll_dice, play_dice_game
def test_roll_dice():
for _ in range(100):
roll = roll_dice()
assert 1 <= roll <= 6
def test_play_dice_game():
for _ in range(100):
player1_roll, player2_roll, result = play_dice_game()
assert 1 <= player1_roll <= 6
assert ... | [
{
"docstring": "Simulates rolling a six-sided dice.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a dice game between two players and returns the result.",
"function_declaration": "def play_dice_game():",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided dice.\n Returns a random integer between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_g... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063680",
"row_id": 63680,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128852']"
} | 0.472665 | Filter_63680 | I | [
"roll_dice",
"play_dice_game"
] | 2 | [
[
"play_dice_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a54a93f59cd729d1ea89529f2e41484512ae1bac | 1ec68b14060be2c9c986e8781ab25bed4e8c336b | |||
v1.0 | instruct | Filter | Filter_63699_I | Write a Python function that reads a CSV file containing a list of websites and creates a new CSV file with only the websites that have a valid SSL certificate. Use the `ssl` and `socket` modules to check the SSL certificate of each website. | import csv
import ssl
import socket
def check_ssl_certificate(hostname):
"""
Checks if the domain has a valid SSL certificate.
"""
context = ssl.create_default_context()
try:
with socket.create_connection((hostname, 443), timeout=10) as sock:
with context.wrap_socket(sock, serve... | import os
import pytest
from solution import check_ssl_certificate, filter_websites_with_ssl
def test_check_ssl_certificate():
assert check_ssl_certificate("google.com") == True
assert check_ssl_certificate("expired.badssl.com") == False # Example site with invalid SSL
def test_filter_websites_with_ssl(tmpdir... | [
{
"docstring": "Checks if the domain has a valid SSL certificate.",
"function_declaration": "def check_ssl_certificate(hostname):",
"function_name": "check_ssl_certificate",
"parameter_list": "(hostname)"
},
{
"docstring": "Reads a CSV file containing a list of websites and writes a new CSV ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nimport socket\nimport ssl\n\ndef has_valid_ssl_certificate(hostname):\n \"\"\"\n Check if the given hostname has a valid SSL certificate.\n\n :param hostname: The hostname... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063699",
"row_id": 63699,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_128898']"
} | 0.708353 | Filter_63699 | I | [
"check_ssl_certificate",
"filter_websites_with_ssl"
] | 2 | [
[
"filter_websites_with_ssl",
"check_ssl_certificate"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8bb4f39ad9adc705e2b00c7bc969fff328ef5904 | 5d2737db04e3f46d873283e11d9520c349fd88f0 | |||
v1.0 | instruct | Filter | Filter_63769_I | Can you provide a Python code snippet that performs a merge sort on a list of numbers? | def merge_sort(lst):
"""
Performs a merge sort on a list of numbers and returns a sorted list.
Args:
lst (list): A list of numbers.
Returns:
list: A sorted list.
"""
if len(lst) <= 1:
return lst
mid = len(lst) // 2
left_half = merge_sort(lst[:mid])
right_ha... | from solution import merge_sort
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_list():
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_merge_sort_mixed... | [
{
"docstring": "Performs a merge sort on a list of numbers and returns a sorted list.\n\nArgs:\nlst (list): A list of numbers.\n\nReturns:\nlist: A sorted list.",
"function_declaration": "def merge_sort(lst):",
"function_name": "merge_sort",
"parameter_list": "(lst)"
},
{
"docstring": "Merge... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on a list of numbers.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n right_half... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00063769",
"row_id": 63769,
"seed_ids": "['Qwen2.5-Coder-32B-Instruct_129040']"
} | 0.566438 | Filter_63769 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e34b711012c7d6409d602f9a7ff9de6b9e96f2ae | a1462ab5c7106114b227acc46d7ece2b7ef8f7c8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.