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_52948_I
I need help with designing a Python script that can monitor the availability and response time of a list of websites. The script should use HTTP requests to check if the website is up and measure how long it takes for the site to respond. It should run periodically, say every 10 minutes, and log the results to a file. ...
import requests import time import logging from datetime import datetime # Configure logging logging.basicConfig(filename='website_monitor.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def check_website(url): """ Check the availability and response time of a...
import pytest import requests from unittest.mock import patch from solution import check_website def mock_requests_get_success(url): class MockResponse: status_code = 200 def __init__(self, url): self.url = url return MockResponse(url) def mock_requests_get_failure(url): raise...
[ { "docstring": "Check the availability and response time of a website.\n\nArgs:\n url (str): The URL of the website to check.\n \nReturns:\n tuple: (status, response_time) where status is True if the website is up and False otherwise, \n and response_time is the time taken for the request in ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\nimport requests\nimport logging\nfrom datetime import datetime\n\n# Initialize logging\nlogging.basicConfig(filename='website_monitor.log', level=logging.INFO, \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052948", "row_id": 52948, "seed_ids": "['Qwen2.5-72B-Instruct_109030']" }
0.620418
Filter_52948
I
[ "check_website", "monitor_websites" ]
2
[ [ "monitor_websites", "check_website" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
d0edc2167bf8ad14af86bb9022f987f963b30289
7aff606e6ec8a231f60270ab4c6620cfaa371489
v1.0
instruct
Filter
Filter_52951_I
Can you write a simple function in Python that generates a random number between 1 and 100, and then checks if this number is a prime number? If it is a prime, the function should return "Prime", otherwise, it should return "Not Prime". Please include comments in your code to explain what each part does.
import random def is_prime(n): """ Checks 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 ...
from solution import is_prime, random_prime_check def test_is_prime(): # Test known prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(11) == True assert is_prime(97) == True # Test known non-prime numbers assert is_prime(1) == False assert is_prime(4) =...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates a random number between 1 and 100 and checks if it is a prime.\nReturns \"Prime\" if the number is prime, othe...
[ 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 is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ==...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052951", "row_id": 52951, "seed_ids": "['Qwen2.5-72B-Instruct_109035']" }
0.703009
Filter_52951
I
[ "is_prime", "random_prime_check" ]
2
[ [ "random_prime_check", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b6c7b0de40db81b3a816524277c974fec66e23b3
440e00bb70f725b39292b5fac29ac801d61a5010
v1.0
instruct
Filter
Filter_52956_I
Design a simple single-player dice rolling game using Python where the player rolls a six-sided die and wins if the roll is a 6. The player gets 3 attempts to win. The game should display the result of each roll and a final message at the end indicating if the player has won or lost. Include a loop to allow the player ...
import random def roll_dice(): """ Simulates rolling a six-sided die. Returns the result of the roll (an integer between 1 and 6). """ return random.randint(1, 6) def play_game(): """ Plays a single-player dice game where the player gets 3 attempts to roll a 6. Displays the result of e...
from solution import roll_dice, play_game def test_roll_dice(): results = set(roll_dice() for _ in range(1000)) # Run multiple times to check variability for result in results: assert 1 <= result <= 6 # Since play_game() and main() involve print statements and user interaction, we # would need to moc...
[ { "docstring": "Simulates rolling a six-sided die.\nReturns the result of the roll (an integer between 1 and 6).", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Plays a single-player dice game where the player gets 3 attem...
[ 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_die():\n \"\"\"\n Simulate rolling a six-sided die.\n \"\"\"\n return random.randint(1, 6)\n\ndef play_game():\n \"\"\"\n Conduct a single round of ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00052956", "row_id": 52956, "seed_ids": "['Qwen2.5-72B-Instruct_109044']" }
0.497878
Filter_52956
I
[ "roll_dice", "play_game", "main" ]
3
[ [ "play_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b46dd1fc648467030d9858f9416cfbf32955618
51e55453cfb9a0cd01faa4d0fb0c752931e8c6d6
v1.0
instruct
Filter
Filter_52971_I
Write a Python program that not only performs element-wise multiplication of two given lists but also allows the user to input the lists. The program should validate that the inputs are valid lists of numbers and that both lists are of the same length. If the inputs are invalid, the program should inform the user of th...
def validate_list(input_list): """ Validates if the input list contains only numbers. """ if not isinstance(input_list, list): return False for item in input_list: if not isinstance(item, (int, float)): return False return True def elementwise_multiply(list1, list2):...
import pytest from solution import elementwise_multiply def test_elementwise_multiply_valid_input(): assert elementwise_multiply([1, 2, 3], [4, 5, 6]) == [4, 10, 18] assert elementwise_multiply([1.5, 2.5], [2, 3]) == [3.0, 7.5] def test_elementwise_multiply_invalid_input(): with pytest.raises(ValueErr...
[ { "docstring": "Validates if the input list contains only numbers.", "function_declaration": "def validate_list(input_list):", "function_name": "validate_list", "parameter_list": "(input_list)" }, { "docstring": "Performs element-wise multiplication of two lists of numbers.", "function_d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def elementwise_multiply(list1, list2):\n \"\"\"\n Performs element-wise multiplication of two lists.\n Returns the resulting list.\n \"\"\"\n if not all(isinstance(x, (int, flo...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052971", "row_id": 52971, "seed_ids": "['Qwen2.5-72B-Instruct_109068']" }
0.664339
Filter_52971
I
[ "validate_list", "elementwise_multiply" ]
2
[ [ "elementwise_multiply", "validate_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24c6ea8e4d0e6476d1ee1f5eb3b1aa1c1069e43a
4eb2f7864c42c052219c46e519a0c8bb2771cda7
v1.0
instruct
Filter
Filter_52985_I
Design a Python function that simulates a geometric distribution and uses a hypothesis test to determine if a coin is fair, given a specific number of trials and a significance level. The function should take the number of trials, the observed number of successes, and the significance level as inputs. Utilize a statist...
import scipy.stats as stats def geometric_test(trials, successes, alpha): """ Determines if a coin is fair using a statistical test based on the geometric distribution. Parameters: trials (int): Number of trials. successes (int): Observed number of successes. alpha (float): Significanc...
from solution import geometric_test def test_geometric_test_coin_is_fair(): assert geometric_test(100, 50, 0.05) == "Fail to reject the null hypothesis: The coin is fair." def test_geometric_test_coin_is_not_fair(): assert geometric_test(100, 30, 0.05) == "Reject the null hypothesis: The coin is not fair." ...
[ { "docstring": "Determines if a coin is fair using a statistical test based on\nthe geometric distribution.\n\nParameters:\ntrials (int): Number of trials.\nsuccesses (int): Observed number of successes.\nalpha (float): Significance level for the hypothesis test.\n\nReturns:\nstr: Conclusion of the hypothesis t...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import scipy.stats as stats\n\ndef geometric_test(trials, successes, alpha):\n \"\"\"\n Determines if a coin is fair using a statistical test based on\n the geometric distribution.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00052985", "row_id": 52985, "seed_ids": "['Qwen2.5-72B-Instruct_109104']" }
0.451299
Filter_52985
I
[ "geometric_test", "check_geometric_test" ]
2
[ [ "check_geometric_test", "geometric_test" ] ]
1
[]
false
[]
false
pytest
true
[ "scipy" ]
false
f08f58b4c0164eed7a0bed9b1d134a6e31c03383
64bb4737831a4aaab78aa648ea8f91487a499162
v1.0
instruct
Filter
Filter_52988_I
can you write a python script that converts temperature from Fahrenheit to Celsius and vice versa, and then returns the temperature in a human-readable format?
def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0/9.0 def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return celsius * 9.0/5.0 + 32 def convert_temperature(temp, scale): """ Converts the tem...
import pytest from solution import fahrenheit_to_celsius, celsius_to_fahrenheit, convert_temperature def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(98.6) == pytest.approx(37, rel=1e-2) def test_celsius_to_fahren...
[ { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts Fahrenheit to Celsius.\n \"\"\"\n celsius = (fahrenheit - 32) * 5.0/9.0\n return f\"{fahrenheit}°F is {celsius:.2f}°C\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00052988", "row_id": 52988, "seed_ids": "['Qwen2.5-72B-Instruct_109107']" }
0.425127
Filter_52988
I
[ "fahrenheit_to_celsius", "celsius_to_fahrenheit", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ddde09b4e848e84639e8544f88ed526e5fadf502
f137a58e54508e91aff1fc82939da554306efdb4
v1.0
instruct
Filter
Filter_53007_I
Can you write a simple Python program that converts temperatures from Celsius to Fahrenheit and vice versa? It would be great if the program could ask the user for the temperature and the scale they are converting from and to.
def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return celsius * 9.0 / 5.0 + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0 / 9.0 def convert_temperature(temp, from_scale, to_scale): """ ...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053007", "row_id": 53007, "seed_ids": "['Qwen2.5-72B-Instruct_109139']" }
0.422538
Filter_53007
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9cd7399822751c4d60bc12316b2cf1fc2cbbfc04
d34126236dae7b7742b3a8ab4376cd71cbd6a70a
v1.0
instruct
Filter
Filter_53018_I
Can you explain how to train a basic neural network model using PyTorch?
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset # Define a simple neural network class SimpleNN(nn.Module): def __init__(self): super(SimpleNN, self).__init__() self.fc1 = nn.Linear(2, 10) self.relu = nn.ReLU() se...
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset from solution import SimpleNN, train_neural_network def test_model_initialization(): model = SimpleNN() assert isinstance(model, nn.Module) assert isinstance(model.fc1, nn.Linear) asser...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "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\nfrom torchvision import datasets, transforms\n\n# Define a simple neural network\nclass SimpleNet(nn.Module):\n def __init_...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053018", "row_id": 53018, "seed_ids": "['Qwen2.5-72B-Instruct_109157']" }
0.371162
Filter_53018
I
[ "train_neural_network", "example_usage" ]
2
[ [ "example_usage", "train_neural_network" ] ]
1
[]
false
[ "SimpleNN" ]
true
pytest
true
[ "torch" ]
false
c55597429f9f22319398d0eb1e02aa4802e071d3
78626b73781a01e4c3b1af7d46786349e9ad1de3
v1.0
instruct
Filter
Filter_53040_I
Write a Python script that generates a random sample of 1000 records with 3 columns: `timestamp`, `user_id`, and `activity`. The `timestamp` should be a random datetime between January 1, 2023, and December 31, 2023. The `user_id` should be a random integer between 1 and 1000. The `activity` should be one of the follow...
import random import csv from datetime import datetime, timedelta def generate_random_timestamp(start, end): """ Generate a random datetime between two datetime objects. """ delta = end - start random_seconds = random.randint(0, int(delta.total_seconds())) return start + timedelta(seconds=rando...
import csv from datetime import datetime def test_generate_activity_data(): filename = 'activity_data.csv' generate_activity_data(filename) with open(filename, mode='r') as file: reader = csv.reader(file) rows = list(reader) # Check that there is a header and 1000 rec...
[ { "docstring": "Generate a random datetime between two datetime objects.", "function_declaration": "def generate_random_timestamp(start, end):", "function_name": "generate_random_timestamp", "parameter_list": "(start, end)" }, { "docstring": "Generate random activity data and save it to a CS...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\nimport random\nfrom datetime import datetime, timedelta\n\ndef generate_random_datetime(start, end):\n \"\"\"\n Generates a random datetime between the start and end dates.\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053040", "row_id": 53040, "seed_ids": "['Qwen2.5-72B-Instruct_109195']" }
0.665339
Filter_53040
I
[ "generate_random_timestamp", "generate_activity_data" ]
2
[ [ "generate_activity_data", "generate_random_timestamp" ] ]
1
[]
false
[]
false
pytest
false
[]
true
816eb24171200050fff04c9372d97a99be18a531
38b4179849831d15538d6487670ab0149eaf8413
v1.0
instruct
Filter
Filter_53041_I
I have a series of strings and I need to sort them in a specific order based on the numeric values contained within the strings, which may be in different formats (e.g., "5 apples", "12 oranges", "100 bananas"). The numeric values should be the primary key for sorting, and if two strings have the same numeric value, th...
import re def extract_number_and_text(s): """ Extracts the numeric value and the text from the input string. :param s: Input string containing a numeric value followed by some text :type s: str :return: A tuple containing the numeric value and the text :rtype: tuple """ match = re....
from solution import sort_strings def test_sorting_basic(): input_strings = ["12 oranges", "5 apples", "100 bananas", "7 grapes"] expected_output = ["5 apples", "7 grapes", "12 oranges", "100 bananas"] assert sort_strings(input_strings) == expected_output def test_sorting_with_same_numbers(): input_st...
[ { "docstring": "Extracts the numeric value and the text from the input string.\n\n:param s: Input string containing a numeric value followed by some text\n:type s: str\n:return: A tuple containing the numeric value and the text\n:rtype: tuple", "function_declaration": "def extract_number_and_text(s):", ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef extract_number_and_text(s):\n \"\"\"\n Helper function to extract number and text from the string.\n \"\"\"\n match = re.match(r'(\\d+)\\s*(.*)', s)\n if not ma...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053041", "row_id": 53041, "seed_ids": "['Qwen2.5-72B-Instruct_109198']" }
0.683193
Filter_53041
I
[ "extract_number_and_text", "sort_strings" ]
2
[ [ "sort_strings", "extract_number_and_text" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f241ddc1839d59368687bf33ad855984d6f93a2
b8b4b7b7596a2e00f724bea55af4293edcc9c627
v1.0
instruct
Filter
Filter_53046_I
Could you explain how to implement a basic genetic algorithm for optimizing a simple function in Python?
import random def generate_individual(min_value, max_value): return random.uniform(min_value, max_value) def generate_population(size, min_value, max_value): return [generate_individual(min_value, max_value) for _ in range(size)] def fitness(individual): return individual ** 2 def select_parents(populat...
from solution import generate_individual, generate_population, fitness, select_parents, crossover, mutate, genetic_algorithm def test_generate_individual(): individual = generate_individual(-10, 10) assert -10 <= individual <= 10 def test_generate_population(): population = generate_population(10, -10, 10...
[ { "docstring": null, "function_declaration": "def generate_individual(min_value, max_value):", "function_name": "generate_individual", "parameter_list": "(min_value, max_value)" }, { "docstring": null, "function_declaration": "def generate_population(size, min_value, max_value):", "f...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef initialize_population(pop_size, x_min, x_max):\n return [random.uniform(x_min, x_max) for _ in range(pop_size)]\n\ndef fitness(x):\n return x ** 2\n\ndef select(popu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053046", "row_id": 53046, "seed_ids": "['Qwen2.5-72B-Instruct_109206']" }
0.448204
Filter_53046
I
[ "generate_individual", "generate_population", "fitness", "select_parents", "crossover", "mutate", "genetic_algorithm" ]
7
[ [ "generate_population", "generate_individual" ], [ "genetic_algorithm", "crossover" ], [ "genetic_algorithm", "generate_population" ], [ "genetic_algorithm", "mutate" ], [ "genetic_algorithm", "select_parents" ], [ "mutate", "generate_individual" ...
7
[]
false
[]
false
pytest
true
[]
true
dc4eb9285cae7a91868d4adcbb81c9cbdfdc32b8
297ac545efbdb4f248892987d1c94860dafa65c2
v1.0
instruct
Filter
Filter_53052_I
Develop a Python script that processes a folder of images, applies a specified filter (like grayscale or sepia), and saves the processed images in a new folder. The script should take the source folder, destination folder, and filter type as command-line arguments. How would you go about writing this script, and what l...
import os import sys from PIL import Image, ImageOps def apply_grayscale(image): return ImageOps.grayscale(image) def apply_sepia(image): sepia_image = image.convert("RGB") width, height = sepia_image.size pixels = sepia_image.load() for py in range(height): for px in range(width): ...
import os import shutil from PIL import Image from solution import process_images_in_folder def setup_module(module): os.makedirs('test_source', exist_ok=True) os.makedirs('test_destination', exist_ok=True) image = Image.new('RGB', (100, 100), color='red') image.save('test_source/image1.jpg') image...
[ { "docstring": null, "function_declaration": "def apply_grayscale(image):", "function_name": "apply_grayscale", "parameter_list": "(image)" }, { "docstring": null, "function_declaration": "def apply_sepia(image):", "function_name": "apply_sepia", "parameter_list": "(image)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport sys\nfrom PIL import Image, ImageOps\n\ndef apply_grayscale(image):\n return ImageOps.grayscale(image)\n\ndef apply_sepia(image):\n sepia_image = image.convert(\"RGB\")...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053052", "row_id": 53052, "seed_ids": "['Qwen2.5-72B-Instruct_109219']" }
0.533472
Filter_53052
I
[ "apply_grayscale", "apply_sepia", "process_image", "process_images_in_folder" ]
4
[ [ "process_image", "apply_grayscale" ], [ "process_image", "apply_sepia" ], [ "process_images_in_folder", "process_image" ] ]
3
[]
false
[]
false
pytest
true
[ "PIL" ]
false
4dc54bb664259e31728ea0022d7c55c78566975b
764404ac512a39c7c96c62797440823a99609829
v1.0
instruct
Filter
Filter_53054_I
Implement a function in Python to create a simple, stylized cloud symbol using Matplotlib. The cloud should consist of semi-circular arcs and the function should accept parameters for the center of the cloud and its scale size. Additionally, include functionality to adjust the color of the cloud. Demonstrate the correc...
import matplotlib.pyplot as plt import numpy as np def draw_cloud(ax, center, scale, color='blue'): """ Draw a stylized cloud on the provided axes `ax`. Parameters: - ax: Matplotlib axes object where the cloud will be drawn. - center: A tuple (x, y) representing the center of the cloud. - scal...
import matplotlib.pyplot as plt from solution import draw_cloud def test_draw_cloud(): fig, ax = plt.subplots() ax.set_xlim(-10, 10) ax.set_ylim(-10, 10) draw_cloud(ax, center=(0, 0), scale=3, color='blue') # Check if lines have been drawn on the axes lines = ax.get_lines() assert len(...
[ { "docstring": "Draw a stylized cloud on the provided axes `ax`.\n\nParameters:\n- ax: Matplotlib axes object where the cloud will be drawn.\n- center: A tuple (x, y) representing the center of the cloud.\n- scale: A float representing the size of the cloud.\n- color: A string representing the color of the clou...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import matplotlib.pyplot as plt\nimport matplotlib.patches as patches\n\ndef draw_cloud(x, y, scale, color='blue'):\n fig, ax = plt.subplots()\n\n # Draw the base ellipse for the cloud\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053054", "row_id": 53054, "seed_ids": "['Qwen2.5-72B-Instruct_109221']" }
0.421864
Filter_53054
I
[ "draw_cloud", "plot_cloud_example" ]
2
[ [ "plot_cloud_example", "draw_cloud" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
0c017e85ddcb5f36dcfe8863ce65f44f7310f937
51b7919e4a4821b50f76e4a843c65b95dabb8dfa
v1.0
instruct
Filter
Filter_53064_I
How can I implement an iterative merge sort algorithm in Python?
def merge_sort_iterative(arr): """ Iteratively sort an array using merge sort algorithm. """ width = 1 n = len(arr) while width < n: for i in range(0, n, 2 * width): left = arr[i:i + width] right = arr[i + width:i + 2 * width] arr[i:i + 2 * width] = me...
from solution import merge_sort_iterative def test_merge_sort_iterative_empty(): assert merge_sort_iterative([]) == [] def test_merge_sort_iterative_single(): assert merge_sort_iterative([1]) == [1] def test_merge_sort_iterative_sorted(): assert merge_sort_iterative([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] d...
[ { "docstring": "Iteratively sort an array using merge sort algorithm.", "function_declaration": "def merge_sort_iterative(arr):", "function_name": "merge_sort_iterative", "parameter_list": "(arr)" }, { "docstring": "Merge two sorted arrays into one sorted array.", "function_declaration":...
[ 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 Iteratively sort array using merge sort algorithm.\n \"\"\"\n width = 1\n n = len(arr)\n while width < n:\n for i in range(0, n, 2*widt...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053064", "row_id": 53064, "seed_ids": "['Qwen2.5-72B-Instruct_109231']" }
0.586991
Filter_53064
I
[ "merge_sort_iterative", "merge" ]
2
[ [ "merge_sort_iterative", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c4073f25753dd47009cb77474c2c82059225a4a2
32a17efb71e28718c0f386620005e04bc055a33a
v1.0
instruct
Filter
Filter_53068_I
Write a simple python program that converts temperature from Celsius to Fahrenheit and vice versa. The program should have a simple menu to select the conversion direction and input the temperature value. It should also validate the input to ensure it's a number.
def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5/9 def convert_temperature(direction, temp): """ Converts temperatu...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053068", "row_id": 53068, "seed_ids": "['Qwen2.5-72B-Instruct_109237']" }
0.458658
Filter_53068
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
af054b54815ac297938a45941bb250437b264d5d
45b2664ba46ee839b8b955c20f114d7c8a519776
v1.0
instruct
Filter
Filter_53073_I
Write a program in Python that creates a dictionary with the keys being the letters from A to Z, and the values being the corresponding positions in the alphabet (1 for A, 2 for B, etc.). Then, write a function that takes a string as input and returns a list of the positions of each character in the alphabet, using the...
def create_alphabet_dict(): """ Creates a dictionary with keys being letters from A to Z and values being their corresponding positions in the alphabet. """ import string alphabet_dict = {letter: idx + 1 for idx, letter in enumerate(string.ascii_uppercase)} return alphabet_dict def string_t...
from solution import create_alphabet_dict, string_to_positions def test_create_alphabet_dict(): alphabet_dict = create_alphabet_dict() assert alphabet_dict['A'] == 1 assert alphabet_dict['Z'] == 26 assert alphabet_dict['M'] == 13 def test_string_to_positions_all_letters(): assert string_to_positio...
[ { "docstring": "Creates a dictionary with keys being letters from A to Z\nand values being their corresponding positions in the alphabet.", "function_declaration": "def create_alphabet_dict():", "function_name": "create_alphabet_dict", "parameter_list": "()" }, { "docstring": "Takes a string...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_alphabet_dict():\n \"\"\"\n Creates a dictionary with keys being letters from A to Z (uppercase) and values being their positions in the alphabet.\n \"\"\"\n return {chr...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053073", "row_id": 53073, "seed_ids": "['Qwen2.5-72B-Instruct_109247']" }
0.617271
Filter_53073
I
[ "create_alphabet_dict", "string_to_positions" ]
2
[ [ "string_to_positions", "create_alphabet_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
49c5093c9363c84a01c537f8708d4ea168dc15cd
a9ef294174afa4589e36c9547a3b1e03d3c33fea
v1.0
instruct
Filter
Filter_53081_I
Generate a Python code snippet that simulates a simple game of rock, paper, scissors. The game should allow a human player to input their choice, randomly generate a choice for the computer, and then determine the winner according to the rules of the game. The game should be played in a loop until the human player deci...
import random def get_computer_choice(): """ Randomly generates and returns a choice for the computer. """ choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(player_choice, computer_choice): """ Determines the winner of a rock-paper-scissors game. ...
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(): # Test cases for player winning assert determine_winner('rock', 'scissors...
[ { "docstring": "Randomly generates and returns a choice 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 game.\n\nArguments:\nplayer_choic...
[ 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 returns one of 'rock', 'paper', or 'scissors'.\n \"\"\"\n options = ['rock', 'paper', 'scissors']\n return random...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053081", "row_id": 53081, "seed_ids": "['Qwen2.5-72B-Instruct_109257']" }
0.487667
Filter_53081
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ], [ "play_game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
92675eaf0297347cddbd18767f4c22ff0b0b7bbe
2b6e5c6bb2dd1a3fc55ee82fbe2f86fa8f3a94dd
v1.0
instruct
Filter
Filter_53093_I
I want to implement a basic machine learning model in Python that can classify emails as spam or not spam. Can you guide me through the process?
import pandas as pd from sklearn.model_selection import train_test_split from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB from sklearn.metrics import accuracy_score, classification_report def load_data(): # Load the dataset (replace 'emails.csv' with your da...
import pandas as pd from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB from solution import load_data, preprocess_data, split_data, vectorize_data, train_model, ev...
[ { "docstring": null, "function_declaration": "def load_data():", "function_name": "load_data", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def preprocess_data(data):", "function_name": "preprocess_data", "parameter_list": "(data)" }, { "docstri...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import ac...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053093", "row_id": 53093, "seed_ids": "['Qwen2.5-72B-Instruct_109278']" }
0.493864
Filter_53093
I
[ "load_data", "preprocess_data", "split_data", "vectorize_data", "train_model", "evaluate_model", "classify_emails" ]
7
[ [ "classify_emails", "evaluate_model" ], [ "classify_emails", "load_data" ], [ "classify_emails", "preprocess_data" ], [ "classify_emails", "split_data" ], [ "classify_emails", "train_model" ], [ "classify_emails", "vectorize_data" ] ]
6
[]
false
[]
false
pytest
true
[ "pandas", "sklearn" ]
false
e3bcf5d44106a620654dd20479e986f2213b6c8b
8bc65f4340adc9fd6de050c330faeca77a899f5a
v1.0
instruct
Filter
Filter_53104_I
Write a code in Python to simulate a rock-paper-scissors game against the computer. The user should be able to input their choice (rock, paper, or scissors), and the computer should randomly select its choice. The program should then determine the winner based on the rules of rock-paper-scissors. Make sure to include a...
import random def get_computer_choice(): """ Function to return a random choice from rock, paper, or scissors. """ return random.choice(['rock', 'paper', 'scissors']) def determine_winner(user_choice, computer_choice): """ Function to determine the winner of a rock-paper-scissors game. """...
from solution import determine_winner def test_determine_winner_user_wins(): assert determine_winner('rock', 'scissors') == 'User' assert determine_winner('paper', 'rock') == 'User' assert determine_winner('scissors', 'paper') == 'User' def test_determine_winner_computer_wins(): assert determine_winne...
[ { "docstring": "Function to return a random choice from rock, paper, or scissors.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Function to determine the winner of a rock-paper-scissors game.", "f...
[ 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 Function to return a random choice from rock, paper, or scissors.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053104", "row_id": 53104, "seed_ids": "['Qwen2.5-72B-Instruct_109292']" }
0.493978
Filter_53104
I
[ "get_computer_choice", "determine_winner", "play_game" ]
3
[ [ "play_game", "determine_winner" ], [ "play_game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d711af491336a18fadad45f9ea2cbe48286dc957
2deaf807500fb3573117bdcb7542a65708a42745
v1.0
instruct
Filter
Filter_53155_I
Write a program in Python that demonstrates the concept of "functional programming". Use a real-world analogy to explain the code you write. For example, if you choose to implement a function that processes a list of numbers, you could compare this to a factory line that takes raw materials (the numbers) and processes ...
def fahrenheit_to_celsius(fahrenheit): """ Convert Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0/9.0 def above_freezing(fahrenheit): """ Check if the temperature in Fahrenheit is above freezing point (32 F). """ return fahrenheit > 32 def process_temperatures(temperatures):...
from solution import fahrenheit_to_celsius, above_freezing, process_temperatures def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 def test_above_freezing(): assert above_freezing(33) == True assert above_freezing(32) == False assert a...
[ { "docstring": "Convert Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Check if the temperature in Fahrenheit is above freezing point (32 F).", "funct...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import reduce\n\ndef apply_paint(car):\n return f\"{car} with paint\"\n\ndef add_tires(car):\n return f\"{car} with tires\"\n\ndef add_engine(car):\n return f\"{car} wi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053155", "row_id": 53155, "seed_ids": "['Qwen2.5-72B-Instruct_109375']" }
0.44058
Filter_53155
I
[ "fahrenheit_to_celsius", "above_freezing", "process_temperatures" ]
3
[ [ "process_temperatures", "above_freezing" ], [ "process_temperatures", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a78ed75125b365f1f0497ec243ef650beaf6be65
796979d2efd8235ac47d7c5e1f2f7f897fa720e9
v1.0
instruct
Filter
Filter_53162_I
Write a Python function to simulate the rolling of two six-sided dice and return the sum of the two dice. Also, include a function to simulate rolling these two dice 1000 times and return the frequency distribution of the sums. Use the random module for generating the dice rolls.
import random from collections import defaultdict def roll_two_dice(): """ Simulates the rolling of two six-sided dice and returns the sum. """ die1 = random.randint(1, 6) die2 = random.randint(1, 6) return die1 + die2 def roll_dice_1000_times(): """ Simulates rolling two six-sided dic...
from solution import roll_two_dice, roll_dice_1000_times def test_roll_two_dice(): sum_of_dice = roll_two_dice() assert 2 <= sum_of_dice <= 12 def test_roll_dice_1000_times(): frequencies = roll_dice_1000_times() assert sum(frequencies.values()) == 1000 assert all(2 <= sum_of_dice <= 12 for sum_of...
[ { "docstring": "Simulates the rolling of two six-sided dice and returns the sum.", "function_declaration": "def roll_two_dice():", "function_name": "roll_two_dice", "parameter_list": "()" }, { "docstring": "Simulates rolling two six-sided dice 1000 times and returns the frequency distributio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom collections import defaultdict\n\ndef roll_two_dice():\n \"\"\"\n Simulates rolling two six-sided dice and returns the sum of the two dice.\n \"\"\"\n die1 = ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053162", "row_id": 53162, "seed_ids": "['Qwen2.5-72B-Instruct_109389']" }
0.706061
Filter_53162
I
[ "roll_two_dice", "roll_dice_1000_times" ]
2
[ [ "roll_dice_1000_times", "roll_two_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92f11b211863a75654affe222946541475d704c8
168f08e6fdd38bb133c0730e3ece21d27bc72856
v1.0
instruct
Filter
Filter_53167_I
Explain the process of creating a custom function in Python that takes a list of integers and returns a new list containing only the prime numbers from the original list. Include a sample implementation of the function.
def is_prime(num): """ Determines if num is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def filter_prim...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False def test_filter_primes_all_primes(): assert filter_primes...
[ { "docstring": "Determines if num is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from the input list.", "function_declaration": "def filter_primes(numbers):", ...
[ 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 Determines if num is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053167", "row_id": 53167, "seed_ids": "['Qwen2.5-72B-Instruct_109398']" }
0.602839
Filter_53167
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ee5547e1521edc22c7f9b7ad9b6c7b331139425
e6a51a1f3057edd14961374fbf99b5b7e3e75e5b
v1.0
instruct
Filter
Filter_53201_I
Implement a recursive function to calculate the nth term of the Fibonacci sequence in Python. Please also include a simple check function to validate your implementation with the first 10 terms of the Fibonacci sequence.
def fibonacci(n): """ Returns the nth term in the Fibonacci sequence. """ if n <= 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def check_fibonacci(): """ Validates the Fibonacci implementation with the first 10 terms. """ ...
from solution import fibonacci, check_fibonacci def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_recursive_cases(): assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 def test_fibonacci_large...
[ { "docstring": "Returns the nth term in the Fibonacci sequence.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Validates the Fibonacci implementation with the first 10 terms.", "function_declaration": "def check_fib...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fib(n):\n \"\"\"\n Returns the nth term of the Fibonacci sequence.\n \n :param n: the term index (0-based)\n :return: the nth term of the Fibonacci sequence\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053201", "row_id": 53201, "seed_ids": "['Qwen2.5-72B-Instruct_109456']" }
0.766746
Filter_53201
I
[ "fibonacci", "check_fibonacci" ]
2
[ [ "check_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7e1e29d4a6109317c2b1fa0072053d5483cce2e
6199b5a195e2518431672728847d3119131bec0c
v1.0
instruct
Filter
Filter_53209_I
You're tasked with building a small project that requires converting a given string to its SHA-256 hash equivalent in Python. Additionally, the program should verify if a given SHA-256 hash matches the hash of the provided string. The program should be user-friendly, allowing the user to input a string, then choose whe...
import hashlib def convert_to_sha256(input_string): """ Converts the provided string to its SHA-256 hash equivalent. Args: input_string (str): The string to be converted to SHA-256 hash. Returns: str: The SHA-256 hash of the input string. """ if not isinstance(input_string, st...
from solution import convert_to_sha256, verify_sha256 def test_convert_to_sha256_valid_input(): assert convert_to_sha256("test") == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" def test_convert_to_sha256_empty_string(): assert convert_to_sha256("") == "e3b0c44298fc1c149afbf4c8996fb92427a...
[ { "docstring": "Converts the provided string to its SHA-256 hash equivalent.\n\nArgs:\ninput_string (str): The string to be converted to SHA-256 hash.\n\nReturns:\nstr: The SHA-256 hash of the input string.", "function_declaration": "def convert_to_sha256(input_string):", "function_name": "convert_to_sh...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\n\ndef convert_to_sha256(input_string):\n \"\"\"\n Converts the provided string to its SHA-256 hash equivalent.\n \n Args:\n input_string (str): The string to be ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053209", "row_id": 53209, "seed_ids": "['Qwen2.5-72B-Instruct_109471']" }
0.757285
Filter_53209
I
[ "convert_to_sha256", "verify_sha256" ]
2
[ [ "verify_sha256", "convert_to_sha256" ] ]
1
[]
false
[]
false
pytest
true
[]
true
68b026bae6b6e59bc5a8a179437e3b2d90e90553
538a8f6cdfb23cef9e1afee51490343c7be84aef
v1.0
instruct
Filter
Filter_53216_I
Design a Python function that takes a list of numerical values and rounds each value to the nearest 10. The function should return a list of these rounded values. For a given number, if the value is exactly halfway between two multiples of 10, it should be rounded up. For example, 15 should round to 20, 25 to 30, and s...
def round_to_nearest_10(numbers): """ Rounds each number in the list to the nearest 10. If a number is halfway between two multiples of 10, it is rounded up. """ rounded_numbers = [] for num in numbers: remainder = num % 10 if remainder >= 5: rounded_number = (num // ...
from solution import round_to_nearest_10, check_solution def test_round_to_nearest_10(): assert round_to_nearest_10([12, 15, 25, 34, 45, 46, 55]) == [10, 20, 30, 30, 50, 50, 60] assert round_to_nearest_10([5, 14, 19, 23, 35, 47, 50]) == [10, 10, 20, 20, 40, 50, 50] assert round_to_nearest_10([20, 30, 40, 5...
[ { "docstring": "Rounds each number in the list to the nearest 10.\nIf a number is halfway between two multiples of 10, it is rounded up.", "function_declaration": "def round_to_nearest_10(numbers):", "function_name": "round_to_nearest_10", "parameter_list": "(numbers)" }, { "docstring": null...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def round_to_nearest_10(numbers):\n \"\"\"\n Rounds each number in the list to the nearest 10.\n \n Args:\n numbers (list of float or int): A list of numerical values.\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053216", "row_id": 53216, "seed_ids": "['Qwen2.5-72B-Instruct_109481']" }
0.614234
Filter_53216
I
[ "round_to_nearest_10", "check_solution" ]
2
[ [ "check_solution", "round_to_nearest_10" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d99d4f2efda68e5d72eef4d45224c8ba8e4d0fb
0b9a2e96d5e5a6ecef27cb671159165f58e1fefe
v1.0
instruct
Filter
Filter_53221_I
Write a Python script that checks if a given number is a prime number or not. The script should take an input from the user, check if the number is prime, and then print a message indicating whether the number is prime or not. Make sure to handle edge cases, such as negative numbers and the number 1, which are not cons...
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 p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def check_prime(): ...
from solution import is_prime def test_is_prime_negative_number(): assert is_prime(-5) == False assert is_prime(-1) == False def test_is_prime_zero_and_one(): assert is_prime(0) == False assert is_prime(1) == False def test_is_prime_two(): assert is_prime(2) == True def test_is_prime_even_number...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes an input from the user, checks if the number is prime, and prints a message.", "function_declaration": "def che...
[ 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 given number is a prime number.\n \n Parameters:\n n (int): The number to check.\n \n Returns:\n bool: True if the number is prim...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053221", "row_id": 53221, "seed_ids": "['Qwen2.5-72B-Instruct_109488']" }
0.739645
Filter_53221
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d55728104784e266c9bf2248c6074d5247d8951
ea3b94dcb71529a4cb44f2df71ddd7dd3fdb726e
v1.0
instruct
Filter
Filter_53238_I
Can you generate a code snippet to simulate a basic blockchain in Python? It should be simple and easy to understand, focusing on the core concepts of a blockchain, such as blocks, transactions, and the chain itself.
import hashlib import time class Block: def __init__(self, index, previous_hash, timestamp, data, hash): self.index = index self.previous_hash = previous_hash self.timestamp = timestamp self.data = data self.hash = hash def calculate_hash(index, previous_hash, timestamp, da...
from solution import Block, Blockchain, create_genesis_block, create_new_block def test_create_genesis_block(): genesis_block = create_genesis_block() assert genesis_block.index == 0 assert genesis_block.previous_hash == "0" assert genesis_block.data == "Genesis Block" assert isinstance(genesis_blo...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, previous_hash, transactions, timestamp=None):\n self.index = index\n self.previous_hash = previous_hash...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053238", "row_id": 53238, "seed_ids": "['Qwen2.5-72B-Instruct_109515']" }
0.390532
Filter_53238
I
[ "calculate_hash", "create_genesis_block", "create_new_block" ]
3
[ [ "create_genesis_block", "calculate_hash" ], [ "create_new_block", "calculate_hash" ] ]
2
[]
false
[ "Block", "Blockchain" ]
true
pytest
true
[]
true
cfe4e1bcae42f2741ae92fa5a4be8c2a82c11b3c
8e4fc50a081ecc78c9a6cf16a3892eb766033358
v1.0
instruct
Filter
Filter_53255_I
Can you provide an example of a Python function that filters a list of numbers, returning only those that are prime?
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def filter_primes(numbe...
from solution import is_prime, filter_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(1) == False assert is_prime(-5) == False def test_filter_primes_with_mixed_numbers(): assert filte...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Filters the list of numbers, returning only the prime numbers.", "function_declaration": "def filter_primes(numbers):", ...
[ 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 check if a number is prime.\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053255", "row_id": 53255, "seed_ids": "['Qwen2.5-72B-Instruct_109548']" }
0.649893
Filter_53255
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bcaa317a120a152968b94dfc0b6be1f5512d2e9a
eb2bfdec876614b8620763823fba052e9ce5da67
v1.0
instruct
Filter
Filter_53262_I
Write a Python function that takes a list of integers and returns a new list containing only the unique elements from the original list, preserving the order in which they first appeared. The function should be named `filter_unique` and take a single argument, `numbers_list`. Additionally, include a simple check functi...
def filter_unique(numbers_list): """ Returns a list containing only the unique elements from the original list, preserving the order in which they first appeared. """ seen = set() unique_list = [] for number in numbers_list: if number not in seen: seen.add(number) ...
from solution import filter_unique def test_filter_unique_with_repeats(): assert filter_unique([1, 2, 3, 2, 1]) == [1, 2, 3] def test_filter_unique_mixed_elements(): assert filter_unique([4, 5, 6, 7, 4, 6, 8]) == [4, 5, 6, 7, 8] def test_filter_unique_with_other_repeats(): assert filter_unique([10, 20, 1...
[ { "docstring": "Returns a list containing only the unique elements from the original list,\npreserving the order in which they first appeared.", "function_declaration": "def filter_unique(numbers_list):", "function_name": "filter_unique", "parameter_list": "(numbers_list)" }, { "docstring": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def filter_unique(numbers_list):\n \"\"\"\n Returns a new list containing only the unique elements from the original list,\n preserving the order in which they first appeared.\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053262", "row_id": 53262, "seed_ids": "['Qwen2.5-72B-Instruct_109557']" }
0.71904
Filter_53262
I
[ "filter_unique", "verify_solution" ]
2
[ [ "verify_solution", "filter_unique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa17ea49d80f6afcecc4dc64a2e60ed41b45f7e8
12df12e97e13c5f02f6d016ec260445352792ed1
v1.0
instruct
Filter
Filter_53267_I
Write a script to ping a list of hosts and report their statuses. The script should be written in Python.
import os def ping_host(host): """ Pings a given host and returns True if the host is reachable, otherwise False. """ response = os.system(f"ping -c 1 {host} > /dev/null 2>&1") return response == 0 def ping_hosts(hosts): """ Pings a list of hosts and returns a dictionary with hostnames as ...
from solution import ping_host, ping_hosts def test_ping_host_reachable(): assert ping_host("google.com") == True def test_ping_host_unreachable(): assert ping_host("nonexistent.local") == False def test_ping_hosts(): hosts = ["google.com", "nonexistent.local"] statuses = ping_hosts(hosts) assert...
[ { "docstring": "Pings a given host and returns True if the host is reachable, otherwise False.", "function_declaration": "def ping_host(host):", "function_name": "ping_host", "parameter_list": "(host)" }, { "docstring": "Pings a list of hosts and returns a dictionary with hostnames as keys a...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef ping_host(host):\n \"\"\"\n Pings a given host and returns True if the host is reachable, otherwise False.\n \"\"\"\n response = os.system(f\"ping -c 1 {host} > /d...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053267", "row_id": 53267, "seed_ids": "['Qwen2.5-72B-Instruct_109564']" }
0.657851
Filter_53267
I
[ "ping_host", "ping_hosts" ]
2
[ [ "ping_hosts", "ping_host" ] ]
1
[]
false
[]
false
pytest
true
[]
true
707593b7630196c717a52e5a14fef33c906a987c
557c80f9f1060a665aad52872b7c68d1e1e9583e
v1.0
instruct
Filter
Filter_53315_I
Implement a secure and efficient algorithm to hash a given string using SHA-256 in Python, and demonstrate how to verify a string against a hashed value. Additionally, include a method to generate a salt, and explain how salting enhances the security of hashed passwords.
import hashlib import os def generate_salt(length=16): """ Generates a random salt of the given length. """ return os.urandom(length) def hash_string_with_salt(string, salt): """ Hashes a string using SHA-256 with the provided salt. """ sha = hashlib.sha256() sha.update(salt + stri...
from solution import generate_salt, hash_string_with_salt, verify_string_with_salt def test_generate_salt_length(): salt = generate_salt() assert len(salt) == 16 def test_hash_string_with_salt(): salt = generate_salt() string = "my_secure_password" hashed_value = hash_string_with_salt(string, salt...
[ { "docstring": "Generates a random salt of the given length.", "function_declaration": "def generate_salt(length=16):", "function_name": "generate_salt", "parameter_list": "(length=16)" }, { "docstring": "Hashes a string using SHA-256 with the provided salt.", "function_declaration": "de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import hashlib\nimport os\n\ndef generate_salt(length=16):\n \"\"\"\n Generates a random salt of the given length.\n \"\"\"\n return os.urandom(length)\n\ndef hash_string_sha256(in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053315", "row_id": 53315, "seed_ids": "['Qwen2.5-72B-Instruct_109635']" }
0.644096
Filter_53315
I
[ "generate_salt", "hash_string_with_salt", "verify_string_with_salt" ]
3
[ [ "verify_string_with_salt", "hash_string_with_salt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
425a2b6c4ffa4ea437ced4abc69cafb30af0d0d1
6b442fcfa00cd3fca10e84d08362da0fe28d6edb
v1.0
instruct
Filter
Filter_53356_I
Write a program in Python that implements a Caesar cipher, which is a type of substitution cipher where each letter in the plaintext is shifted by a certain number of places down the alphabet. The program should include functions for both encryption and decryption. It should also handle both uppercase and lowercase let...
def caesar_cipher_encrypt(plaintext, shift): """ Encrypts the plaintext using a Caesar cipher with the specified shift. """ encrypted_text = [] for char in plaintext: if char.isalpha(): shift_base = ord('A') if char.isupper() else ord('a') encrypted_char = chr(sh...
from solution import caesar_cipher_encrypt, caesar_cipher_decrypt def test_caesar_cipher_encrypt(): assert caesar_cipher_encrypt("hello", 3) == "khoor" assert caesar_cipher_encrypt("HELLO", 3) == "KHOOR" assert caesar_cipher_encrypt("hello, world!", 3) == "khoor, zruog!" assert caesar_cipher_encrypt("P...
[ { "docstring": "Encrypts the plaintext using a Caesar cipher with the specified shift.", "function_declaration": "def caesar_cipher_encrypt(plaintext, shift):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(plaintext, shift)" }, { "docstring": "Decrypts the ciphertext which w...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "def caesar_cipher_encrypt(plaintext, shift):\n \"\"\"\n Encrypts the plaintext using a Caesar cipher with the specified shift.\n \"\"\"\n encrypted_text = ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053356", "row_id": 53356, "seed_ids": "['Qwen2.5-72B-Instruct_109701']" }
0.712295
Filter_53356
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt", "user_interface" ]
3
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ], [ "user_interface", "caesar_cipher_decrypt" ], [ "user_interface", "caesar_cipher_encrypt" ] ]
3
[]
false
[]
false
pytest
true
[]
true
e606b74605b2f5d8ee302e21867b5aa034d31550
6d32a9345569a5da5f869c8e5162793695f002ab
v1.0
instruct
Filter
Filter_53457_I
Can you help me generate a Python program that simulates a simple dice roll game? The game should have a player who rolls a six-sided die, and the computer should also roll a six-sided die. The program should then compare the results and announce the winner (player or computer). If both roll the same number, it should ...
import random def roll_dice(): """ Simulate rolling a six-sided die. Returns a random integer between 1 and 6. """ return random.randint(1, 6) def determine_winner(player_roll, computer_roll): """ Determines the winner based on the rolls. Returns 'player' if the player wins, 'computer'...
import pytest from solution import roll_dice, determine_winner def test_roll_dice(): for _ in range(100): result = roll_dice() assert 1 <= result <= 6 def test_determine_winner_player_wins(): assert determine_winner(6, 4) == 'player' assert determine_winner(5, 3) == 'player' def test_dete...
[ { "docstring": "Simulate rolling a six-sided die.\nReturns a random integer between 1 and 6.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Determines the winner based on the rolls.\nReturns 'player' if the player wins, '...
[ 1, 0, 0 ]
1
medium
0.333
{ "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 integer between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef determin...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053457", "row_id": 53457, "seed_ids": "['Qwen2.5-72B-Instruct_109869']" }
0.509185
Filter_53457
I
[ "roll_dice", "determine_winner", "dice_roll_game" ]
3
[ [ "dice_roll_game", "determine_winner" ], [ "dice_roll_game", "roll_dice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9c65214d4faac05b133739255d824b902dc8b3ac
8a0da26a85a6ebfc38b45fa1bc4eb6fd073e61d4
v1.0
instruct
Filter
Filter_53523_I
How can I create a simple chatbot for my website using Python and Flask?
from flask import Flask, request, jsonify app = Flask(__name__) # Define basic chatbot responses responses = { "hi": "Hello! How can I help you today?", "hello": "Hi! What can I do for you?", "how are you": "I'm just a bot, but I'm doing great! How about you?", "bye": "Goodbye! Have a great day!", } ...
import pytest from solution import get_bot_response def test_bot_response_hello(): assert get_bot_response("hi") == "Hello! How can I help you today?" assert get_bot_response("hello") == "Hi! What can I do for you?" def test_bot_response_how_are_you(): assert get_bot_response("how are you") == "I'm just a...
[ { "docstring": "This function returns a response based on the user's message.", "function_declaration": "def get_bot_response(message):", "function_name": "get_bot_response", "parameter_list": "(message)" }, { "docstring": null, "function_declaration": "def chat():", "function_name":...
[ 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, request, jsonify\n\napp = Flask(__name__)\n\n# Define basic chatbot responses\nresponses = {\n \"hi\": \"Hello! How can I help you today?\",\n \"hello\": \"Hi! W...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053523", "row_id": 53523, "seed_ids": "['Qwen2.5-72B-Instruct_109969']" }
0.401258
Filter_53523
I
[ "get_bot_response", "chat" ]
2
[ [ "chat", "get_bot_response" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
c456da75c5e82bf3a9a296cef2713071a9a073a1
1c4d57dd3e925fac94191b3e805a6cf64bdc72ab
v1.0
instruct
Filter
Filter_53532_I
I have a project where I need to compare the efficiency of various sorting algorithms, including Bubble Sort, Quick Sort, and Merge Sort, in Python. Can you provide sample code for each of these algorithms to help me with my project?
def bubble_sort(arr): """ Bubble Sort algorithm. """ n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr def quick_sort(arr): """ Quick Sort algorithm. """ if len(arr) ...
from solution import bubble_sort, quick_sort, merge_sort def test_bubble_sort(): assert bubble_sort([64, 34, 25, 12, 22, 11, 90]) == [11, 12, 22, 25, 34, 64, 90] assert bubble_sort([]) == [] assert bubble_sort([1]) == [1] assert bubble_sort([2, 1]) == [1, 2] assert bubble_sort([1, 2, 3, 4, 5]) == [...
[ { "docstring": "Bubble Sort algorithm.", "function_declaration": "def bubble_sort(arr):", "function_name": "bubble_sort", "parameter_list": "(arr)" }, { "docstring": "Quick Sort algorithm.", "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bubble_sort(arr):\n \"\"\"\n Bubble Sort algorithm.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053532", "row_id": 53532, "seed_ids": "['Qwen2.5-72B-Instruct_109979']" }
0.505626
Filter_53532
I
[ "bubble_sort", "quick_sort", "merge_sort", "merge" ]
4
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
75c536ed880e1cd2d0abd070910ca8f5be3b8e60
c89be34af322ab3c71ed66f1684bac1ea5782a0c
v1.0
instruct
Filter
Filter_53541_I
How can I create a basic chatbot using Python and Flask to improve customer support service?
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/chatbot', methods=['POST']) def chatbot(): user_message = request.json.get('message') response = generate_response(user_message) return jsonify({"response": response}) def generate_response(message): """ Generates a simp...
import pytest from flask import json from solution import app, generate_response @pytest.fixture def client(): with app.test_client() as client: yield client def test_generate_response(): assert generate_response("hello") == "Hi there! How can I help you today?" assert generate_response("What is t...
[ { "docstring": null, "function_declaration": "def chatbot():", "function_name": "chatbot", "parameter_list": "()" }, { "docstring": "Generates a simple response based on keyword matching.", "function_declaration": "def generate_response(message):", "function_name": "generate_response...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\nresponses = {\n \"hello\": \"Hi there! How can I help you today?\",\n \"hi\": \"Hello! How can I assist you?\",\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053541", "row_id": 53541, "seed_ids": "['Qwen2.5-72B-Instruct_109994']" }
0.382709
Filter_53541
I
[ "chatbot", "generate_response" ]
2
[ [ "chatbot", "generate_response" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
22f328d962d83d7c3c7ed903af4cae7d247946d9
5ce7c04529607d52ee44d2f00ab79350f7a3af1a
v1.0
instruct
Filter
Filter_53552_I
I need to create a Python script that automates the process of downloading files from a list of URLs and saving them to a specified directory. Can you provide a sample script for this?
import os import requests def download_file(url, save_path): """ Downloads a file from the given URL and saves it to the specified path. Args: url (str): URL of the file to be downloaded. save_path (str): Path where the file will be saved. """ response = requests.get(url) response.rais...
import os import pytest import requests from unittest.mock import patch from solution import download_file, download_files # Mocking requests.get to avoid actual network calls during testing class MockResponse: def __init__(self, content, status_code): self.content = content self.status_code = stat...
[ { "docstring": "Downloads a file from the given URL and saves it to the specified path.\n\nArgs:\nurl (str): URL of the file to be downloaded.\nsave_path (str): Path where the file will be saved.", "function_declaration": "def download_file(url, save_path):", "function_name": "download_file", "param...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport requests\n\ndef download_file(url, directory):\n \"\"\"\n Downloads a file from the given URL and saves it to the specified directory.\n \n :param url: URL of the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053552", "row_id": 53552, "seed_ids": "['Qwen2.5-72B-Instruct_110013']" }
0.608091
Filter_53552
I
[ "download_file", "download_files" ]
2
[ [ "download_files", "download_file" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
6fb384d03ab9118721c534100028794c9ba00234
0679e38051834db44d0113fcb81438bffc642dd0
v1.0
instruct
Filter
Filter_53555_I
Write a Python code that sorts a list of integers in ascending order using the quick sort algorithm. Make sure to include a function that checks if the list is sorted and returns a message indicating whether the sorting was successful or not. Please include comments in your code to explain the steps.
def quick_sort(arr): """ Sorts a list of integers in ascending order using the quick sort algorithm. """ if len(arr) <= 1: return arr else: pivot = arr[len(arr) // 2] less = [x for x in arr if x < pivot] equal = [x for x in arr if x == pivot] greater = [x for ...
from solution import quick_sort, is_sorted, check_sorted_message def test_quick_sort(): assert quick_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] assert quick_sort([5, 3, 8, 6, 2, 7, 4, 1]) == [1, 2, 3, 4, 5, 6, 7, 8] assert quick_sort([]) == [] assert quick_sort([1]) ==...
[ { "docstring": "Sorts a list of integers in ascending order using the quick sort algorithm.", "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" }, { "docstring": "Checks if a list is sorted in ascending order.", "function_declaration...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort(arr):\n \"\"\"\n Sorts a list of integers in ascending order using the quick sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n else:\n piv...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053555", "row_id": 53555, "seed_ids": "['Qwen2.5-72B-Instruct_110021']" }
0.615162
Filter_53555
I
[ "quick_sort", "is_sorted", "check_sorted_message" ]
3
[ [ "check_sorted_message", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1429c5fb80b2bb07c263d1497fd36b816d581e44
fd4dc2df9ef7c643582c9cb4ede477e59130c980
v1.0
instruct
Filter
Filter_53560_I
Can you write a Python script to check if a website is up and running? It should output "Website is up" or "Website is down" based on the status. Additionally, it should log the uptime and downtime in a file named `uptime.log`, including the date and time of the check. The script should be robust and handle exceptions ...
import requests from datetime import datetime def check_website(url): """ Checks if a website is up and running. Args: url (str): The URL of the website to check. Returns: str: "Website is up" if the website is reachable, otherwise "Website is down". """ try: response = re...
from solution import check_website import requests from unittest.mock import patch def test_check_website_up(): with patch('requests.get') as mocked_get: mocked_get.return_value.status_code = 200 assert check_website("http://example.com") == "Website is up" def test_check_website_down(): with ...
[ { "docstring": "Checks if a website is up and running.\n\nArgs:\nurl (str): The URL of the website to check.\n\nReturns:\nstr: \"Website is up\" if the website is reachable, otherwise \"Website is down\".", "function_declaration": "def check_website(url):", "function_name": "check_website", "paramet...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom datetime import datetime\n\ndef check_website(url):\n \"\"\"\n Checks if the website at the given URL is up and running.\n Logs the result to uptime.log includin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053560", "row_id": 53560, "seed_ids": "['Qwen2.5-72B-Instruct_110030']" }
0.537025
Filter_53560
I
[ "check_website", "log_status" ]
2
[ [ "check_website", "log_status" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
1ea636246cebc9bfd02bd494035d62116382a3b3
3ae6384d96a6ab9a01fec1586aae9eddf1de3b74
v1.0
instruct
Filter
Filter_53569_I
I need to create a Python script that can automatically download files from a list of URLs and save them in a specific directory. The script should also log the success or failure of each download. How can I do this?
import os import requests def download_file(url, directory): """ Downloads a file from a given URL and saves it to the specified directory. Logs the success or failure of the download. Parameters: url (str): The URL of the file to be downloaded. directory (str): The directory where the fil...
from unittest.mock import patch, mock_open import pytest from solution import download_file, download_files @patch("solution.requests.get") @patch("builtins.open", new_callable=mock_open) @patch("solution.os.makedirs") def test_download_file_success(mock_makedirs, mock_open, mock_requests): url = "https://example....
[ { "docstring": "Downloads a file from a given URL and saves it to the specified directory.\nLogs the success or failure of the download.\n\nParameters:\nurl (str): The URL of the file to be downloaded.\ndirectory (str): The directory where the file should be saved.\n\nReturns:\nstr: The path to the downloaded f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport requests\nfrom urllib.parse import urlparse\n\ndef download_files(urls, save_directory, log_file):\n \"\"\"\n Downloads files from a list of URLs and saves them in a sp...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053569", "row_id": 53569, "seed_ids": "['Qwen2.5-72B-Instruct_110043']" }
0.628112
Filter_53569
I
[ "download_file", "download_files" ]
2
[ [ "download_files", "download_file" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
d6feb07ff0296e756c787cd29afe6d726a10d3e0
78774aedca0073e23edbdcb69d96fa58619dc7b3
v1.0
instruct
Filter
Filter_53588_I
I need to create a simple web application using Flask that displays a table of products and their prices. The application should also allow users to add a product, which will then be displayed in the table. How can I achieve this?
from flask import Flask, request, render_template_string app = Flask(__name__) products = [] @app.route('/') def home(): return render_template_string(""" <html> <body> <h1>Product List</h1> <table border="1"> <tr> <t...
import pytest from solution import app @pytest.fixture def client(): with app.test_client() as client: yield client def test_home_page(client): response = client.get('/') assert response.status_code == 200 assert b'<h1>Product List</h1>' in response.data def test_add_product(client): prod...
[ { "docstring": null, "function_declaration": "def home():", "function_name": "home", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def add_product():", "function_name": "add_product", "parameter_list": "()" } ]
[ 0, 1, 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, redirect, url_for\n\napp = Flask(__name__)\n\n# In-memory storage for products\nproducts = []\n\n@app.route('/')\ndef index():\n return re...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053588", "row_id": 53588, "seed_ids": "['Qwen2.5-72B-Instruct_110072']" }
0.40448
Filter_53588
I
[ "home", "add_product" ]
2
[ [ "add_product", "home" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
0bff835085a47c28d00df9733b51e4d2730b0481
28960f912b051eb429a91f39f17fb146a32a00a1
v1.0
instruct
Filter
Filter_53600_I
Implement a basic chatbot using Flask in Python. The chatbot should be able to respond to simple greetings like "Hi" or "Hello" with a predefined response. Please include the necessary code and any setup instructions for running the chatbot.
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/chat', methods=['POST']) def chat(): user_message = request.json.get('message') if user_message: response = get_response(user_message) return jsonify({'response': response}) else: return jsonify({'res...
import pytest from solution import app @pytest.fixture def client(): with app.test_client() as client: yield client def test_chat_hi(client): response = client.post('/chat', json={'message': 'hi'}) data = response.get_json() assert response.status_code == 200 assert data['response'] == 'He...
[ { "docstring": null, "function_declaration": "def chat():", "function_name": "chat", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_response(message):", "function_name": "get_response", "parameter_list": "(message)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n@app.route('/chat', methods=['POST'])\ndef chat():\n user_message = request.json.get('message')\n \n if user_mess...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053600", "row_id": 53600, "seed_ids": "['Qwen2.5-72B-Instruct_110095']" }
0.42469
Filter_53600
I
[ "chat", "get_response" ]
2
[ [ "chat", "get_response" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
c095d65b7b722231fce052fc7f680b8cdc1dd7be
79504549de9ebc4efa117e9367850e90fe4fd784
v1.0
instruct
Filter
Filter_53626_I
I need to create a Python function that reads a text file, processes it, and saves the processed data. I want to ensure that the function can handle large files efficiently without loading the entire file into memory at once. How can I achieve this?
def process_large_file(input_file_path, output_file_path): """ Reads a large text file, processes each line, and writes the processed lines to an output file. :param input_file_path: Path to the input text file :param output_file_path: Path to the output text file """ with open(input_file_p...
import os from solution import process_large_file, process_line def test_process_line(): assert process_line(" Hello World ") == "HELLO WORLD" assert process_line("test") == "TEST" assert process_line("") == "" def test_process_large_file(tmpdir): input_file_path = os.path.join(tmpdir, "input.txt") ...
[ { "docstring": "Reads a large text file, processes each line, and writes the processed lines to an output file.\n\n:param input_file_path: Path to the input text file\n:param output_file_path: Path to the output text file", "function_declaration": "def process_large_file(input_file_path, output_file_path):"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_file(input_file_path, output_file_path, process_line_func):\n \"\"\"\n Reads a text file, processes it line by line, and writes the processed data to another file.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053626", "row_id": 53626, "seed_ids": "['Qwen2.5-72B-Instruct_110143']" }
0.418985
Filter_53626
I
[ "process_large_file", "process_line" ]
2
[ [ "process_large_file", "process_line" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19a0915ce31a8439baddf36e7319763c243e1851
90a1d94cdfc41cff0ad6322766fa5880283907d0
v1.0
instruct
Filter
Filter_53629_I
Design a Python function that computes the sum of all prime numbers up to a given number, utilizing a highly optimized algorithm. The function should be capable of efficiently handling a high volume of data, such as processing the sum of all prime numbers up to 1,000,000. Additionally, the function should be designed t...
def sieve_of_eratosthenes(limit): """ Generates a list of primes up to the given limit using the Sieve of Eratosthenes. Parameters: limit (int): The upper limit to generate prime numbers. Returns: list: A list of prime numbers up to the given limit. """ if limit < 2: re...
from solution import sieve_of_eratosthenes, sum_of_primes def test_sieve_of_eratosthenes_small_limit(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] def test_sieve_of_eratosthenes_large_limit(): primes_up_to_50 = sieve_of_eratosthenes(50) expected_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, ...
[ { "docstring": "Generates a list of primes up to the given limit using the Sieve of Eratosthenes.\n\nParameters:\nlimit (int): The upper limit to generate prime numbers.\n\nReturns:\nlist: A list of prime numbers up to the given limit.", "function_declaration": "def sieve_of_eratosthenes(limit):", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_primes(n):\n \"\"\"\n Returns the sum of all prime numbers up to and including n using the Sieve of Eratosthenes algorithm.\n \n Parameters:\n n (int): The upper limi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053629", "row_id": 53629, "seed_ids": "['Qwen2.5-72B-Instruct_110148']" }
0.645757
Filter_53629
I
[ "sieve_of_eratosthenes", "sum_of_primes" ]
2
[ [ "sum_of_primes", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7c6c75d3dd51f4aac7134d60722c14e92d752daa
4bb17746fdaf121f3a41880f90e484c23a819798
v1.0
instruct
Filter
Filter_53645_I
Write a Python script that creates a dictionary containing file names as keys and their corresponding MD5 hash values as values. The script should read files from a specified directory. Ensure the script handles files of different types and sizes, and manages potential errors when reading files (e.g., permission errors...
import os import hashlib def calculate_md5(file_path): """ Calculate the MD5 hash of a given file. """ hash_md5 = hashlib.md5() try: with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) except (PermissionError,...
import pytest import tempfile import os from solution import calculate_md5, generate_md5_dict def test_calculate_md5(): with tempfile.NamedTemporaryFile(delete=False) as tf: tf.write(b"test content") tf.close() assert calculate_md5(tf.name) == hashlib.md5(b"test content").hexdigest() ...
[ { "docstring": "Calculate the MD5 hash of a given file.", "function_declaration": "def calculate_md5(file_path):", "function_name": "calculate_md5", "parameter_list": "(file_path)" }, { "docstring": "Generate a dictionary with file names as keys and their MD5 hash values as values\nfor all f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport hashlib\n\ndef get_file_md5(file_path):\n \"\"\"\n Returns MD5 hash of the file at the given file_path.\n \"\"\"\n hash_md5 = hashlib.md5()\n try:\n wit...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053645", "row_id": 53645, "seed_ids": "['Qwen2.5-72B-Instruct_110179']" }
0.790695
Filter_53645
I
[ "calculate_md5", "generate_md5_dict" ]
2
[ [ "generate_md5_dict", "calculate_md5" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5a44d2a2d4e03f66180d51731d68e4e989b872e6
790ee415b5f8c9067e7dad9123d5f7e05951a2dc
v1.0
instruct
Filter
Filter_53652_I
can you write a Python function to implement a basic Caesar cipher and its decryption? Also, provide a brief explanation of the Caesar cipher.
def caesar_cipher_encrypt(text, shift): """ Encrypts the given text using a Caesar cipher with the specified shift. Parameters: text (str): The plaintext to be encrypted. shift (int): The number of positions to shift each letter. Returns: str: The encrypted cipherte...
def test_caesar_cipher_encrypt(): assert caesar_cipher_encrypt("HELLO", 3) == "KHOOR" assert caesar_cipher_encrypt("hello", 3) == "khoor" assert caesar_cipher_encrypt("WORLD", 5) == "BTWQI" assert caesar_cipher_encrypt("world", 5) == "btwqi" assert caesar_cipher_encrypt("Python3.8", 10) == "Zidryx3....
[ { "docstring": "Encrypts the given text using a Caesar cipher with the specified shift.\n\nParameters:\n text (str): The plaintext to be encrypted.\n shift (int): The number of positions to shift each letter.\n \nReturns:\n str: The encrypted ciphertext.", "function_declaration": "def caesar_cip...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_encrypt(plaintext, shift):\n \"\"\"\n Encrypts plaintext using a Caesar cipher with given shift.\n \n :param plaintext: The input string to encrypt.\n :param s...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053652", "row_id": 53652, "seed_ids": "['Qwen2.5-72B-Instruct_110194']" }
0.605131
Filter_53652
I
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt" ]
2
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ] ]
1
[]
false
[]
false
pytest
false
[]
true
6ce9a7039e0c847c4c2cf42d1660c18004d031a8
a2e1c4f4eab72b5531b6f1aa31a9f3964cbbd366
v1.0
instruct
Filter
Filter_53657_I
I want to learn how to code a simple game in Python. Can you guide me through creating a basic version of "Rock, Paper, Scissors"?
import random def get_computer_choice(): """Randomly choose between 'rock', 'paper', or 'scissors' for the computer.""" options = ['rock', 'paper', 'scissors'] return random.choice(options) def determine_winner(user_choice, computer_choice): """Determine the winner of the rock-paper-scissors game.""" ...
from solution import determine_winner, play_round def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'user' assert determine_winner('scissors', 'paper') == 'user' assert determine_winner('paper', 'rock') == 'user' assert determine_winner('rock', 'paper') == 'computer' ...
[ { "docstring": "Randomly choose between 'rock', 'paper', or 'scissors' for the computer.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determine the winner of the rock-paper-scissors game.", "func...
[ 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 get_computer_choice():\n \"\"\"\n Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice.\n \"\"\"\n choices = ['rock', 'paper', 'scissors']\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053657", "row_id": 53657, "seed_ids": "['Qwen2.5-72B-Instruct_110200']" }
0.363496
Filter_53657
I
[ "get_computer_choice", "determine_winner", "play_round" ]
3
[ [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7626ef1dd77fadbba177e10009b940865008a88a
d1f5a0cf48af21643d8bf8c6e864dda1b4e922da
v1.0
instruct
Filter
Filter_53658_I
Design a Python program that creates a loop to print out all the prime numbers from 1 to 100. Additionally, implement a function that checks if a number is prime and use this function within your loop. Ensure your code is efficient and well-commented.
def is_prime(n): """ Check if a number is prime. :param n: The number to check. :return: True if the number is prime, False otherwise. """ 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): ...
from solution import is_prime, print_primes_up_to_100 def test_is_prime_for_prime_numbers(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True assert is_prime(11) == True assert is_prime(13) == True def test_is_prime_for_non_prime_numbe...
[ { "docstring": "Check if a number is prime.\n\n:param n: The number to check.\n:return: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Print all the prime numbers from 1 to 10...
[ 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": "00053658", "row_id": 53658, "seed_ids": "['Qwen2.5-72B-Instruct_110202']" }
0.670895
Filter_53658
I
[ "is_prime", "print_primes_up_to_100" ]
2
[ [ "print_primes_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8b3fb5941efb754fcde3d9aadac452655fdd352
be3083e35ad321c1237972ebd3fd3407f1172148
v1.0
instruct
Filter
Filter_53665_I
Can you help me with a Python script to automate the process of downloading images from a list of URLs and saving them into a specific folder? I want to make sure that the script also logs any errors if a download fails.
import os import requests from urllib.parse import urlparse def download_image(url, folder): """ Downloads an image from the specified URL and saves it in the specified folder. Parameters: url (str): The URL to download the image from. folder (str): The folder to save the downloaded image into...
import os import pytest from unittest.mock import patch, mock_open, call from solution import download_images, log_error, download_image def test_download_image_success(): url = 'http://example.com/image.jpg' folder = 'test_folder' with patch('requests.get') as mocked_get: mocked_get.return_va...
[ { "docstring": "Downloads an image from the specified URL and saves it in the specified folder.\n\nParameters:\nurl (str): The URL to download the image from.\nfolder (str): The folder to save the downloaded image into.\n\nReturns:\nstr: The file path of the downloaded image if successful, None otherwise.", ...
[ 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 requests\nimport logging\n\ndef setup_logging(log_file='download.log'):\n logging.basicConfig(level=logging.ERROR, \n format='%(asctime)s %(levelnam...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053665", "row_id": 53665, "seed_ids": "['Qwen2.5-72B-Instruct_110214']" }
0.583278
Filter_53665
I
[ "download_image", "log_error", "download_images" ]
3
[ [ "download_image", "log_error" ], [ "download_images", "download_image" ] ]
2
[]
false
[]
false
pytest
true
[ "requests" ]
false
0cbeec1f79916dd5588b3c2e77824ace8953f31a
e70ab8da596a51e5bf56b21a17ebc7295199b8ff
v1.0
instruct
Filter
Filter_53680_I
Write a function in Python that checks if a number is a prime number and returns `True` if it is, and `False` otherwise. Additionally, the function should be able to find the next prime number greater than a given input number and return this value. If the input number itself is prime, the function should return the ne...
def is_prime(n): """ Check if a given number is prime. Args: n (int): The number to check. Returns: bool: True if n 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 = 5 ...
from solution import is_prime, next_prime 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(10) == False assert is_prime(29) == True assert is_prime(1) == False assert is_prime(0) == False ...
[ { "docstring": "Check if a given number is prime.\n\nArgs:\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": "Find the next prime number g...
[ 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(n):\n \"\"\"\n Checks if a 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 % 3 == ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053680", "row_id": 53680, "seed_ids": "['Qwen2.5-72B-Instruct_110235']" }
0.720978
Filter_53680
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7df7fa0a36436f13a1f75de13145d5692676ba0
d8a67539aa59e9111a6ee340b034a598647692e8
v1.0
instruct
Filter
Filter_53691_I
Design a programming question that tests a candidate's understanding of using the Python `asyncio` library for asynchronous programming, specifically focusing on handling multiple asynchronous tasks concurrently and efficiently.
import aiohttp import asyncio import logging logging.basicConfig(level=logging.INFO) CONCURRENCY_LIMIT = 5 async def fetch_data(session, url): try: async with session.get(url) as response: response.raise_for_status() data = await response.text() logging.info(f"Fetched ...
import pytest from solution import run_fetch_all_data @pytest.mark.asyncio async def test_fetch_all_data_success(): # URLs for testing purpose, using some public APIs urls = [ "https://jsonplaceholder.typicode.com/posts/1", "https://jsonplaceholder.typicode.com/posts/2", "https://jsonpl...
[ { "docstring": null, "function_declaration": "def run_fetch_all_data(urls):", "function_name": "run_fetch_all_data", "parameter_list": "(urls)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import asyncio\n\nasync def fetch_data(source):\n \"\"\"\n Simulates fetching data from an asynchronous source. It sleeps for a duration\n representing the delay from that source and ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053691", "row_id": 53691, "seed_ids": "['Qwen2.5-72B-Instruct_110252']" }
0.393799
Filter_53691
I
[ "fetch_data", "fetch_all_data", "run_fetch_all_data" ]
3
[ [ "fetch_all_data", "fetch_data" ], [ "run_fetch_all_data", "fetch_all_data" ] ]
2
[]
false
[]
false
pytest
true
[ "aiohttp" ]
false
9c938a89211c6cb9d99d42b67d40a0c400fe076c
62f7f0797837cb97719816286299f5d7ccd9fa84
v1.0
instruct
Filter
Filter_53706_I
Design a Python program that generates a list of 10 unique random numbers between 1 and 100, and then sorts the list in ascending order. Include functionality to allow the user to specify the range and the number of unique numbers they would like to generate. Additionally, provide the ability to sort the list in descen...
import random def generate_unique_random_numbers(count, start, end, sort_order='ascending'): """ Generates a list of unique random numbers within a specified range and sorts the list in ascending or descending order. Parameters: - count: Number of unique random numbers to generate. - start...
from solution import generate_unique_random_numbers def test_generate_unique_random_numbers_ascending(): result = generate_unique_random_numbers(5, 1, 10, 'ascending') assert len(result) == 5 assert all(isinstance(num, int) for num in result) assert result == sorted(result) assert len(result) == le...
[ { "docstring": "Generates a list of unique random numbers within a specified range\nand sorts the list in ascending or descending order.\n\nParameters:\n- count: Number of unique random numbers to generate.\n- start: Start of the range (inclusive).\n- end: End of the range (inclusive).\n- sort_order: 'ascending...
[ 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 generate_unique_random_numbers(count, start=1, end=100):\n if count > (end - start + 1):\n raise ValueError(\"Cannot generate more unique numbers than are availa...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053706", "row_id": 53706, "seed_ids": "['Qwen2.5-72B-Instruct_110276']" }
0.610147
Filter_53706
I
[ "generate_unique_random_numbers", "command_line_interface" ]
2
[ [ "command_line_interface", "generate_unique_random_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e17f5d7b70425ab4e10b15d2adf6eb08cc45b841
133a76ec92c64ecd82e2769772f8cf9332c12bd8
v1.0
instruct
Filter
Filter_53707_I
Given a set of differential equations that model predator-prey dynamics, how would you simulate the system and visualize the results in Python? Please provide a practical example.
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt def predator_prey_system(y, t, alpha, beta, delta, gamma): """ Defines the differential equations for the predator-prey system. Arguments: y : array State of the system, [prey_population, predator_populat...
import numpy as np from solution import predator_prey_system, simulate_predator_prey def test_predator_prey_system(): alpha = 0.1 beta = 0.02 delta = 0.01 gamma = 0.1 y = [40, 9] t = 0 dydt = predator_prey_system(y, t, alpha, beta, delta, gamma) assert len(dydt) == 2 assert isinstan...
[ { "docstring": "Defines the differential equations for the predator-prey system.\n\nArguments:\ny : array\n State of the system, [prey_population, predator_population]\nt : float\n Time\nalpha : float\n Prey birth rate\nbeta : float\n Prey death rate due to predation\ndelta : float\n Predator bir...
[ 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.integrate import odeint\nimport matplotlib.pyplot as plt\n\n# Define the predator-prey model equations\ndef predator_prey_system(y, t, alpha, beta, delta, gamma)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053707", "row_id": 53707, "seed_ids": "['Qwen2.5-72B-Instruct_110277']" }
0.314664
Filter_53707
I
[ "predator_prey_system", "simulate_predator_prey", "plot_predator_prey", "main" ]
4
[ [ "simulate_predator_prey", "predator_prey_system" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy", "scipy" ]
false
7be2219e8430e209539cbde715dc7a44c1c7dbd6
77045f5d68708431f0d3c8b9a3669aaef4cfda40
v1.0
instruct
Filter
Filter_53715_I
Design a Python function that takes in a list of strings and filters out elements based on a provided pattern. The pattern filtering should focus on excluding strings that match a specific keyword exactly, but the keyword itself is allowed to remain in the list. For example, if the keyword is "apple", any string that e...
def filter_by_keyword(strings, keyword): """ Filters out elements from the list of strings that match the keyword exactly. Keeps the keyword if it appears within a longer string. Args: strings: List of strings to filter. keyword: String keyword to filter by. Returns: Filtered l...
from solution import filter_by_keyword, verify_results def test_filter_by_keyword(): assert filter_by_keyword(["apple", "red apple", "green apple", "apple pie"], "apple") == ["red apple", "green apple", "apple pie"] assert filter_by_keyword(["banana", "yellow banana", "ripe banana"], "banana") == ["yellow bana...
[ { "docstring": "Filters out elements from the list of strings that match the keyword exactly.\nKeeps the keyword if it appears within a longer string.\n\nArgs:\nstrings: List of strings to filter.\nkeyword: String keyword to filter by.\n\nReturns:\nFiltered list of strings.", "function_declaration": "def fi...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def filter_by_keyword(lst, keyword):\n \"\"\"\n Filters out elements from the list that match the keyword exactly.\n \n Parameters:\n lst (list): A list of strings.\n keyword...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053715", "row_id": 53715, "seed_ids": "['Qwen2.5-72B-Instruct_110296']" }
0.633513
Filter_53715
I
[ "filter_by_keyword", "verify_results" ]
2
[ [ "verify_results", "filter_by_keyword" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e52badd671dbd600a80eba5ec27b71f515023cbe
84333ccbf942732117ec52782160de5f09467481
v1.0
instruct
Filter
Filter_53719_I
Write a python script to convert a JSON file to CSV. The script should be able to handle nested JSON structures and flatten them before writing to the CSV file. Assume the JSON file is well-formed. Provide a detailed explanation of the script.
import json import csv def flatten_json(y): """ Flatten a nested json file Args: y (dict): The json file as a dictionary Returns: dict: The flattened version of the json """ out = {} def flatten(x, name=''): if type(x) is dict: for a in x: flat...
import pytest from solution import flatten_json, json_to_csv import json import os import csv def test_flatten_json(): nested_json = { "name": "John", "location": { "city": "New York", "zip": { "code": 12345, "plus4": 6789 } ...
[ { "docstring": "Flatten a nested json file\n\nArgs:\ny (dict): The json file as a dictionary\n\nReturns:\ndict: The flattened version of the json", "function_declaration": "def flatten_json(y):", "function_name": "flatten_json", "parameter_list": "(y)" }, { "docstring": null, "function_d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\nimport csv\nfrom collections.abc import MutableMapping\n\ndef flatten_json(y):\n \"\"\"\n Flatten a nested json file to a flat dictionary.\n \"\"\"\n out = {}\n\n d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053719", "row_id": 53719, "seed_ids": "['Qwen2.5-72B-Instruct_110300']" }
0.714737
Filter_53719
I
[ "flatten_json", "json_to_csv" ]
2
[ [ "json_to_csv", "flatten_json" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fc660404fe7e69dda7de0af54cf8db89c1829af
ac31f313a5ae5f549be16265a1140be27cb5900c
v1.0
instruct
Filter
Filter_53734_I
Write a Python function named `calculate_temperature_in_fahrenheit` that converts a given temperature from Celsius to Fahrenheit. The function should accept a single argument, which is the temperature in Celsius, and return the temperature converted to Fahrenheit. Use the formula \(F = C \times \frac{9}{5} + 32\) for t...
def calculate_temperature_in_fahrenheit(celsius): """ Converts a given temperature from Celsius to Fahrenheit. Parameters: celsius (float): Temperature in Celsius. Returns: float: Temperature in Fahrenheit. """ return celsius * 9 / 5 + 32 def check_conversion(): ""...
from solution import calculate_temperature_in_fahrenheit def test_calculate_temperature_in_fahrenheit_zero(): assert calculate_temperature_in_fahrenheit(0) == 32 def test_calculate_temperature_in_fahrenheit_boiling(): assert calculate_temperature_in_fahrenheit(100) == 212 def test_calculate_temperature_in_fa...
[ { "docstring": "Converts a given temperature from Celsius to Fahrenheit.\n\nParameters:\n celsius (float): Temperature in Celsius.\n\nReturns:\n float: Temperature in Fahrenheit.", "function_declaration": "def calculate_temperature_in_fahrenheit(celsius):", "function_name": "calculate_temperature_...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_temperature_in_fahrenheit(celsius):\n \"\"\"\n Converts temperature from Celsius to Fahrenheit.\n \n Args:\n celsius (float): Temperature in Celsius.\n \n Re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053734", "row_id": 53734, "seed_ids": "['Qwen2.5-72B-Instruct_110316']" }
0.46108
Filter_53734
I
[ "calculate_temperature_in_fahrenheit", "check_conversion" ]
2
[ [ "check_conversion", "calculate_temperature_in_fahrenheit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa0ef5e18c56a68b7b2bc463ded168275c589ff5
94c9dde11dc370d318205863f3ffc347171d2d4d
v1.0
instruct
Filter
Filter_53777_I
Design a Python function that accepts a list of integers and returns the product of the unique prime numbers found within the list. If the list contains no prime numbers, the function should return 1. Consider the input list to contain only positive integers.
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def product_of_...
from solution import product_of_unique_primes def test_no_primes(): assert product_of_unique_primes([1, 4, 6, 8, 10]) == 1 def test_single_prime(): assert product_of_unique_primes([2]) == 2 assert product_of_unique_primes([5]) == 5 def test_multiple_primes(): assert product_of_unique_primes([2, 3, 5,...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the product of the unique prime numbers found within the list.\nIf the list contains no prime numbers, return...
[ 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 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...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053777", "row_id": 53777, "seed_ids": "['Qwen2.5-72B-Instruct_110398']" }
0.665346
Filter_53777
I
[ "is_prime", "product_of_unique_primes" ]
2
[ [ "product_of_unique_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e16cbe0735af73ac6574713edd1c6ed721e3cc3d
893f46c82a6df1887edbd49a90e1a3e92c641131
v1.0
instruct
Filter
Filter_53787_I
Can you assist me in creating a simple chatbot using Python and Flask? I want the chatbot to answer basic questions about a fictional bakery. The chatbot should be able to greet users, provide information about the bakery's hours, menu, and special offers, and respond to a few frequently asked questions, like "What are...
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/chatbot', methods=['POST']) def chatbot(): user_message = request.json.get('message', '').lower() response = get_bot_response(user_message) return jsonify({"response": response}) def get_bot_response(message): if "hello" in ...
import pytest from solution import app, get_bot_response # Helper function to test response from the Flask app def post_message(client, message): return client.post('/chatbot', json={"message": message}) @pytest.fixture def client(): with app.test_client() as client: yield client def test_greeting(cl...
[ { "docstring": null, "function_declaration": "def chatbot():", "function_name": "chatbot", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_bot_response(message):", "function_name": "get_bot_response", "parameter_list": "(message)" } ]
[ 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, jsonify\n\napp = Flask(__name__)\n\n@app.route('/chatbot', methods=['POST'])\ndef chatbot():\n user_message = request.json.get('message', '').lower()\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053787", "row_id": 53787, "seed_ids": "['Qwen2.5-72B-Instruct_110411']" }
0.433843
Filter_53787
I
[ "chatbot", "get_bot_response" ]
2
[ [ "chatbot", "get_bot_response" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
612064ef4c0530b531181d8459937e867fc9c901
dadb2dca606e42d620dce6fde244aaea0b75940a
v1.0
instruct
Filter
Filter_53810_I
Create a Python function that returns the maximum number of consecutive 1's in a binary array, but only if the number of 1's is also a prime number. If there are no such instances, the function should return 0.
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 max_consecutive_ones_with_prime_count def test_no_consecutive_ones(): assert max_consecutive_ones_with_prime_count([0, 0, 0]) == 0 def test_no_ones(): assert max_consecutive_ones_with_prime_count([0, 0, 0, 0, 0]) == 0 def test_prime_consecutive_ones(): assert max_consecutive_ones_wit...
[ { "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 maximum number of consecutive 1's in a binary array,\nbut only if the number of 1's is also a prime number.\n...
[ 1, 0, 0 ]
1
medium
0.333
{ "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 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 % 3 == 0:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053810", "row_id": 53810, "seed_ids": "['Qwen2.5-72B-Instruct_110446']" }
0.626683
Filter_53810
I
[ "is_prime", "max_consecutive_ones_with_prime_count" ]
2
[ [ "max_consecutive_ones_with_prime_count", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07114450c007549791247a0513cbd91e24959872
14373c8aac4016f1673bcfa8316a8c940cfbf555
v1.0
instruct
Filter
Filter_53835_I
Write a Python function that determines the size of a directory in a human-readable format. The function should print the total size of all files within the directory, including subdirectories, and should format the output to be easily readable (e.g., 500K, 1.5M, 2G). The function should also handle any errors graceful...
import os def get_size(start_path='.', unit='B'): """ Determine the size of a directory in a human-readable format. :param start_path: Directory path to calculate size. :param unit: Unit for the size ('B', 'K', 'M', 'G'). :return: String representing the size in human-readable format. """ t...
import os import tempfile from solution import get_size, print_directory_size def test_get_size_bytes(): with tempfile.TemporaryDirectory() as tempdir: file_path = os.path.join(tempdir, 'test_file') with open(file_path, 'wb') as f: f.write(b'a' * 1024) # 1 KB file assert get_si...
[ { "docstring": "Determine the size of a directory in a human-readable format.\n:param start_path: Directory path to calculate size.\n:param unit: Unit for the size ('B', 'K', 'M', 'G').\n:return: String representing the size in human-readable format.", "function_declaration": "def get_size(start_path='.', u...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef get_size(start_path='.', unit='B'):\n \"\"\"\n Determine the size of a directory in a human-readable format.\n :param start_path: Directory path to calculate size.\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053835", "row_id": 53835, "seed_ids": "['Qwen2.5-72B-Instruct_110489']" }
0.648109
Filter_53835
I
[ "get_size", "print_directory_size" ]
2
[ [ "print_directory_size", "get_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2b422f8571270464ff5101b767056e16c7460dde
e2e24521f1098b5f81d9dffe98014b1bfccf21f0
v1.0
instruct
Filter
Filter_53867_I
Given a list of integers, write a Python function to filter out all the prime numbers and return them in a new list. Make sure your function is efficient and handles edge cases, such as when the input list is empty. Demonstrate your function with an example.
import math 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 ...
from solution import is_prime, filter_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(20) == False assert is_prime(-3) == False assert is_prime(0) == False assert is_prime(1) == Fal...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filters out all the prime numbers from a list and returns them in a new list.", "function_declaration": "def filter_p...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053867", "row_id": 53867, "seed_ids": "['Qwen2.5-72B-Instruct_110540']" }
0.640772
Filter_53867
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b695048a3dd96ea312d6db32c4a409de86072d35
0766e0df1c45a367fc7798f1f2bfced6a2b64bdf
v1.0
instruct
Filter
Filter_53868_I
Create a Python script that converts temperatures from Fahrenheit to Celsius and vice versa. The user should be able to specify the conversion direction and input the temperature. The script should also validate the input to ensure that it is a valid number. Provide error messages for invalid inputs and guide the user ...
def fahrenheit_to_celsius(fahrenheit): """ Converts Fahrenheit to Celsius. """ return (fahrenheit - 32) * 5.0/9.0 def celsius_to_fahrenheit(celsius): """ Converts Celsius to Fahrenheit. """ return (celsius * 9.0/5.0) + 32 def convert_temperature(value, direction): """ Converts ...
from solution import fahrenheit_to_celsius, celsius_to_fahrenheit, convert_temperature def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(98.6) == 37 def test_celsius_to_fahrenheit(): assert celsius_to_fahrenhei...
[ { "docstring": "Converts Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Converts Celsius to Fahrenheit.", "function_declaration": "def celsius_to_fahr...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts temperature from Fahrenheit to Celsius.\n \"\"\"\n return (fahrenheit - 32) * 5.0/9.0\n\ndef celsius_to_fahrenheit(celsiu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053868", "row_id": 53868, "seed_ids": "['Qwen2.5-72B-Instruct_110541']" }
0.431698
Filter_53868
I
[ "fahrenheit_to_celsius", "celsius_to_fahrenheit", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b9409344cb80b18eb5472b10185355c6142afe1d
cf1ad50606fabbcc4e9998997b2724c32001531d
v1.0
instruct
Filter
Filter_53870_I
I need to create a Python program that uses the PyTorch library to perform operations on a dataset. Can you provide a brief example on how to load a dataset, create a simple model, train it, and then save the model for later use?
import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader, TensorDataset # Define a simple dataset def load_data(): # Create some example data inputs = torch.tensor([[1.0], [2.0], [3.0], [4.0]], dtype=torch.float32) targets = torch.tensor([[2.0], [4.0], [6.0], [...
import os import torch from solution import train_model, save_model, load_model, SimpleModel def test_train_model(): model = train_model() assert isinstance(model, SimpleModel) for param in model.parameters(): assert param.requires_grad def test_save_model(): model = train_model() save_mod...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "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\nimport torch.utils.data as data\nimport torchvision\nimport torchvision.transforms as transforms\n\n# Define a simple model\nc...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053870", "row_id": 53870, "seed_ids": "['Qwen2.5-72B-Instruct_110544']" }
0.353375
Filter_53870
I
[ "load_data", "train_model", "save_model", "load_model" ]
4
[ [ "train_model", "load_data" ] ]
1
[]
false
[ "SimpleModel" ]
true
pytest
true
[ "torch" ]
false
bf2185cb3fc4dddb5102d5662ada2e233efcbe57
fb91a4d9ef90bd4483d2c8b89bd6d2c37a9d5e1d
v1.0
instruct
Filter
Filter_53875_I
Can you write a program that simulates a simple game of rock, paper, scissors in Python? The program should allow a user to play against the computer, which randomly selects its choice. The game should keep track of the score and allow the user to play multiple rounds until they choose to quit.
import random def get_computer_choice(): """ Randomly returns 'rock', 'paper', or 'scissors' for the computer's choice. """ choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def determine_winner(user_choice, computer_choice): """ Determines the winner between the user a...
from solution import get_computer_choice, determine_winner def test_get_computer_choice(): choices = ['rock', 'paper', 'scissors'] for _ in range(100): # Test 100 times to cover the randomness assert get_computer_choice() in choices def test_determine_winner(): assert determine_winner('rock', 'sc...
[ { "docstring": "Randomly returns 'rock', 'paper', or 'scissors' for the computer's choice.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner between the user and the computer.\nRetur...
[ 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 returns 'rock', 'paper', or 'scissors' for the computer's choice.\n \"\"\"\n choices = ['rock', 'paper', 'scissors']...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00053875", "row_id": 53875, "seed_ids": "['Qwen2.5-72B-Instruct_110550']" }
0.400181
Filter_53875
I
[ "get_computer_choice", "determine_winner", "game" ]
3
[ [ "game", "determine_winner" ], [ "game", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ee4cd30e571b80e885cd62177a8b0243455ff227
aa5bf476d3b2ee51bcfe3e64d5820c20fbc1c58a
v1.0
instruct
Filter
Filter_53885_I
Write a Python function that generates a random integer between 1 and 1000 and checks if the integer is a prime number. The function should return the integer and a boolean indicating whether it is prime. Use a simple primality test for this function.
import random def is_prime(num): """ Returns True if num is a prime number, otherwise False. """ 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) ...
from solution import is_prime, generate_random_prime_check def test_is_prime_with_primes(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(11) == True assert is_prime(97) == True def test_is_prime_with_non_primes(): assert is_prime(1) == False ...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a random integer between 1 and 1000, and checks if it is prime.\nReturns a tuple of the ...
[ 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 is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053885", "row_id": 53885, "seed_ids": "['Qwen2.5-72B-Instruct_110569']" }
0.707213
Filter_53885
I
[ "is_prime", "generate_random_prime_check" ]
2
[ [ "generate_random_prime_check", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e49adc9dbded69f82bbe2e5647c251b178610673
b421102ed7e6dedcc7c9835943c27100bb90cab7
v1.0
instruct
Filter
Filter_53896_I
Can you help me to understand how to use the `map` function in Python with a list of dictionaries? I have a list of dictionaries, and I want to apply a function to each dictionary to modify a specific value or add a new key-value pair. How can I achieve this using `map`?
def modify_dict(d): """ Modifies the input dictionary by adding a new key-value pair, where the key is 'new_key' and the value is the length of the original dictionary. """ d['new_key'] = len(d) return d def apply_map_to_list_of_dicts(lst): """ Applies the modify_dict function to each d...
from solution import modify_dict, apply_map_to_list_of_dicts def test_modify_dict_adds_new_key(): dict_input = {'a': 1, 'b': 2} modified_dict = modify_dict(dict_input.copy()) assert modified_dict['new_key'] == 2 assert modified_dict == {'a': 1, 'b': 2, 'new_key': 2} def test_apply_map_to_list_of_dicts...
[ { "docstring": "Modifies the input dictionary by adding a new key-value pair,\nwhere the key is 'new_key' and the value is the length of the original dictionary.", "function_declaration": "def modify_dict(d):", "function_name": "modify_dict", "parameter_list": "(d)" }, { "docstring": "Applie...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add_is_adult(person):\n \"\"\"\n Adds an 'is_adult' key to the dictionary based on the 'age' value.\n \"\"\"\n person['is_adult'] = person['age'] >= 18\n return person\n\nda...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053896", "row_id": 53896, "seed_ids": "['Qwen2.5-72B-Instruct_110591']" }
0.551317
Filter_53896
I
[ "modify_dict", "apply_map_to_list_of_dicts" ]
2
[ [ "apply_map_to_list_of_dicts", "modify_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
58706280ef13b7e98ac95909f163c99bed9ac268
60bd3f51fedb76dea7899b79e33d4a4e40abeb47
v1.0
instruct
Filter
Filter_53926_I
Design a Python program that can monitor a list of websites for availability and response time, and alert if any of them are down or exceed a specified response time. The program should be able to run continuously and should log all its activities. Additionally, provide a way to specify the websites and the response ti...
import requests import time import logging import json # Setup logging logging.basicConfig(filename='website_monitor.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') def load_config(config_file): """ Loads the configuration from a JSON file. """ with open(config_file, 'r')...
import pytest from unittest import mock from solution import load_config, check_website def test_load_config(): mock_config_data = { "websites": ["https://example.com"], "response_time_threshold": 2.0, "check_interval": 60 } with mock.patch('builtins.open', mock.mock_open(read_data=...
[ { "docstring": "Loads the configuration from a JSON file.", "function_declaration": "def load_config(config_file):", "function_name": "load_config", "parameter_list": "(config_file)" }, { "docstring": "Checks the availability and response time of a website.", "function_declaration": "def...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nimport time\nimport logging\nimport json\n\ndef check_website(url, threshold):\n \"\"\"\n Checks website availability and response time.\n Returns True if the website...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053926", "row_id": 53926, "seed_ids": "['Qwen2.5-72B-Instruct_110640']" }
0.621041
Filter_53926
I
[ "load_config", "check_website", "monitor_websites" ]
3
[ [ "monitor_websites", "check_website" ], [ "monitor_websites", "load_config" ] ]
2
[]
false
[]
false
pytest
true
[ "requests" ]
false
4063c0728eec2495e8266b565cb346dbadd64368
c3453a25f30ce1ef2b108bd8caeb8fdd2527ce75
v1.0
instruct
Filter
Filter_53934_I
I need help with a programming challenge. I'm trying to find the fastest route for a delivery truck to visit a series of locations and return to the starting point. The locations are given as a list of (x, y) coordinates. I want to use an algorithm that can handle a moderate number of locations and provide a reasonably...
from itertools import permutations def euclidean_distance(p1, p2): """ Returns the Euclidean distance between points p1 and p2. """ return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5 def nearest_neighbor_algorithm(locations): """ Implements the nearest neighbor algorithm for the TSP. ...
from solution import nearest_neighbor_algorithm, euclidean_distance def test_nearest_neighbor_algorithm_no_locations(): assert nearest_neighbor_algorithm([]) == ([], 0) def test_nearest_neighbor_algorithm_one_location(): assert nearest_neighbor_algorithm([(0, 0)]) == ([(0, 0), (0, 0)], 0) def test_nearest_ne...
[ { "docstring": "Returns the Euclidean distance between points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Implements the nearest neighbor algorithm for the TSP.\nReturns the pat...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef calculate_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return math.sqrt((point1[0] - point2[0])**2 + (poi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053934", "row_id": 53934, "seed_ids": "['Qwen2.5-72B-Instruct_110649']" }
0.597297
Filter_53934
I
[ "euclidean_distance", "nearest_neighbor_algorithm" ]
2
[ [ "nearest_neighbor_algorithm", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6b86438d61224ebc35485d930aa2734cd346e718
5bd72edb1985a40e4715a9f14f912a6173b8e1b1
v1.0
instruct
Filter
Filter_53950_I
How can I use Python to create a simple game of rock, paper, scissors? Could you provide a basic example?
import random def get_computer_choice(): """ Randomly returns 'rock', 'paper' or 'scissors'. """ return random.choice(['rock', 'paper', 'scissors']) def determine_winner(player_choice, computer_choice): """ Determines the winner between player and computer based on their choices. Parameter...
from solution import get_computer_choice, determine_winner, play_round def test_get_computer_choice(): choice = get_computer_choice() assert choice in ['rock', 'paper', 'scissors'] def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'win' assert determine_winner('rock', 'paper'...
[ { "docstring": "Randomly returns 'rock', 'paper' or 'scissors'.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner between player and computer based on their choices.\nParameters:\n- ...
[ 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 get_computer_choice():\n \"\"\"\n Randomly returns one of 'rock', 'paper' or 'scissors' as the computer's choice.\n \"\"\"\n return random.choice(['rock', 'pap...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053950", "row_id": 53950, "seed_ids": "['Qwen2.5-72B-Instruct_110674']" }
0.400834
Filter_53950
I
[ "get_computer_choice", "determine_winner", "play_round" ]
3
[ [ "play_round", "determine_winner" ], [ "play_round", "get_computer_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
34f00ce8a31b7621665887fb7640bb7a56df5eaa
1be5ae6016cce8bb07e3fbba26b4dbb6909dec1e
v1.0
instruct
Filter
Filter_53963_I
Write a Python function to simulate the rolling of a fair six-sided die. The function should return the number that comes up on the die. Additionally, modify the function to roll the die multiple times and return the results in a list.
import random def roll_die(): """ Simulates the rolling of a fair six-sided die. Returns the number that comes up on the die (1 to 6). """ return random.randint(1, 6) def roll_die_multiple(times): """ Rolls a six-sided die `times` times and returns the results in a list. Args: ...
from solution import roll_die, roll_die_multiple def test_roll_die(): # Ensure that roll_die returns a value between 1 and 6 inclusive. for _ in range(100): # Test multiple times to cover the range result = roll_die() assert 1 <= result <= 6, f"Die roll out of bounds: {result}" def test_roll_...
[ { "docstring": "Simulates the rolling of a fair six-sided die.\nReturns the number that comes up on the die (1 to 6).", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Rolls a six-sided die `times` times and returns the result...
[ 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 a roll of a fair six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef roll_die_multiple_times(n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053963", "row_id": 53963, "seed_ids": "['Qwen2.5-72B-Instruct_110692']" }
0.609478
Filter_53963
I
[ "roll_die", "roll_die_multiple" ]
2
[ [ "roll_die_multiple", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a35c0eabc7e386793b38dcf4d03bc9793c68f161
a7db071e408bbf197891e5f87dd2d5cd1cc63e70
v1.0
instruct
Filter
Filter_53973_I
Create a Python function that returns the day of the year for a given date, but only if the year is a leap year. If the year is not a leap year, the function should return an error message. The function should be named `leap_year_day` and the input should be a single string in the format `YYYY-MM-DD`.
import datetime def is_leap_year(year): """ Returns True if the given year is a leap year, False otherwise. """ return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) def leap_year_day(date_str): """ Returns the day of the year for a given date, but only if the year is a leap year. ...
from solution import leap_year_day def test_leap_year_day_valid_leap(): assert leap_year_day("2020-02-29") == 60 # February 29 is the 60th day in a leap year assert leap_year_day("2016-12-31") == 366 # December 31 is the 366th day in a leap year def test_leap_year_day_invalid_leap(): assert leap_year_da...
[ { "docstring": "Returns True if the given year is a leap year, False otherwise.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Returns the day of the year for a given date, but only if the year is a leap yea...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def leap_year_day(date_str):\n \"\"\"\n Returns the day of the year for a given date if the year is a leap year.\n If the year is not a leap year, returns an error message.\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00053973", "row_id": 53973, "seed_ids": "['Qwen2.5-72B-Instruct_110711']" }
0.621382
Filter_53973
I
[ "is_leap_year", "leap_year_day" ]
2
[ [ "leap_year_day", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0317b4962b48f72bdeac569c0876d68cbd8eb833
7712029ac21a315ba66675078f568c8f5e4b1798
v1.0
instruct
Filter
Filter_53988_I
Create a Python function named `calculate_area` that computes the area of a circle given its radius. The function should round the result to 2 decimal places. Additionally, write a `check_area` function that tests the `calculate_area` function with a radius of 5 (expected output: 78.54) and a radius of 7 (expected outp...
import math def calculate_area(radius): """ Returns the area of a circle given its radius. The result is rounded to 2 decimal places. """ area = math.pi * radius ** 2 return round(area, 2) def check_area(): """ Tests the calculate_area function with specific values. Returns a d...
from solution import calculate_area, check_area def test_calculate_area(): assert calculate_area(5) == 78.54 assert calculate_area(7) == 153.94 assert calculate_area(0) == 0.00 assert calculate_area(1) == 3.14 assert calculate_area(10) == 314.16 def test_check_area(): results = check_area() ...
[ { "docstring": "Returns the area of a circle given its radius.\nThe result is rounded to 2 decimal places.", "function_declaration": "def calculate_area(radius):", "function_name": "calculate_area", "parameter_list": "(radius)" }, { "docstring": "Tests the calculate_area function with specif...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef calculate_area(radius):\n \"\"\"\n Computes the area of a circle given its radius and rounds the result to 2 decimal places.\n \"\"\"\n area = math.pi * radius *...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00053988", "row_id": 53988, "seed_ids": "['Qwen2.5-72B-Instruct_110739']" }
0.529176
Filter_53988
I
[ "calculate_area", "check_area" ]
2
[ [ "check_area", "calculate_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
279ac2964abd0f61d54cd5fa0ff274c0d7de1476
56f060e1cfbf598af5b2eba46863c566a69c5593
v1.0
instruct
Filter
Filter_54036_I
Develop a Python function `find_next_prime` that takes an integer and returns the next prime number following the input value. Ensure your solution is efficient for larger inputs and doesn't just brute force the solution. The function should also include docstrings explaining the method used and any limitations. Additi...
import math def is_prime(n): """ Helper function to check if a number n 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: ...
from solution import find_next_prime, is_prime 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(19) == True def test_find_next_prime(): assert find_next_prime(2) =...
[ { "docstring": "Helper function to check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the next prime number following the input value n.\nUses efficient prime-checking methods, i...
[ 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 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 ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054036", "row_id": 54036, "seed_ids": "['Qwen2.5-72B-Instruct_110814']" }
0.63814
Filter_54036
I
[ "is_prime", "find_next_prime" ]
2
[ [ "find_next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b31f26b6d175ee355ce53601a78dd76ae8bb4bb
e69672584c53efa9993442d76a2110d936077fb9
v1.0
instruct
Filter
Filter_54056_I
Create a Python script to rename a user's file, ensuring that the script includes a function to check if the file exists and to handle basic errors. The script should also include a simple user interface for entering the current and new file names.
import os def file_exists(file_path): """ Checks if a file exists at the given file path. """ return os.path.isfile(file_path) def rename_file(current_name, new_name): """ Renames a file from current_name to new_name. """ if not file_exists(current_name): return "Current file d...
import os import pytest from solution import file_exists, rename_file def test_file_exists(tmp_path): test_file = tmp_path / "test.txt" test_file.write_text("Sample content") assert file_exists(test_file) == True assert file_exists("nonexistentfile.txt") == False def test_rename_file_success(tmp_...
[ { "docstring": "Checks if a file exists at the given file path.", "function_declaration": "def file_exists(file_path):", "function_name": "file_exists", "parameter_list": "(file_path)" }, { "docstring": "Renames a file from current_name to new_name.", "function_declaration": "def rename_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef file_exists(file_path):\n \"\"\"\n Checks if a file exists at the given file path.\n \"\"\"\n return os.path.isfile(file_path)\n\ndef rename_file(current_name, new...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00054056", "row_id": 54056, "seed_ids": "['Qwen2.5-72B-Instruct_110850']" }
0.551849
Filter_54056
I
[ "file_exists", "rename_file", "main" ]
3
[ [ "rename_file", "file_exists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f73c896641c47f3e0dc9c05930458224db71c31d
9cb81b2d1a3c3957f70c0cbe03c8d44b8c2ba92a
v1.0
instruct
Filter
Filter_54059_I
Create a Python script that will generate a list of prime numbers up to a given number, n, using the Sieve of Eratosthenes algorithm. The script should also include a function to check if the generated list is correct by verifying each number in the list is prime. Finally, include a way to run a test with a few sample ...
def sieve_of_eratosthenes(n): """ Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm. """ if n < 2: return [] sieve = [True] * (n + 1) sieve[0] = sieve[1] = False # 0 and 1 are not primes p = 2 while p * p <= n: if sieve[p]: ...
from solution import sieve_of_eratosthenes, is_prime, verify_prime_list def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(0) == [] assert sieve_of_eratosthenes(1) == [] assert sieve_of_eratosthenes(2) == [2] assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(...
[ { "docstring": "Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Checks if a number is prime.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n if n < 2:\n return []\n \n sie...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00054059", "row_id": 54059, "seed_ids": "['Qwen2.5-72B-Instruct_110853']" }
0.649459
Filter_54059
I
[ "sieve_of_eratosthenes", "is_prime", "verify_prime_list" ]
3
[ [ "verify_prime_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
53d5196c9310af4bdf66b97e2557f8cd5b67c5c7
66edb598b199ac8886445f7532fa8d3fd4f0077a
v1.0
instruct
Filter
Filter_54066_I
Write a Python program to solve the traveling salesman problem using the brute force approach. The program should take as input a list of cities represented as coordinates and return the shortest possible route that visits each city exactly once and returns to the origin city. Explain the time complexity of your soluti...
import itertools def calculate_distance(coord1, coord2): """ Helper function to calculate the Euclidean distance between two coordinates. """ return ((coord1[0] - coord2[0]) ** 2 + (coord1[1] - coord2[1]) ** 2) ** 0.5 def total_distance(route, cities): """ Helper function to calculate the tota...
from solution import tsp_brute_force def test_no_cities(): assert tsp_brute_force([]) == (0, []) def test_one_city(): assert tsp_brute_force([(0, 0)]) == (0, [0]) def test_two_cities(): assert tsp_brute_force([(0, 0), (1, 1)]) == (2 ** 0.5 * 2, (0, 1)) def test_three_cities(): cities = [(0, 0), (1, ...
[ { "docstring": "Helper function to calculate the Euclidean distance between two coordinates.", "function_declaration": "def calculate_distance(coord1, coord2):", "function_name": "calculate_distance", "parameter_list": "(coord1, coord2)" }, { "docstring": "Helper function to calculate the to...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\nimport math\n\ndef calculate_distance(point1, point2):\n \"\"\"Calculate the Euclidean distance between two points.\"\"\"\n return math.sqrt((point1[0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054066", "row_id": 54066, "seed_ids": "['Qwen2.5-72B-Instruct_110862']" }
0.594025
Filter_54066
I
[ "calculate_distance", "total_distance", "tsp_brute_force" ]
3
[ [ "total_distance", "calculate_distance" ], [ "tsp_brute_force", "total_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f2e3cc105df9599b3dfddc3473f19a62ff30e05c
8e6a261d7b65dc03f28ad1937eb7fabd94e34094
v1.0
instruct
Filter
Filter_54148_I
How can I create a simple chatbot using Python and Flask that can answer basic questions like "What's the weather like today?" or "Tell me a joke"?
from flask import Flask, request, jsonify import random app = Flask(__name__) def get_weather(): # This is just a placeholder. In a real application, you'd fetch actual weather data. weather = ["sunny", "cloudy", "rainy", "stormy"] return f"Today's weather is {random.choice(weather)}." def tell_joke(): ...
import pytest from flask import Flask from solution import app @pytest.fixture def client(): with app.test_client() as client: yield client def test_weather_response(client): response = client.post('/chat', json={'message': "What's the weather like today?"}) data = response.get_json() assert "...
[ { "docstring": null, "function_declaration": "def get_weather():", "function_name": "get_weather", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def tell_joke():", "function_name": "tell_joke", "parameter_list": "()" }, { "docstring": null, "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\ndef get_response(message):\n \"\"\"\n Returns a predefined response based on the message.\n \"\"\"\n if \"weat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054148", "row_id": 54148, "seed_ids": "['Qwen2.5-72B-Instruct_111004']" }
0.39944
Filter_54148
I
[ "get_weather", "tell_joke", "chat" ]
3
[ [ "chat", "get_weather" ], [ "chat", "tell_joke" ] ]
2
[]
false
[]
false
pytest
true
[ "flask" ]
false
cd40384c589f1e0727686eec812c86db601a1e93
8b92a422e09c044e53c2104445a74233860c185c
v1.0
instruct
Filter
Filter_54150_I
I'm working on a Python application and need to implement a caching mechanism to store and quickly retrieve results of certain function calls. I've heard that using an in-memory data structure could be efficient. What's a good approach to implement this, and can you provide a basic example using a common Python data st...
class SimpleCache: def __init__(self): self.cache = {} def get(self, key): """ Retrieve a value from the cache by key. """ return self.cache.get(key) def set(self, key, value): """ Store a key-value pair in the cache. """ self...
from solution import SimpleCache, expensive_function, cached_expensive_function def test_cache_set_and_get(): cache = SimpleCache() cache.set('a', 10) assert cache.get('a') == 10 def test_cache_get_nonexistent_key(): cache = SimpleCache() assert cache.get('nonexistent') is None def test_cache_cle...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Cache:\n def __init__(self):\n self.cache_dict = {}\n \n def get(self, key):\n if key in self.cache_dict:\n return self.cache_dict[key]\n return ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054150", "row_id": 54150, "seed_ids": "['Qwen2.5-72B-Instruct_111009']" }
0.354887
Filter_54150
I
[ "expensive_function", "cached_expensive_function" ]
2
[ [ "cached_expensive_function", "expensive_function" ] ]
1
[]
false
[ "SimpleCache" ]
true
pytest
true
[]
true
b76e84491d033364e225c4f29acb464d84e6509a
9ad5486a6cfc94003a9f55f6bce52eb5d07fadcc
v1.0
instruct
Filter
Filter_54195_I
Create a Python script that can check the availability of a list of URLs and indicate if the domain is online or offline. The script should be able to handle exceptions and print out a summary of the results at the end. Additionally, include a feature that allows for the results to be saved to a file.
import requests def check_url(url): """ Check the availability of a single URL. """ try: response = requests.get(url) if response.status_code == 200: return "online" else: return "offline" except requests.exceptions.RequestException: return "o...
from solution import check_url, check_urls, save_results_to_file import os def test_check_url_online(monkeypatch): class MockResponse: status_code = 200 def mock_get(*args, **kwargs): return MockResponse() monkeypatch.setattr(requests, "get", mock_get) assert check_url("http://example.c...
[ { "docstring": "Check the availability of a single URL.", "function_declaration": "def check_url(url):", "function_name": "check_url", "parameter_list": "(url)" }, { "docstring": "Check the availability of a list of URLs.", "function_declaration": "def check_urls(urls):", "function_n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\n\ndef check_url(url):\n \"\"\"\n Check the availability of a single URL.\n \"\"\"\n try:\n response = requests.get(url)\n if response.status_code == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00054195", "row_id": 54195, "seed_ids": "['Qwen2.5-72B-Instruct_111086']" }
0.626894
Filter_54195
I
[ "check_url", "check_urls", "save_results_to_file" ]
3
[ [ "check_urls", "check_url" ] ]
1
[]
false
[]
false
pytest
true
[ "requests" ]
false
59262d369ea52bde1185d596c7c0c12865b192e4
b6e484fce6d284996dc254767a2bd59b79e1078e
v1.0
instruct
Filter
Filter_54208_I
Please help me find a solution for the Travelling Salesman Problem (TSP) for a small set of cities, say 5 cities, using a brute force approach. I would appreciate if you can provide a Python code snippet for this.
import itertools def calculate_total_distance(route, distance_matrix): """ Calculates the total distance of the given route using the distance matrix. """ total_distance = 0 for i in range(len(route)): total_distance += distance_matrix[route[i-1]][route[i]] # distance from previous city to...
from solution import travelling_salesman_brute_force, calculate_total_distance def test_calculate_total_distance(): distance_matrix = [ [0, 10, 15, 20], [10, 0, 35, 25], [15, 35, 0, 30], [20, 25, 30, 0] ] route = (0, 1, 2, 3) assert calculate_total_distance(route, distan...
[ { "docstring": "Calculates the total distance of the given route using the distance matrix.", "function_declaration": "def calculate_total_distance(route, distance_matrix):", "function_name": "calculate_total_distance", "parameter_list": "(route, distance_matrix)" }, { "docstring": "Solves t...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef tsp_brute_force(distances):\n \"\"\"\n Solves the Travelling Salesman Problem using brute force approach.\n \n Parameters:\n distances ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054208", "row_id": 54208, "seed_ids": "['Qwen2.5-72B-Instruct_111113']" }
0.453919
Filter_54208
I
[ "calculate_total_distance", "travelling_salesman_brute_force" ]
2
[ [ "travelling_salesman_brute_force", "calculate_total_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e2c4c5092a71685178294a0348000d875b13aa4
fa26c8aeec0ddd0f61d3f7d26390b8c96ab612c2
v1.0
instruct
Filter
Filter_54212_I
Write a program in Python to find all prime numbers within a given range. The program should take two integers as input, representing the start and end of the range, and output all prime numbers within that range. Optimize the program for efficiency.
def is_prime(n): """ Helper function to check if a number is prime. :param n: integer, the number to be checked. :return: boolean, True if n is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False ...
from solution import find_primes_in_range def test_find_primes_in_range(): assert find_primes_in_range(10, 20) == [11, 13, 17, 19] assert find_primes_in_range(1, 10) == [2, 3, 5, 7] assert find_primes_in_range(15, 17) == [17] assert find_primes_in_range(20, 30) == [23, 29] assert find_primes_in_ran...
[ { "docstring": "Helper function to check if a number is prime.\n:param n: integer, the number to be checked.\n:return: boolean, True if n is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all ...
[ 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": "00054212", "row_id": 54212, "seed_ids": "['Qwen2.5-72B-Instruct_111119']" }
0.600366
Filter_54212
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ae32591a097fac4a8f79bc953658a4dcb5e6fcb
dd8734f0b04b7c35d0a092ab50b6580ddcc71d71
v1.0
instruct
Filter
Filter_54245_I
Design a Python program for a simple text-based rock-paper-scissors game where a human player can compete against the computer. The game should allow the player to input their choice (rock, paper, scissors), then generate a random selection for the computer, determine the winner based on the classic rules of the game, ...
import random def get_computer_choice(): """ Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice. """ return random.choice(['rock', 'paper', 'scissors']) def determine_winner(player_choice, computer_choice): """ Determines the winner between player and computer. Return...
from solution import get_computer_choice, determine_winner, display_result def test_get_computer_choice(): assert get_computer_choice() in ['rock', 'paper', 'scissors'] def test_determine_winner(): assert determine_winner('rock', 'scissors') == 'player' assert determine_winner('rock', 'paper') == 'compute...
[ { "docstring": "Randomly returns 'rock', 'paper', or 'scissors' as the computer's choice.", "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": "Determines the winner between player and computer.\nReturns 'pla...
[ 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 selects and returns one of 'rock', 'paper', or 'scissors' for the computer.\n \"\"\"\n return random.choice(['rock',...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054245", "row_id": 54245, "seed_ids": "['Qwen2.5-72B-Instruct_111181']" }
0.492851
Filter_54245
I
[ "get_computer_choice", "determine_winner", "display_result", "rock_paper_scissors_game" ]
4
[ [ "rock_paper_scissors_game", "determine_winner" ], [ "rock_paper_scissors_game", "display_result" ], [ "rock_paper_scissors_game", "get_computer_choice" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b85a9de3fcefcecd79bdf03f569ef9fc0c260cd1
9fe17a89b679eff9fe9ab6b322553d8ff24e4337
v1.0
instruct
Filter
Filter_54251_I
How can I use the `map` function in Python to apply a function to each element in a list? Can you give an example using a list of integers and a function that squares the number?
def square(x): """ Returns the square of x. """ return x * x def apply_square_using_map(nums): """ Applies the square function to each element in the list nums using the map function. Args: nums (list of int): A list of integers to be squared. Returns: list of int: A list...
from solution import square, apply_square_using_map def test_square(): assert square(2) == 4 assert square(-3) == 9 assert square(0) == 0 def test_apply_square_using_map(): assert apply_square_using_map([1, 2, 3, 4]) == [1, 4, 9, 16] assert apply_square_using_map([0, -1, -2, -3]) == [0, 1, 4, 9] ...
[ { "docstring": "Returns the square of x.", "function_declaration": "def square(x):", "function_name": "square", "parameter_list": "(x)" }, { "docstring": "Applies the square function to each element in the list nums \nusing the map function.\n\nArgs:\nnums (list of int): A list of integers t...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def square(x):\n \"\"\"\n Returns the square of x.\n \"\"\"\n return x * x\n\ndef apply_function_with_map(func, data):\n \"\"\"\n Applies the function 'func' to each element ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054251", "row_id": 54251, "seed_ids": "['Qwen2.5-72B-Instruct_111188']" }
0.551399
Filter_54251
I
[ "square", "apply_square_using_map" ]
2
[ [ "apply_square_using_map", "square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b32ca81bfd44601d91cf0320942288ed889d16aa
90fe1af5a93bcfa456168f62db27ad3cd9d33fdc
v1.0
instruct
Filter
Filter_54272_I
Create a Python function that takes a list of integers as input and returns a new list containing only the integers that are palindromes. An integer is considered a palindrome if it reads the same backward as forward. For example, 121 and 454 are palindromes, but 123 and 40 are not.
def is_palindrome(n): """ Determines if the given integer n is a palindrome. Args: n (int): The integer to check. Returns: bool: True if n is a palindrome, False otherwise. """ return str(n) == str(n)[::-1] def filter_palindromes(lst): """ Filters a list of int...
from solution import filter_palindromes def test_all_palindromes(): assert filter_palindromes([121, 454, 787]) == [121, 454, 787] def test_no_palindromes(): assert filter_palindromes([123, 456, 789]) == [] def test_mixed_palindromes(): assert filter_palindromes([121, 123, 454, 456]) == [121, 454] def te...
[ { "docstring": "Determines if the given integer n is a palindrome.\n\nArgs:\n n (int): The integer to check.\n\nReturns:\n bool: True if n is a palindrome, False otherwise.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Determines if the given integer n is a palindrome.\n \n Args:\n n (int): The integer to check.\n \n Returns:\n bool: True if n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00054272", "row_id": 54272, "seed_ids": "['Qwen2.5-72B-Instruct_111220']" }
0.726356
Filter_54272
I
[ "is_palindrome", "filter_palindromes" ]
2
[ [ "filter_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
12f296c845f84643a9228dc3c37b1a304d15f074
5d4be00d34c0a07c4a2d5cb64e8643c42c83228c
v1.0
instruct
Filter
Filter_54285_I
How can I modify a Python script to pause for 5 seconds before executing a particular function?
import time def example_function(): """ This function will be called after a 5 seconds delay. """ return "Function executed after 5 seconds delay." def delayed_execution(): """ Waits for 5 seconds and then executes the example_function. """ time.sleep(5) return example_function()
from solution import delayed_execution, example_function import time def test_delayed_execution(): start_time = time.time() result = delayed_execution() end_time = time.time() # Check that the delay was close to 5 seconds assert end_time - start_time >= 5 assert result == "Function execute...
[ { "docstring": "This function will be called after a 5 seconds delay.", "function_declaration": "def example_function():", "function_name": "example_function", "parameter_list": "()" }, { "docstring": "Waits for 5 seconds and then executes the example_function.", "function_declaration": ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\n\ndef delayed_execution(func, delay=5, *args, **kwargs):\n \"\"\"\n Delays the execution of the given function by a specified number of seconds.\n\n Parameters:\n fu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054285", "row_id": 54285, "seed_ids": "['Qwen2.5-72B-Instruct_111246']" }
0.578929
Filter_54285
I
[ "example_function", "delayed_execution" ]
2
[ [ "delayed_execution", "example_function" ] ]
1
[]
false
[]
false
pytest
true
[]
true
919ba93b8ccdefc7858bfe0d147a4108018c4b91
3535679d34607d94bc0a831b3cd88542671524ae
v1.0
instruct
Filter
Filter_54304_I
Develop a Python program that asks the user to input a number and then checks if the number is prime. If the number is prime, print "The number is prime." Otherwise, print "The number is not prime." Ensure that your program handles potential errors gracefully.
def is_prime(n): """ Check if n is a prime number. Returns True if n is prime, else False. """ 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 ret...
from solution import is_prime def test_is_prime(): assert is_prime(2) assert not is_prime(1) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(0) assert not is_prime(-5) assert not is_prime(9) assert is_prime(13) assert not is_prime(15) def test_i...
[ { "docstring": "Check if n is a prime number.\nReturns True if n is prime, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def check_prime():", "function_name": "check_prim...
[ 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 Returns True if n is prime, else False.\n \"\"\"\n if n <= 1:\n return False\n\n for i in range(2, int(n**...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054304", "row_id": 54304, "seed_ids": "['Qwen2.5-72B-Instruct_111281']" }
0.763734
Filter_54304
I
[ "is_prime", "check_prime" ]
2
[ [ "check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86a73bf8e7e4e6cdcf3e4869b61c6204eb0d9209
0c872e936222526a764dbea9552d9589a2f8f809
v1.0
instruct
Filter
Filter_54306_I
Create a Python script that reads a CSV file, where the first column contains dates in the format 'YYYY-MM-DD', and the second column contains corresponding values. The script should calculate the moving average of the values over a window of 5 days and output this to a new CSV file with the same dates and the calculat...
import csv from datetime import datetime from collections import deque def read_csv(file_name): """ Reads a CSV file and returns a list of tuples with dates and values """ data = [] try: with open(file_name, 'r') as file: reader = csv.reader(file) for row in reader: ...
import os import csv from solution import read_csv, calculate_moving_average, write_csv, process_csv def test_read_csv(): data = [('2023-01-01', 1.0), ('2023-01-02', 2.0), ('2023-01-03', 3.0), ('2023-01-04', 4.0), ('2023-01-05', 5.0)] with open('test_input.csv', 'w', newline='') as f: writer = csv.writ...
[ { "docstring": "Reads a CSV file and returns a list of tuples with dates and values", "function_declaration": "def read_csv(file_name):", "function_name": "read_csv", "parameter_list": "(file_name)" }, { "docstring": "Calculates the moving average of the values over the specified window size...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import pandas as pd\n\ndef calculate_moving_average(input_csv, output_csv, window_size=5):\n \"\"\"\n Calculate the moving average from an input CSV file and output to another CSV file.\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054306", "row_id": 54306, "seed_ids": "['Qwen2.5-72B-Instruct_111285']" }
0.524641
Filter_54306
I
[ "read_csv", "calculate_moving_average", "write_csv", "process_csv" ]
4
[ [ "process_csv", "calculate_moving_average" ], [ "process_csv", "read_csv" ], [ "process_csv", "write_csv" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4c5a0400d6d83615da7ba575ac0547ab38625a6b
a2a5936c8ad4eae6278aa830d194e2f94b8f408c
v1.0
instruct
Filter
Filter_54325_I
I need to create a Python program that simulates a simple generator for random number sequences. The program should allow the user to specify the length of the sequence, the range of the numbers (minimum and maximum), and the type of numbers (integers or floats). Can you help me write this program, including a user int...
import random def generate_random_sequence(length, min_value, max_value, num_type): """ Generates a random sequence of numbers. Parameters: - length (int): The length of the sequence. - min_value (int/float): Minimum value of the range. - max_value (int/float): Maximum value of the range. ...
from solution import generate_random_sequence def test_generate_random_sequence_ints(): seq = generate_random_sequence(5, 1, 10, 'int') assert len(seq) == 5 assert all(isinstance(num, int) for num in seq) assert all(1 <= num <= 10 for num in seq) def test_generate_random_sequence_floats(): seq = g...
[ { "docstring": "Generates a random sequence of numbers.\n\nParameters:\n- length (int): The length of the sequence.\n- min_value (int/float): Minimum value of the range.\n- max_value (int/float): Maximum value of the range.\n- num_type (str): The type of the numbers ('int' or 'float').\n\nReturns:\n- list: A li...
[ 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 generate_random_sequence(length, minimum, maximum, number_type='int'):\n \"\"\"\n Generates a sequence of random numbers.\n\n :param length: Length of the sequenc...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054325", "row_id": 54325, "seed_ids": "['Qwen2.5-72B-Instruct_111321']" }
0.619558
Filter_54325
I
[ "generate_random_sequence", "user_interface" ]
2
[ [ "user_interface", "generate_random_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a8fcc44e836ff6334667f681375ff66bab85b73e
0c9a72673bb68ec562a892c2b0de9dc951f60986
v1.0
instruct
Filter
Filter_54330_I
How can I efficiently convert a list of keys and a list of values into a dictionary in Python? Additionally, how would you handle an unequal number of keys and values, ensuring that all provided keys and values are used without raising an error? Please provide a code snippet that demonstrates this, along with an exampl...
def lists_to_dict(keys, values): """ Converts two lists (keys and values) into a dictionary. If keys and values are of unequal length, extra elements in the longer list are ignored. """ length = min(len(keys), len(values)) return {keys[i]: values[i] for i in range(length)} def check_dict_correc...
from solution import lists_to_dict, check_dict_correctness def test_equal_length_lists(): keys = ['a', 'b', 'c'] values = [1, 2, 3] expected = {'a': 1, 'b': 2, 'c': 3} assert lists_to_dict(keys, values) == expected def test_keys_longer_than_values(): keys = ['a', 'b', 'c'] values = [1, 2] ...
[ { "docstring": "Converts two lists (keys and values) into a dictionary.\nIf keys and values are of unequal length, extra elements in the longer list are ignored.", "function_declaration": "def lists_to_dict(keys, values):", "function_name": "lists_to_dict", "parameter_list": "(keys, values)" }, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def list_to_dict(keys, values):\n \"\"\"\n Converts two lists, one of keys and one of values, into a dictionary.\n If the lists are not of equal length, the longer list's extra elemen...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054330", "row_id": 54330, "seed_ids": "['Qwen2.5-72B-Instruct_111328']" }
0.642715
Filter_54330
I
[ "lists_to_dict", "check_dict_correctness" ]
2
[ [ "check_dict_correctness", "lists_to_dict" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46ef4da3b650dba38238451718f515586d494da6
5ed4d4ed7cb9b6fb4b37dccd948eca70c2086b7c
v1.0
instruct
Filter
Filter_54331_I
How can I create a Python function that checks if a given number is a prime number? I want to use this function to find all prime numbers up to a certain limit.
def is_prime(n): """ Returns True if n is a prime number, otherwise returns 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 Fa...
from solution import is_prime, find_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(13) == True assert is_prime(1) == False assert is_prime(-5) == False def test_find_primes_up_to(): assert find_primes_up_t...
[ { "docstring": "Returns True if n is a prime number, otherwise returns False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers up to the specified limit.", "function_declaration": "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 Check if a given number n is a prime number.\n \n Parameters:\n n (int): The number to check for primality.\n \n Returns:\n bool: True if n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054331", "row_id": 54331, "seed_ids": "['Qwen2.5-72B-Instruct_111331']" }
0.773397
Filter_54331
I
[ "is_prime", "find_primes_up_to" ]
2
[ [ "find_primes_up_to", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc5af2564a8de9859942a54015985bc22fc0cec8
49a944244dfcbb9da31216933065d505b361cb4a
v1.0
instruct
Filter
Filter_54342_I
Can you create a Python program that converts temperatures from Celsius to Fahrenheit and vice versa? The program should accept user input and validate that the input is a valid temperature and the correct scale (C for Celsius or F for Fahrenheit). It should then display the converted temperature. If the user enters in...
def celsius_to_fahrenheit(celsius): """ Converts celsius temperature to fahrenheit. """ return celsius * 9/5 + 32 def fahrenheit_to_celsius(fahrenheit): """ Converts fahrenheit temperature to celsius. """ return (fahrenheit - 32) * 5/9 def convert_temperature(temp_input): """ C...
from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature def test_celsius_to_fahrenheit(): assert celsius_to_fahrenheit(0) == 32 assert celsius_to_fahrenheit(100) == 212 assert celsius_to_fahrenheit(-40) == -40 def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsiu...
[ { "docstring": "Converts celsius temperature to fahrenheit.", "function_declaration": "def celsius_to_fahrenheit(celsius):", "function_name": "celsius_to_fahrenheit", "parameter_list": "(celsius)" }, { "docstring": "Converts fahrenheit temperature to celsius.", "function_declaration": "d...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Con...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054342", "row_id": 54342, "seed_ids": "['Qwen2.5-72B-Instruct_111349']" }
0.410375
Filter_54342
I
[ "celsius_to_fahrenheit", "fahrenheit_to_celsius", "convert_temperature" ]
3
[ [ "convert_temperature", "celsius_to_fahrenheit" ], [ "convert_temperature", "fahrenheit_to_celsius" ] ]
2
[]
false
[]
false
pytest
true
[]
true
69ce55ff08e0b2632ae7294e08b2c05fb9acaecf
dd2ab935abaf7fe45ee70987d611a6678c747840
v1.0
instruct
Filter
Filter_54345_I
I need to code a Python script to automate the creation of a simple REST API. The API should have endpoints for creating, reading, updating, and deleting user information. Can you guide me through the process? The user information should include at least the following fields: `id`, `name`, `email`, and `age`. Additiona...
from flask import Flask, request, jsonify, abort import re app = Flask(__name__) users = [] def is_valid_email(email): return re.match(r"[^@]+@[^@]+\.[^@]+", email) def is_valid_age(age): return age > 0 @app.route('/users', methods=['POST']) def create_user(): data = request.get_json() if not data ...
import pytest from flask import Flask from solution import app, users @pytest.fixture def client(): app.testing = True return app.test_client() def test_create_user(client): response = client.post('/users', json={ 'name': 'John Doe', 'email': 'john@example.com', 'age': 30 }) ...
[ { "docstring": null, "function_declaration": "def is_valid_email(email):", "function_name": "is_valid_email", "parameter_list": "(email)" }, { "docstring": null, "function_declaration": "def is_valid_age(age):", "function_name": "is_valid_age", "parameter_list": "(age)" }, { ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, jsonify\nfrom werkzeug.exceptions import BadRequest\n\napp = Flask(__name__)\n\nusers = {}\nnext_id = 1\n\n# Helper functions for validation\ndef is_valid_ema...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054345", "row_id": 54345, "seed_ids": "['Qwen2.5-72B-Instruct_111352']" }
0.538573
Filter_54345
I
[ "is_valid_email", "is_valid_age", "create_user", "get_users", "get_user", "update_user", "delete_user" ]
7
[ [ "create_user", "is_valid_age" ], [ "create_user", "is_valid_email" ], [ "update_user", "is_valid_age" ], [ "update_user", "is_valid_email" ] ]
4
[]
false
[]
false
pytest
true
[ "flask" ]
false
ee0f9517090e5a836e5293be98467f4d3c8c8c6d
e0acca6d3694627b4cc9c80a808cd528349996cd
v1.0
instruct
Filter
Filter_54359_I
Write a Python program that prints out the Fibonacci sequence up to the nth number, where n is an input from the user. However, make sure to validate the user input to ensure it is a positive integer greater than 0. If the input is not valid, the program should prompt the user to enter a valid positive integer until th...
def generate_fibonacci(n): """ Generate Fibonacci sequence up to the nth number. """ if n == 1: return [0] elif n == 2: return [0, 1] fib_sequence = [0, 1] for i in range(2, n): fib_sequence.append(fib_sequence[-1] + fib_sequence[-2]) return fib_sequence def is_v...
from solution import generate_fibonacci, is_valid_input def test_generate_fibonacci(): assert generate_fibonacci(1) == [0] assert generate_fibonacci(2) == [0, 1] assert generate_fibonacci(3) == [0, 1, 1] assert generate_fibonacci(5) == [0, 1, 1, 2, 3] assert generate_fibonacci(10) == [0, 1, 1, 2, 3...
[ { "docstring": "Generate Fibonacci sequence up to the nth number.", "function_declaration": "def generate_fibonacci(n):", "function_name": "generate_fibonacci", "parameter_list": "(n)" }, { "docstring": "Check if the user input is a positive integer greater than 0.", "function_declaratio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Returns the Fibonacci sequence up to the nth number.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer greater th...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054359", "row_id": 54359, "seed_ids": "['Qwen2.5-72B-Instruct_111368']" }
0.769641
Filter_54359
I
[ "generate_fibonacci", "is_valid_input", "get_fibonacci_sequence" ]
3
[ [ "get_fibonacci_sequence", "generate_fibonacci" ], [ "get_fibonacci_sequence", "is_valid_input" ] ]
2
[]
false
[]
false
pytest
true
[]
true
59df0ed4196bc1afb6b9d2131d2b6811239b2529
3051ed3bf21a25a95dd794567555964d67b49678
v1.0
instruct
Filter
Filter_54371_I
Design a simple Python script that monitors a specific directory for new files and automatically compresses any new file it finds using gzip. The script should run continuously, checking for new files every 5 minutes. Ensure to include error handling for common issues like file access problems.
import os import gzip import shutil import time from pathlib import Path def compress_file(file_path): """ Compresses the specified file using gzip. """ compressed_file_path = f"{file_path}.gz" try: with open(file_path, 'rb') as f_in: with gzip.open(compressed_file_path, 'w...
import os import gzip from solution import compress_file import pytest def setup_module(module): """ Setup a temporary directory and file for testing. """ os.mkdir('temp_test_dir') with open('temp_test_dir/test_file.txt', 'w') as f: f.write('This is a test file.') def teardown_module(module): ...
[ { "docstring": "Compresses the specified file using gzip.", "function_declaration": "def compress_file(file_path):", "function_name": "compress_file", "parameter_list": "(file_path)" }, { "docstring": "Monitors the specified directory for new files and compresses them.", "function_declar...
[ 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 gzip\nimport shutil\n\ndef monitor_directory(directory):\n \"\"\"\n Monitors the specified directory for new files and compresses them using gzip.\n \"\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00054371", "row_id": 54371, "seed_ids": "['Qwen2.5-72B-Instruct_111389']" }
0.609579
Filter_54371
I
[ "compress_file", "monitor_directory" ]
2
[ [ "monitor_directory", "compress_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e994f26ff670b5f14193a165621660bd57c9e692
18e168f0fe4fe90e7a9f50cdb3a4521bb2d2fdc4
v1.0
instruct
Filter
Filter_54384_I
I'm stuck on a problem where I need to generate a random number in Python between 1 and 100, and then check if it's a prime number. How can I do this?
import random def is_prime(num): """ Returns True if the given number is prime, else False. """ 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) == ...
from solution import is_prime, generate_random_and_check_prime 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(97) == True assert is_...
[ { "docstring": "Returns True if the given number is prime, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a random number between 1 and 100 and checks if it is prime.\nReturns the generated numbe...
[ 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 is_prime(n):\n \"\"\"\n Return True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054384", "row_id": 54384, "seed_ids": "['Qwen2.5-72B-Instruct_111410']" }
0.531227
Filter_54384
I
[ "is_prime", "generate_random_and_check_prime" ]
2
[ [ "generate_random_and_check_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
82a333eeb51cb05583a194795e33cba657ee18b0
81be3426598d57071fe9b82cedbe600175d531d3
v1.0
instruct
Filter
Filter_54391_I
Create a Python program that demonstrates the use of a while loop to print out a countdown from 10 to 1. The program should also include a function that checks if the number is even or odd and prints out a message accordingly. For example, "10 is even" or "9 is odd".
def is_even_or_odd(number): """ Checks if a number is even or odd and returns a string message. """ if number % 2 == 0: return f"{number} is even" else: return f"{number} is odd" def countdown(start): """ Starts a countdown from a given number, prints each number and whether...
from solution import is_even_or_odd, countdown import pytest def test_is_even_or_odd(): assert is_even_or_odd(10) == "10 is even" assert is_even_or_odd(9) == "9 is odd" assert is_even_or_odd(0) == "0 is even" assert is_even_or_odd(-1) == "-1 is odd" assert is_even_or_odd(-2) == "-2 is even" def te...
[ { "docstring": "Checks if a number is even or odd and returns a string message.", "function_declaration": "def is_even_or_odd(number):", "function_name": "is_even_or_odd", "parameter_list": "(number)" }, { "docstring": "Starts a countdown from a given number, prints each number and whether i...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_even_or_odd(number):\n \"\"\"\n Check if the number is even or odd and return the appropriate message.\n \"\"\"\n if number % 2 == 0:\n return f\"{number} is even\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054391", "row_id": 54391, "seed_ids": "['Qwen2.5-72B-Instruct_111427']" }
0.556534
Filter_54391
I
[ "is_even_or_odd", "countdown" ]
2
[ [ "countdown", "is_even_or_odd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f91f17830047b8fb82bff873224c5e9d3cc24c66
d5563f6191a27d9fa33a6cfd3146b4c358cb0ad6
v1.0
instruct
Filter
Filter_54400_I
Write a python script to check the disk usage of a directory and display the top 10 files/folders by size.
import os def get_size(path): """ Recursively get the size of the directory or file at the provided path. """ total_size = 0 if os.path.isfile(path): total_size = os.path.getsize(path) else: for dirpath, dirnames, filenames in os.walk(path): for filename in filenames...
import os import tempfile from solution import get_top_10_files_and_folders def test_get_size_for_file(): with tempfile.NamedTemporaryFile(delete=False) as temp_file: file_path = temp_file.name temp_file.write(b'0' * 100) # Write 100 bytes try: assert get_size(file_path) == 100 fin...
[ { "docstring": "Recursively get the size of the directory or file at the provided path.", "function_declaration": "def get_size(path):", "function_name": "get_size", "parameter_list": "(path)" }, { "docstring": "Returns a list of top 10 files/folders by size in given directory.", "functi...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef get_disk_usage(directory):\n \"\"\"\n Returns a list of tuples containing the file/folder name and its size in bytes, sorted by size in descending order.\n Only inclu...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054400", "row_id": 54400, "seed_ids": "['Qwen2.5-72B-Instruct_111448']" }
0.585062
Filter_54400
I
[ "get_size", "get_top_10_files_and_folders" ]
2
[ [ "get_top_10_files_and_folders", "get_size" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d4ed2b1666d8cf13902624634ed210266bdb1a7
71aa63fe5ce8c5bbf6fab568f6e85cfa8037a206
v1.0
instruct
Filter
Filter_54408_I
I need to create a simple web application that allows users to input a number and then displays the Fibonacci sequence up to that number. Can you guide me on how to set up this application using Python and Flask?
from flask import Flask, request, render_template_string app = Flask(__name__) def fibonacci(n): """ Generate Fibonacci sequence up to n. """ sequence = [] a, b = 0, 1 while a <= n: sequence.append(a) a, b = b, a + b return sequence @app.route('/', methods=['GET', 'POST'])...
from solution import fibonacci def test_fibonacci_zero(): assert fibonacci(0) == [0] def test_fibonacci_one(): assert fibonacci(1) == [0, 1, 1] def test_fibonacci_small_number(): assert fibonacci(5) == [0, 1, 1, 2, 3, 5] def test_fibonacci_larger_number(): assert fibonacci(21) == [0, 1, 1, 2, 3, 5, ...
[ { "docstring": "Generate Fibonacci sequence up to n.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def index():", "function_name": "index", "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, render_template_string\n\napp = Flask(__name__)\n\ndef generate_fibonacci_sequence(n):\n \"\"\"\n Generates a Fibonacci sequence up to the nth number.\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054408", "row_id": 54408, "seed_ids": "['Qwen2.5-72B-Instruct_111463']" }
0.566114
Filter_54408
I
[ "fibonacci", "index" ]
2
[ [ "index", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
2092e2eae68d7dab832e4e2b56a859b7a4807b11
3fb190281af2a87339e5804b9a31d7a02ce39c19
v1.0
instruct
Filter
Filter_54409_I
I'm teaching a beginner's class on coding and I want to introduce the concept of functions and loops in Python. Can you suggest a simple project that would allow students to practice these concepts while also being fun and engaging?
import random def generate_random_number(start, end): """ Generates a random number between start and end (inclusive). """ return random.randint(start, end) def get_user_guess(): """ Prompts the user to guess a number. """ return int(input('Guess the number: ')) def play_game(): "...
import random from solution import generate_random_number def test_generate_random_number(): for _ in range(100): num = generate_random_number(1, 100) assert 1 <= num <= 100 def test_generate_random_number_same_range(): num = generate_random_number(5, 5) assert num == 5 def test_generate_...
[ { "docstring": "Generates a random number between start and end (inclusive).", "function_declaration": "def generate_random_number(start, end):", "function_name": "generate_random_number", "parameter_list": "(start, end)" }, { "docstring": "Prompts the user to guess a number.", "function...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_random_number(start, end):\n \"\"\"\n Generates a random number between start and end (inclusive).\n \"\"\"\n return random.randint(start, end)\n\ndef...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00054409", "row_id": 54409, "seed_ids": "['Qwen2.5-72B-Instruct_111464']" }
0.434692
Filter_54409
I
[ "generate_random_number", "get_user_guess", "play_game" ]
3
[ [ "play_game", "generate_random_number" ], [ "play_game", "get_user_guess" ] ]
2
[]
false
[]
false
pytest
true
[]
true
188179b4f7d60edd49f92319a99a80db1ecded9c
be9b164fb2f8ecffce10a036f3cdb425e4ea7031
v1.0
instruct
Filter
Filter_54418_I
How can I create a Python script that reads a JSON file and prints out all the keys and values, and also writes them to a new file with a simple key-value format?
import json def read_and_print_json(file_path): with open(file_path, 'r') as file: data = json.load(file) result = [] for key, value in data.items(): print(f"{key}: {value}") result.append(f"{key}: {value}") return result def write_key_value_file(data, output_file...
import os import json import pytest from solution import read_and_print_json, write_key_value_file, process_json @pytest.fixture def sample_json_file(tmp_path): data = { "name": "John", "age": 30, "city": "New York" } file_path = tmp_path / "sample.json" with file_path.open("w")...
[ { "docstring": null, "function_declaration": "def read_and_print_json(file_path):", "function_name": "read_and_print_json", "parameter_list": "(file_path)" }, { "docstring": null, "function_declaration": "def write_key_value_file(data, output_file_path):", "function_name": "write_key...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import json\n\ndef read_and_process_json(input_file_path, output_file_path):\n \"\"\"\n Reads a JSON file and prints out all keys and values.\n Also writes the keys and values to a ne...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00054418", "row_id": 54418, "seed_ids": "['Qwen2.5-72B-Instruct_111475']" }
0.669663
Filter_54418
I
[ "read_and_print_json", "write_key_value_file", "process_json" ]
3
[ [ "process_json", "read_and_print_json" ], [ "process_json", "write_key_value_file" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c289f9fdc42105737821b7e1d4ccf2d76653186a
cc23db7c0374f719a5181ddcdd296db59ae64fa4