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_43241_I | How can I create a Python script that automatically sends emails to a list of recipients from a CSV file? The emails should be personalized with the recipient's name. Also, include a way to handle errors and confirm successful sends. | import smtplib
import csv
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(recipient_name, recipient_email, subject, body, smtp_server, smtp_port, login, password):
"""
Sends an email to the specified recipient.
Parameters:
- recipient_name: Name o... | from unittest.mock import patch, MagicMock
from solution import send_email, send_emails_from_csv
def test_send_email_success():
with patch('smtplib.SMTP') as mock_smtp:
instance = mock_smtp.return_value
instance.sendmail.return_value = {}
result = send_email("Test User", "test@example.com",... | [
{
"docstring": "Sends an email to the specified recipient.\n\nParameters:\n- recipient_name: Name of the recipient.\n- recipient_email: Email address of the recipient.\n- subject: Subject of the email.\n- body: Body text of the email.\n- smtp_server: SMTP server address.\n- smtp_port: SMTP server port.\n- login... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nimport smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ndef send_emails(csv_file, smtp_server, port, login, password):\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043241",
"row_id": 43241,
"seed_ids": "['Qwen2.5-72B-Instruct_93402']"
} | 0.525669 | Filter_43241 | I | [
"send_email",
"send_emails_from_csv"
] | 2 | [
[
"send_emails_from_csv",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba302fbfc1d4092860287ffe65d3013be2ac8e59 | b435e7f2ef4629468ad1faf1c30e928e6e2a004a | |||
v1.0 | instruct | Filter | Filter_43254_I | Write a Python program that implements a simple Caesar cipher. The program should take a string and a shift value as input and output the encrypted string. Additionally, implement a decryption function that can reverse the process. The program should handle both uppercase and lowercase letters, and non-alphabetic chara... | def caesar_cipher_encrypt(text, shift):
"""
Encrypts the input text using a Caesar cipher with the given shift.
Args:
text (str): The input string to be encrypted.
shift (int): The number of positions to shift each letter.
Returns:
str: The encrypted string.
"""
encrypted_t... | from solution import caesar_cipher_encrypt, caesar_cipher_decrypt
def test_caesar_cipher_encrypt_simple():
assert caesar_cipher_encrypt("abc", 1) == "bcd"
assert caesar_cipher_encrypt("ABC", 1) == "BCD"
def test_caesar_cipher_encrypt_with_wraparound():
assert caesar_cipher_encrypt("xyz", 3) == "abc"
a... | [
{
"docstring": "Encrypts the input text using a Caesar cipher with the given shift.\n\nArgs:\ntext (str): The input string to be encrypted.\nshift (int): The number of positions to shift each letter.\n\nReturns:\nstr: The encrypted string.",
"function_declaration": "def caesar_cipher_encrypt(text, shift):",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_cipher_encrypt(text, shift):\n \"\"\"\n Encrypts a given text using Caesar cipher with the given shift.\n \"\"\"\n encrypted_text = []\n for char in text:\n if... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043254",
"row_id": 43254,
"seed_ids": "['Qwen2.5-72B-Instruct_93424']"
} | 0.715511 | Filter_43254 | I | [
"caesar_cipher_encrypt",
"caesar_cipher_decrypt"
] | 2 | [
[
"caesar_cipher_decrypt",
"caesar_cipher_encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19b7a93fe03c633da888a4471a49f6186be12f26 | dce9b4728b5b1c0dede948f21f9abe9f9707c1ed | |||
v1.0 | instruct | Filter | Filter_43272_I | How can I implement a basic search engine for a small website using Python? | import re
from collections import defaultdict, Counter
from typing import List, Tuple
def clean_text(text: str) -> str:
"""
Cleans the input text by removing HTML tags, punctuation, and converting to lowercase.
"""
text = re.sub(r'<[^>]+>', '', text) # Remove HTML tags
text = re.sub(r'[^\w\s]', ''... | import pytest
from solution import clean_text, index_website, search
def test_clean_text():
assert clean_text('<p>Hello, World!</p>') == 'hello world'
assert clean_text('Clean: this text!') == 'clean this text'
assert clean_text('No Punctuation') == 'no punctuation'
def test_index_website():
pages = [... | [
{
"docstring": "Cleans the input text by removing HTML tags, punctuation, and converting to lowercase.",
"function_declaration": "def clean_text(text):",
"function_name": "clean_text",
"parameter_list": "(text)"
},
{
"docstring": "Indexes the content of the website pages.\nThis function take... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class SearchEngine:\n \"\"\"\n A basic search engine for a small website.\n Stores documents and provides search functionality.\n \"\"\"\n def __init__(self):\n self.docu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043272",
"row_id": 43272,
"seed_ids": "['Qwen2.5-72B-Instruct_93458']"
} | 0.501552 | Filter_43272 | I | [
"clean_text",
"index_website",
"search"
] | 3 | [
[
"index_website",
"clean_text"
],
[
"search",
"clean_text"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 449f165b6633e895cc517e9b111893960585a83b | dc3fc084b6977517e744c49c25db3bf8d40d7e91 | |||
v1.0 | instruct | Filter | Filter_43299_I | How can I create a Python function that generates a random number between 1 and 100, and then checks if the number is prime? The function should return the number and a boolean indicating whether it is prime or not. | import random
def is_prime(n):
"""
Determines if the given number n is a prime number.
Returns True if n is prime, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
... | from solution import is_prime, generate_random_prime_status
def test_is_prime_with_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
def test_is_prime_with_non_prime_numbers():
assert is_prim... | [
{
"docstring": "Determines if the given number n is a prime number.\nReturns True if n is prime, otherwise False.",
"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... | [
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 Determines if the given number n is a prime number.\n Returns True if n is prime, otherwise False.\n \"\"\"\n if n <= 1:\n re... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043299",
"row_id": 43299,
"seed_ids": "['Qwen2.5-72B-Instruct_93509']"
} | 0.66287 | Filter_43299 | I | [
"is_prime",
"generate_random_prime_status"
] | 2 | [
[
"generate_random_prime_status",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e177d9956c396e71f0751beaf33043bbc2524559 | af203e2057ac5ac3d51faa5a78b2ec25466350fb | |||
v1.0 | instruct | Filter | Filter_43300_I | Write a Python program that simulates a simple game of rock-paper-scissors. The program should allow a user to play against the computer. The computer's choice should be randomly generated. The program should keep track of the score and allow the user to play multiple rounds until they choose to quit. The rules of the ... | import random
def get_computer_choice():
choices = ['rock', 'paper', 'scissors']
return random.choice(choices)
def get_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return 'tie'
elif (user_choice == 'rock' and computer_choice == 'scissors') or \
(user_choice... | from solution import get_winner, play_round
def test_get_winner_tie():
assert get_winner('rock', 'rock') == 'tie'
assert get_winner('paper', 'paper') == 'tie'
assert get_winner('scissors', 'scissors') == 'tie'
def test_get_winner_user_wins():
assert get_winner('rock', 'scissors') == 'user'
assert ... | [
{
"docstring": null,
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def get_winner(user_choice, computer_choice):",
"function_name": "get_winner",
"parameter_lis... | [
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 get_computer_choice():\n choices = ['rock', 'paper', 'scissors']\n return random.choice(choices)\n\ndef get_winner(user_choice, computer_choice):\n if user_choice... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043300",
"row_id": 43300,
"seed_ids": "['Qwen2.5-72B-Instruct_93510']"
} | 0.533958 | Filter_43300 | I | [
"get_computer_choice",
"get_winner",
"play_round",
"rock_paper_scissors_game"
] | 4 | [
[
"play_round",
"get_computer_choice"
],
[
"play_round",
"get_winner"
],
[
"rock_paper_scissors_game",
"play_round"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 0832838cd4b01135e18d6855e16368854c23b76c | ce279902494b6647589c41ea7918ebcba2d5c4d5 | |||
v1.0 | instruct | Filter | Filter_43304_I | I need to create a function that will take a list of integers and return a new list containing only the integers that are palindromes. How can I do this in Python? | def is_palindrome(number):
"""
Returns True if the number is a palindrome.
"""
original = str(number)
reversed_num = original[::-1]
return original == reversed_num
def filter_palindromes(numbers):
"""
Returns a list containing only the integers that are palindromes from the input list.
... | from solution import is_palindrome, filter_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(-121) == False # Negative numbers are not considered palindromes
assert is_palindrome(0) == ... | [
{
"docstring": "Returns True if the number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list containing only the integers that are palindromes from the input list.",
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(number):\n \"\"\"\n Returns True if the number is a palindrome, False otherwise.\n \"\"\"\n str_num = str(number)\n return str_num == str_num[::-1]\n\ndef filt... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043304",
"row_id": 43304,
"seed_ids": "['Qwen2.5-72B-Instruct_93514']"
} | 0.660306 | Filter_43304 | I | [
"is_palindrome",
"filter_palindromes"
] | 2 | [
[
"filter_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 52c4429230247283d0ee23b173df03b84c286167 | 93a29c882f179810476a4cf01d1cda1839740903 | |||
v1.0 | instruct | Filter | Filter_43305_I | How can I create a Python function that filters a list of numbers to only include those that are prime numbers? | def is_prime(n):
"""
Checks if a number is a prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return... | from solution import filter_primes
def test_filter_primes_with_mixed_numbers():
assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23]) == [2, 3, 5, 7, 11, 13, 17, 19, 23]
def test_filter_primes_wit... | [
{
"docstring": "Checks if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters a list of numbers to only include prime numbers.",
"function_declaration": "def filter_primes(numbers):",
"func... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043305",
"row_id": 43305,
"seed_ids": "['Qwen2.5-72B-Instruct_93515']"
} | 0.654599 | Filter_43305 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0ecb5f2b094e233c3eaa67f5666ea0c48cc4d4ce | a145516f680d7c510572dce2802ed92e37dbf606 | |||
v1.0 | instruct | Filter | Filter_43380_I | Write a program to implement a simple text-based calculator in Python that can perform addition, subtraction, multiplication, and division. The user should be able to input two numbers and select an operation. The program should then display the result. Ensure the program can handle invalid inputs gracefully and provid... | def add(a, b):
"""Returns the sum of a and b."""
return a + b
def subtract(a, b):
"""Returns the difference of a and b."""
return a - b
def multiply(a, b):
"""Returns the product of a and b."""
return a * b
def divide(a, b):
"""Returns the division of a by b. Raises ZeroDivisionError if b... | import pytest
from solution import add, subtract, multiply, divide, calculator
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(0, 5) == -5
assert subtract(-5, -5) == 0
def test_multiply():
a... | [
{
"docstring": "Returns the sum of a and b.",
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the difference of a and b.",
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"paramete... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n return \"Error: Division by zer... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043380",
"row_id": 43380,
"seed_ids": "['Qwen2.5-72B-Instruct_93629']"
} | 0.598537 | Filter_43380 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | d623101b1fd62a280e8284ab151edac6e1f62807 | f451d49cb6d6313a7f91b066ee8cfc7b42379d4e | |||
v1.0 | instruct | Filter | Filter_43397_I | Is there a way to make a text-based game in Python that is both engaging and interactive for beginners to learn programming? | import random
def welcome_message():
print("Welcome to the 'Guess the Number' game!")
print("I have selected a number between 1 and 100.")
print("You have to guess the number. Let's begin!\n")
def get_random_number():
return random.randint(1, 100)
def get_user_guess():
try:
return int(inp... | import random
import builtins
from unittest.mock import patch
def test_welcome_message(capsys):
welcome_message()
captured = capsys.readouterr()
assert "Welcome to the 'Guess the Number' game!" in captured.out
assert "I have selected a number between 1 and 100." in captured.out
def test_get_random_num... | [
{
"docstring": null,
"function_declaration": "def welcome_message():",
"function_name": "welcome_message",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def get_random_number():",
"function_name": "get_random_number",
"parameter_list": "()"
},
{
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def start_game():\n print(\"Welcome to the Adventure Game!\")\n print(\"You find yourself in a dark forest. There are paths to the north, south, and east.\")\n choice = input(\"Which ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043397",
"row_id": 43397,
"seed_ids": "['Qwen2.5-72B-Instruct_93658']"
} | 0.439148 | Filter_43397 | I | [
"welcome_message",
"get_random_number",
"get_user_guess",
"check_guess",
"play_game"
] | 5 | [
[
"play_game",
"check_guess"
],
[
"play_game",
"get_random_number"
],
[
"play_game",
"get_user_guess"
],
[
"play_game",
"welcome_message"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 2938e8f9b2d6d77c017378a8adf15c60c4b20369 | 202e18ef04e8bd6d2d7d8b525157394edfdef577 | |||
v1.0 | instruct | Filter | Filter_43418_I | How can I create a Python function that checks if a given year is a leap year and returns a boolean value? Additionally, how can I use this function to determine the number of leap years between two given years (inclusive)? | def is_leap_year(year):
"""
Returns True if the given year is a leap year, otherwise False.
"""
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return True
return False
def count_leap_years(start_year, end_year):
"""
Returns the count of leap years between start_year an... | from solution import is_leap_year, count_leap_years
def test_is_leap_year():
assert is_leap_year(2000) == True
assert is_leap_year(1900) == False
assert is_leap_year(2004) == True
assert is_leap_year(2001) == False
def test_count_leap_years():
assert count_leap_years(2000, 2004) == 2
assert co... | [
{
"docstring": "Returns True if the given year is a leap year, otherwise False.",
"function_declaration": "def is_leap_year(year):",
"function_name": "is_leap_year",
"parameter_list": "(year)"
},
{
"docstring": "Returns the count of leap years between start_year and end_year (inclusive).",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_leap_year(year):\n \"\"\"\n Checks if a given year is a leap year.\n \n Args:\n year (int): Year to check.\n \n Returns:\n bool: True if the year is a leap year,... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043418",
"row_id": 43418,
"seed_ids": "['Qwen2.5-72B-Instruct_93696']"
} | 0.635669 | Filter_43418 | I | [
"is_leap_year",
"count_leap_years"
] | 2 | [
[
"count_leap_years",
"is_leap_year"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 47dac694654dd2247b1e84bd841920e0f089db60 | 1434861286038603e6bb05b3f9adf360e8fabfbc | |||
v1.0 | instruct | Filter | Filter_43437_I | Write a Python program to simulate a simple dice roll game. The game should roll two six-sided dice and print the sum of the two dice. If the sum is 7 or 11, the player wins; otherwise, the player loses. The program should ask the user if they want to play again after each game. Use functions to organize your code. | import random
def roll_dice():
"""
Simulates rolling two six-sided dice and returns their sum.
"""
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
return die1 + die2
def game_result(dice_sum):
"""
Determines the result of the game. Returns 'win' if the dice sum is 7 or 11,
... | from solution import roll_dice, game_result, play_game
def test_roll_dice():
dice_sum = roll_dice()
assert dice_sum >= 2 and dice_sum <= 12 # Validating possible sums of two dice
def test_game_result():
assert game_result(7) == 'win'
assert game_result(11) == 'win'
assert game_result(2) == 'lose'... | [
{
"docstring": "Simulates rolling two six-sided dice and returns their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Determines the result of the game. Returns 'win' if the dice sum is 7 or 11,\notherwise returns 'l... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"Simulates rolling two six-sided dice and returns their sum.\"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n return die... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043437",
"row_id": 43437,
"seed_ids": "['Qwen2.5-72B-Instruct_93719']"
} | 0.560907 | Filter_43437 | I | [
"roll_dice",
"game_result",
"play_game"
] | 3 | [
[
"play_game",
"game_result"
],
[
"play_game",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 710b9d3e67425b060cf16657d4b3863f94c213ba | f1e50ea5888ef9e5dc81b6c28639398618552541 | |||
v1.0 | instruct | Filter | Filter_43482_I | Write a function in Python that takes a list of integers and returns the largest prime number in the list. If there are no prime numbers, the function should return None. Optimize the function for performance considering large lists. | def is_prime(n):
"""
Helper function to 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 largest_prime
def test_largest_prime_with_primes():
assert largest_prime([2, 3, 5, 7, 11]) == 11
assert largest_prime([13, 17, 19, 23, 29]) == 29
assert largest_prime([31, 37, 41, 43, 47]) == 47
assert largest_prime([101, 103, 107, 109]) == 109
def test_largest_prime_with_no_prime... | [
{
"docstring": "Helper function to check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number in the list. If no prime number is found, returns None.",
"functi... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043482",
"row_id": 43482,
"seed_ids": "['Qwen2.5-72B-Instruct_93795']"
} | 0.721091 | Filter_43482 | I | [
"is_prime",
"largest_prime"
] | 2 | [
[
"largest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c7cf4fa49b296bbcf52aa2da982f2ee7fdc65d0b | fc66a87d0b7c89d9fc58a0c2d87d9211bcb930b9 | |||
v1.0 | instruct | Filter | Filter_43491_I | I have a text file containing a list of email addresses. How can I use Python to filter out invalid email addresses and save the valid ones to a new file? I want to ensure that the email addresses follow the standard email format. | import re
def is_valid_email(email):
"""
Returns True if the provided email address is valid, otherwise returns False.
"""
email_regex = re.compile(
r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
return re.match(email_regex, email) is not None
def filter_valid_emails(input_file_pat... | import os
from solution import is_valid_email, filter_valid_emails
def test_is_valid_email():
assert is_valid_email("test@example.com") == True
assert is_valid_email("invalid-email") == False
assert is_valid_email("another.test@domain.co") == True
assert is_valid_email("bad@domain@domain.com") == False... | [
{
"docstring": "Returns True if the provided email address is valid, otherwise returns False.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Reads email addresses from the input file, filters out inval... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_email(email):\n \"\"\"\n Returns True if the provided email address is valid, otherwise returns False.\n \"\"\"\n email_regex = re.compile(\n r\"(^... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043491",
"row_id": 43491,
"seed_ids": "['Qwen2.5-72B-Instruct_93812']"
} | 0.449979 | Filter_43491 | I | [
"is_valid_email",
"filter_valid_emails"
] | 2 | [
[
"filter_valid_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bf378f47a6081d8a1a55ee2c4f3e828f8a983eb9 | 34c841c12bf3c22255a85b99cf2da3c0c264e1dd | |||
v1.0 | instruct | Filter | Filter_43497_I | Write a Python program that simulates a simple game of rock-paper-scissors. The program should allow a user to play against the computer. The computer's choice should be randomly generated. The program should display the user's choice, the computer's choice, and announce the winner. The game should be played in a loop ... | import random
def get_computer_choice():
"""
Randomly selects and returns the computer's choice.
"""
choices = ['rock', 'paper', 'scissors']
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
"""
Determines the winner of the rock-paper-scissors game.
"""
... | from solution import get_computer_choice, determine_winner, play_round
def test_get_computer_choice():
choices = ['rock', 'paper', 'scissors']
for _ in range(100):
assert get_computer_choice() in choices
def test_determine_winner():
assert determine_winner('rock', 'scissors') == 'user'
assert ... | [
{
"docstring": "Randomly selects and returns the computer's choice.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner of the rock-paper-scissors game.",
"function_declaration": "... | [
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 \"\"\"Randomly returns 'rock', 'paper', or 'scissors'.\"\"\"\n choices = ['rock', 'paper', 'scissors']\n return random.choice(choices)\n\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043497",
"row_id": 43497,
"seed_ids": "['Qwen2.5-72B-Instruct_93819']"
} | 0.476193 | Filter_43497 | I | [
"get_computer_choice",
"determine_winner",
"play_round"
] | 3 | [
[
"play_round",
"determine_winner"
],
[
"play_round",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b6fe88f73eee73d22cc0a2d63f12c12cb5da613d | bd116436d5e0d7f67386dc23ac28befd60d22acb | |||
v1.0 | instruct | Filter | Filter_43532_I | Write a Python program that can calculate the sum of the first 100 prime numbers and print the result. Ensure the program is efficient and includes comments for clarity. | def is_prime(n):
"""
Helper function to check if a number is prime.
A number is prime if it is greater than 1 and has no divisors other than 1 and itself.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False... | from solution import is_prime, sum_of_first_100_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(29) == True
assert is_prime(30) == False
def test_sum_of_first_100_primes():
assert sum_o... | [
{
"docstring": "Helper function to check if a number is prime.\nA number is prime if it is greater than 1 and has no divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Calculate and return th... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if number <= 1:\n return False\n if number <= 3:\n return True\n if number % 2 == 0 or ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043532",
"row_id": 43532,
"seed_ids": "['Qwen2.5-72B-Instruct_93874']"
} | 0.583409 | Filter_43532 | I | [
"is_prime",
"sum_of_first_100_primes"
] | 2 | [
[
"sum_of_first_100_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b59cd340bf25099c77b84a57b949063f502e35d5 | 46b4fd08eb3edd579c8834fda597f55249e7c4df | |||
v1.0 | instruct | Filter | Filter_43555_I | Write a Python program that simulates a simple text-based rock-paper-scissors game. The game should allow a user to play against the computer. The program should keep track of the score and allow the user to play multiple rounds until they decide to quit. Make sure to include error handling for invalid inputs. | import random
def get_computer_choice():
"""
Randomly selects 'rock', 'paper', or 'scissors' for the computer.
"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(user_choice, computer_choice):
"""
Determines the winner of the rock-paper-scissors game.
Returns 'use... | from solution import get_computer_choice, determine_winner, play_round
def test_get_computer_choice():
for _ in range(100):
choice = get_computer_choice()
assert choice in ['rock', 'paper', 'scissors']
def test_determine_winner():
assert determine_winner('rock', 'scissors') == 'user'
asser... | [
{
"docstring": "Randomly selects 'rock', 'paper', or 'scissors' for the computer.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner of the rock-paper-scissors game.\nReturns 'user', ... | [
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 choose between 'rock', 'paper', and 'scissors' for the computer.\n Returns:\n str: The computer's choice.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043555",
"row_id": 43555,
"seed_ids": "['Qwen2.5-72B-Instruct_93911']"
} | 0.492946 | Filter_43555 | I | [
"get_computer_choice",
"determine_winner",
"play_round",
"play_rock_paper_scissors"
] | 4 | [
[
"play_rock_paper_scissors",
"play_round"
],
[
"play_round",
"determine_winner"
],
[
"play_round",
"get_computer_choice"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5c4a036b24f0534dbd5bb22008150400771a66b7 | fda92705668fddd7cbb1a16be63203713b27b437 | |||
v1.0 | instruct | Filter | Filter_43584_I | I am working on a project where I need to classify images into different categories using a deep learning model. I have a dataset of images and I want to use a pre-trained model to improve the accuracy and speed of my project. Can you guide me on how to fine-tune a pre-trained model in PyTorch for my specific dataset? ... | import torch
import torch.nn as nn
import torch.optim as optim
from torchvision import models, datasets, transforms
def get_transforms():
"""
Returns image transformations for data augmentation and normalization.
"""
return {
'train': transforms.Compose([
transforms.RandomResizedCro... | import torch
from torchvision import models
from solution import fine_tune_resnet
def test_fine_tune_resnet_structure():
num_classes = 10
model_ft = fine_tune_resnet(num_classes)
# Verify that the model is a ResNet18
assert isinstance(model_ft, models.ResNet)
assert model_ft._modules['layer4']... | [
{
"docstring": "Returns image transformations for data augmentation and normalization.",
"function_declaration": "def get_transforms():",
"function_name": "get_transforms",
"parameter_list": "()"
},
{
"docstring": "Creates train and validation dataloaders.\n\nArgs:\n- data_dir (str): Path to... | [
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, models, transforms\n\ndef fine_tune_resnet(num_classes, train_data_dir, val_data_dir, batch_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043584",
"row_id": 43584,
"seed_ids": "['Qwen2.5-72B-Instruct_93956']"
} | 0.229037 | Filter_43584 | I | [
"get_transforms",
"create_dataloaders",
"fine_tune_resnet",
"train_model",
"main"
] | 5 | [
[
"create_dataloaders",
"get_transforms"
]
] | 1 | [] | false | [] | false | pytest | true | [
"torch",
"torchvision"
] | false | 7018aa368ced65e39ee1bc784ed27b26790ecdbd | 80a0c98a435d97c25e57a8e21b1f339c770a80ef | |||
v1.0 | instruct | Filter | Filter_43589_I | Write a Python program that checks if a given number is a prime number. The program should take an integer as input and output a message indicating whether the number is prime or not. Make sure to handle edge cases, such as when the input is less than 2. | def is_prime(n):
"""
Check if the given number n is a prime number.
Parameters:
n (int): The number to check.
Returns:
bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
... | from solution import is_prime, prime_check_message
def test_is_prime_with_primes():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(29) == True
def test_is_prime_with_non_primes():
assert is_prime(-1) == False
asse... | [
{
"docstring": "Check if the given number n is a prime number.\n\nParameters:\nn (int): The number to check.\n\nReturns:\nbool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(number):\n \"\"\"\n Checks if the given number is a prime number.\n \n Parameters:\n number (int): The number to check.\n\n Returns:\n bool: True if the numbe... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043589",
"row_id": 43589,
"seed_ids": "['Qwen2.5-72B-Instruct_93962']"
} | 0.767635 | Filter_43589 | I | [
"is_prime",
"prime_check_message"
] | 2 | [
[
"prime_check_message",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45ba49287e66788df0a42e595ada54ca075df348 | ca1872ec216e69c7769137b8d34f8b0d3e649ad8 | |||
v1.0 | instruct | Filter | Filter_43599_I | Write a program in Python that can simulate a simple game of rock, paper, scissors against the computer. The program should allow the user to input their choice (rock, paper, or scissors), randomly generate a choice for the computer, and then determine the winner based on the classic rules of the game. The program shou... | import random
def get_computer_choice():
"""
Randomly generates the computer's choice among 'rock', 'paper', and 'scissors'.
"""
choices = ["rock", "paper", "scissors"]
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
"""
Determines the winner based on the ... | from solution import get_computer_choice, determine_winner, play_game
def test_get_computer_choice():
choices = ["rock", "paper", "scissors"]
for _ in range(100):
assert get_computer_choice() in choices
def test_determine_winner():
assert determine_winner("rock", "scissors") == "user"
assert d... | [
{
"docstring": "Randomly generates the computer's choice among 'rock', 'paper', and 'scissors'.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner based on the choices.\nReturns 'user... | [
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 get_computer_choice():\n \"\"\"\n Randomly generates the computer's choice among 'rock', 'paper', and 'scissors'.\n \"\"\"\n choices = [\"rock\", \"paper\", \"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043599",
"row_id": 43599,
"seed_ids": "['Qwen2.5-72B-Instruct_93975']"
} | 0.5156 | Filter_43599 | I | [
"get_computer_choice",
"determine_winner",
"play_game"
] | 3 | [
[
"play_game",
"determine_winner"
],
[
"play_game",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7bee0af8d0bad3e6ec4feb65870a30498af9155e | 2291b1b1029e3b61f5a57dd2ebe727dabeb631e7 | |||
v1.0 | instruct | Filter | Filter_43626_I | How can I implement a basic version of the K-Nearest Neighbors (KNN) algorithm in Python for a classification task? | import numpy as np
from collections import Counter
def euclidean_distance(point1, point2):
return np.sqrt(np.sum((point1 - point2) ** 2))
def knn_classify(X_train, y_train, X_test, k):
"""
Classifies each sample in X_test based on the k-nearest neighbors.
Parameters:
X_train (array-like): Feature... | from solution import knn_classify
import numpy as np
def test_knn_classify_simple():
X_train = np.array([[1, 2], [2, 3], [3, 4], [6, 7], [7, 8]])
y_train = np.array([0, 0, 0, 1, 1])
X_test = np.array([[1, 2], [3, 4], [6, 7]])
k = 3
expected = [0, 0, 1]
assert knn_classify(X_train, y_train, X_te... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Classifies each sample in X_test based on the k-nearest neighbors.\n\nParameters:\nX_train (array-like): Feat... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom collections import Counter\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate the Euclidean distance between two points.\n \"\"\"\n return np.... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043626",
"row_id": 43626,
"seed_ids": "['Qwen2.5-72B-Instruct_94022']"
} | 0.583035 | Filter_43626 | I | [
"euclidean_distance",
"knn_classify"
] | 2 | [
[
"knn_classify",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 396f7965275a6f9c1bd4bc8a66c1bcbce514aa02 | a1d71d3e05a30052d0eb6140c0d7774da425dfeb | |||
v1.0 | instruct | Filter | Filter_43627_I | Is it possible to generate a random number between 1 and 100 in Python and then check if it's a prime number? Could you show me how to do this? | import random
def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def generate... | from solution import is_prime, generate_random_number_and_check_prime
# Testing is_prime function
def test_is_prime_with_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(97) =... | [
{
"docstring": "Check 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's a prime number.\nReturns a tuple with the number and a boo... | [
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_number():\n \"\"\"\n Generates a random number between 1 and 100.\n \"\"\"\n return random.randint(1, 100)\n\ndef is_prime(n):\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043627",
"row_id": 43627,
"seed_ids": "['Qwen2.5-72B-Instruct_94023']"
} | 0.582313 | Filter_43627 | I | [
"is_prime",
"generate_random_number_and_check_prime"
] | 2 | [
[
"generate_random_number_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45d2709f1c63993a2101d9bc0a6069947f0bc5ff | 4dc288ce5f7ca5e0a1a0452456995e0c9c3cf1c6 | |||
v1.0 | instruct | Filter | Filter_43654_I | How can I design a simple game using Python that involves basic math operations for kids to practice their arithmetic skills? | import random
def generate_math_question():
"""
Generates a simple math question (addition, subtraction, multiplication, or division) with two random integers.
Returns the question string and the correct answer.
"""
operators = ['+', '-', '*', '/']
operator = random.choice(operators)
a... | from solution import generate_math_question, check_answer
import re
def test_generate_math_question_addition():
for _ in range(100):
question, answer = generate_math_question()
if '+' in question:
numbers = list(map(int, re.findall(r'\d+', question)))
assert answer == sum(nu... | [
{
"docstring": "Generates a simple math question (addition, subtraction, multiplication, or division) with two random integers.\nReturns the question string and the correct answer.",
"function_declaration": "def generate_math_question():",
"function_name": "generate_math_question",
"parameter_list":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_math_question():\n \"\"\"\n Generates a simple math question (addition, subtraction, multiplication, or division) with two random integers.\n Returns the... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043654",
"row_id": 43654,
"seed_ids": "['Qwen2.5-72B-Instruct_94063']"
} | 0.505474 | Filter_43654 | I | [
"generate_math_question",
"check_answer",
"math_game"
] | 3 | [
[
"math_game",
"check_answer"
],
[
"math_game",
"generate_math_question"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cbacdf0fc1cd9a89436151c90fb025009e1ce77d | cf6fef7d4b2f239bc2d467b830b4744acc255ed2 | |||
v1.0 | instruct | Filter | Filter_43693_I | Can you help me understand how to use the `map` function in Python, and provide an example of using it to convert a list of temperatures from Celsius to Fahrenheit? | def celsius_to_fahrenheit(celsius_temp):
"""
Converts a temperature from Celsius to Fahrenheit.
"""
return celsius_temp * 9/5 + 32
def convert_list_celsius_to_fahrenheit(celsius_temps):
"""
Converts a list of temperatures from Celsius to Fahrenheit using the map function.
"""
return lis... | from solution import celsius_to_fahrenheit, convert_list_celsius_to_fahrenheit
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(-40) == -40
assert celsius_to_fahrenheit(37) == 98.6
def test_convert_list_celsiu... | [
{
"docstring": "Converts a temperature from Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(celsius_temp):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius_temp)"
},
{
"docstring": "Converts a list of temperatures from Celsius to Fahrenheit ... | [
1,
1,
0
] | 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 a temperature in Celsius to Fahrenheit.\n Formula: (Celsius * 9/5) + 32\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef con... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043693",
"row_id": 43693,
"seed_ids": "['Qwen2.5-72B-Instruct_94126']"
} | 0.439966 | Filter_43693 | I | [
"celsius_to_fahrenheit",
"convert_list_celsius_to_fahrenheit"
] | 2 | [
[
"convert_list_celsius_to_fahrenheit",
"celsius_to_fahrenheit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f2399f5fcc57c634806694115ddcfef0d1876f3e | da2d46613cab9666df6be70e42bf6484aaa61346 | |||
v1.0 | instruct | Filter | Filter_43694_I | I am a beginner in Python programming and I want to create a simple program that can read a text file, count the number of words, and display the most common word along with its frequency. Can you guide me through the process? | from collections import Counter
import re
def read_file(filepath):
"""
Reads content of a file specified by filepath.
"""
with open(filepath, 'r') as file:
return file.read()
def count_words(text):
"""
Counts the number of words in a given text and returns them as a list of words.
... | import pytest
from solution import read_file, count_words, most_common_word, analyze_file
def test_read_file(tmp_path):
file_content = "Hello world. Hello Python."
file_path = tmp_path / "testfile.txt"
file_path.write_text(file_content)
assert read_file(file_path) == file_content
def test_count_w... | [
{
"docstring": "Reads content of a file specified by filepath.",
"function_declaration": "def read_file(filepath):",
"function_name": "read_file",
"parameter_list": "(filepath)"
},
{
"docstring": "Counts the number of words in a given text and returns them as a list of words.",
"function... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nimport re\n\ndef read_file(file_path):\n \"\"\"\n Reads the content of the file at the given file path.\n \n Args:\n file_path (str): Path t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043694",
"row_id": 43694,
"seed_ids": "['Qwen2.5-72B-Instruct_94127']"
} | 0.742018 | Filter_43694 | I | [
"read_file",
"count_words",
"most_common_word",
"analyze_file"
] | 4 | [
[
"analyze_file",
"count_words"
],
[
"analyze_file",
"most_common_word"
],
[
"analyze_file",
"read_file"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 98815f20449aeb1edf5972ca2b9a6cd6b1d5526d | 94fb39ad22e8da28f29fd806829d8d32f2bd0858 | |||
v1.0 | instruct | Filter | Filter_43733_I | Write a Python function that takes a list of numbers and returns a new list containing only the numbers that are prime. The function should also be able to handle an additional argument that, when set to True, returns the prime numbers in descending order. By default, this argument should be False, meaning the primes a... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def get_prime_numbers(numbers, descending=False):
"""
Returns a list of prim... | from solution import is_prime, get_prime_numbers
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_get_prime_number... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from the given list of numbers.\n\n:param numbers: List of integers to check for prime numbers\n:param descending: If True,... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043733",
"row_id": 43733,
"seed_ids": "['Qwen2.5-72B-Instruct_94202']"
} | 0.710898 | Filter_43733 | I | [
"is_prime",
"get_prime_numbers"
] | 2 | [
[
"get_prime_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 236aaef566b84f5c8e7332c136ea700f3cccc0cf | 32ef0dace661aca5e0f0d7ee2cc7a3fa97d483d3 | |||
v1.0 | instruct | Filter | Filter_43794_I | How can I create a Python script to automate the process of checking if a website is up and running? I want the script to send an email alert if the website is down. Can you provide a basic example? | import requests
import smtplib
from email.message import EmailMessage
def check_website(url):
"""
Check if the website is up by making a GET request.
"""
try:
response = requests.get(url)
return response.status_code == 200
except requests.RequestException:
return False
def ... | from solution import check_website, send_email_alert, monitor_website
import requests
from unittest.mock import patch, MagicMock
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')
def test_chec... | [
{
"docstring": "Check if the website is up by making a GET request.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
},
{
"docstring": "Send an email alert.",
"function_declaration": "def send_email_alert(to_email, subject, ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.message import EmailMessage\n\ndef check_website(url):\n \"\"\"\n Check if the website is up by making a GET request.\n \"\"\"\n try:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043794",
"row_id": 43794,
"seed_ids": "['Qwen2.5-72B-Instruct_94300']"
} | 0.537107 | Filter_43794 | I | [
"check_website",
"send_email_alert",
"monitor_website"
] | 3 | [
[
"monitor_website",
"check_website"
],
[
"monitor_website",
"send_email_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 10e57517bc4094a491e2648f8466430010d187f6 | 75054101205947f2c7ca77f75ebc13f1d0ca1902 | |||
v1.0 | instruct | Filter | Filter_43798_I | I'm trying to create a simple Python script to monitor a website for changes. I want it to check the website every hour and notify me via email if there are any changes. Can you guide me through the process? | import requests
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def fetch_website_content(url):
response = requests.get(url)
response.raise_for_status() # Raise an error for bad status codes
return response.text
def send_email_notification(su... | import pytest
from unittest.mock import patch, Mock
from solution import fetch_website_content, send_email_notification
def test_fetch_website_content():
with patch('requests.get') as mock_get:
mock_response = Mock()
mock_response.text = 'mocked content'
mock_response.raise_for_status = Moc... | [
{
"docstring": null,
"function_declaration": "def fetch_website_content(url):",
"function_name": "fetch_website_content",
"parameter_list": "(url)"
},
{
"docstring": null,
"function_declaration": "def send_email_notification(subject, body, from_email, to_email, smtp_server, smtp_port, sm... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport hashlib\nimport time\nimport requests\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\n# Function to get the current content of t... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043798",
"row_id": 43798,
"seed_ids": "['Qwen2.5-72B-Instruct_94304']"
} | 0.421814 | Filter_43798 | I | [
"fetch_website_content",
"send_email_notification",
"monitor_website"
] | 3 | [
[
"monitor_website",
"fetch_website_content"
],
[
"monitor_website",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 8b1e174a3285430493f0bbab08641c8446d6a63a | b4c909af30f7a6e244fbfb6e4d50d532713f9795 | |||
v1.0 | instruct | Filter | Filter_43804_I | Write a Python program to simulate a simple dice game. The game involves two players, each rolling a six-sided die. The player with the higher roll wins the round. If both players roll the same number, the round is a tie. The game continues for a specified number of rounds, and the player with the most wins at the end ... | import random
def roll_dice():
"""
Simulates rolling a six-sided die.
"""
return random.randint(1, 6)
def play_round():
"""
Simulates a round of the dice game where two players roll a die.
Returns:
result (str): 'Player 1 wins', 'Player 2 wins', or 'Tie' based on the outcome o... | import pytest
from unittest.mock import patch
from solution import roll_dice, play_round, play_game
def test_roll_dice():
with patch('random.randint', return_value=3):
assert roll_dice() == 3
def test_play_round_player1_wins():
with patch('solution.roll_dice', side_effect=[6, 3]):
assert play_... | [
{
"docstring": "Simulates rolling a six-sided die.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates a round of the dice game where two players roll a die.\n\nReturns:\n result (str): 'Player 1 wins', 'Player 2 ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n return random.randint(1, 6)\n\ndef play_rounds(rounds):\n player1_wins = 0\n player2_wins = 0\n \n for _ in range(rounds):\n player1_r... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043804",
"row_id": 43804,
"seed_ids": "['Qwen2.5-72B-Instruct_94319']"
} | 0.553322 | Filter_43804 | I | [
"roll_dice",
"play_round",
"play_game"
] | 3 | [
[
"play_game",
"play_round"
],
[
"play_round",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 09326eed935e3dbd0e50a8b0f2c7ac1d5308de58 | 97773de63933a784cdefe26ffb35a2c6d961ba50 | |||
v1.0 | instruct | Filter | Filter_43817_I | How can I implement a basic neural network using PyTorch for a binary classification task? Could you provide a simple example? | import torch
import torch.nn as nn
import torch.optim as optim
# Define a basic neural network
class SimpleNN(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
super(SimpleNN, self).__init__()
self.layer1 = nn.Linear(input_dim, hidden_dim)
self.relu = nn.ReLU()
self... | import torch
from solution import SimpleNN, train, create_data_loader
def test_simple_nn_initialization():
input_dim = 10
hidden_dim = 5
output_dim = 1
model = SimpleNN(input_dim, hidden_dim, output_dim)
assert isinstance(model, nn.Module)
assert len(list(model.parameters())) == 4 # Two l... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import torch\nimport torch.nn as nn\nimport torch.optim as optim\n\n# Define a basic neural network\nclass SimpleNN(nn.Module):\n def __init__(self, input_dim, hidden_dim, output_dim):\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043817",
"row_id": 43817,
"seed_ids": "['Qwen2.5-72B-Instruct_94335']"
} | 0.361111 | Filter_43817 | I | [
"train",
"create_data_loader",
"example_usage"
] | 3 | [
[
"example_usage",
"create_data_loader"
],
[
"example_usage",
"train"
]
] | 2 | [] | false | [
"SimpleNN"
] | true | pytest | true | [
"torch"
] | false | 04051c0bd8595004b794dc58e417bcb3b943b1e0 | 94b6ffb22aba2d4056464bde6b2022e9fe1c068b | |||
v1.0 | instruct | Filter | Filter_43831_I | I have a Python function that currently accepts a single string as input and returns a modified version of that string. I want to modify this function so that it can accept a list of strings and return a list of modified strings, applying the same modification to each string in the list. How should I go about changing ... | def modify_string(s):
"""
Returns the modified version of the input string.
"""
# Example modification: converting the string to uppercase
return s.upper()
def modify_strings(strings):
"""
Takes a list of strings and returns a list of modified strings.
Applies the same modification as ... | from solution import modify_string, modify_strings
def test_modify_string():
assert modify_string("hello") == "HELLO"
assert modify_string("world") == "WORLD"
assert modify_string("Python") == "PYTHON"
def test_modify_strings_single_string():
assert modify_strings(["hello"]) == ["HELLO"]
def test_mod... | [
{
"docstring": "Returns the modified version of the input string.",
"function_declaration": "def modify_string(s):",
"function_name": "modify_string",
"parameter_list": "(s)"
},
{
"docstring": "Takes a list of strings and returns a list of modified strings. \nApplies the same modification as... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def modify_string(s):\n \"\"\"\n Original string modification logic. \n For example, let's assume that the modification is converting the string to uppercase and adding \"MODIFIED\" t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043831",
"row_id": 43831,
"seed_ids": "['Qwen2.5-72B-Instruct_94356']"
} | 0.537917 | Filter_43831 | I | [
"modify_string",
"modify_strings"
] | 2 | [
[
"modify_strings",
"modify_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2143d3d0d54801e03a373afd7181d6a316a59d14 | c6b2aae8f7f3a7d24118b1c36210444593863d54 | |||
v1.0 | instruct | Filter | Filter_43832_I | Write a program in Python that prints out all the prime numbers between 1 and 100. Make sure to use comments to explain your code. | def is_prime(n):
"""
Determines if a given number n is prime.
A number is prime if it is greater than 1 and has no divisors other than 1 and itself.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def p... | from solution import is_prime, primes_between_1_and_100
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(15) == False
assert is_prime(97) == True
assert is_prime(1) == False # by definition, 1... | [
{
"docstring": "Determines if a given number n is prime.\n\nA number is prime if it is greater than 1 and has no divisors other than 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime... | [
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 Determine if a given number is a prime number.\n Args:\n num (int): The number to check.\n\n Returns:\n bool: True if the number is prime, False... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043832",
"row_id": 43832,
"seed_ids": "['Qwen2.5-72B-Instruct_94357']"
} | 0.568835 | Filter_43832 | I | [
"is_prime",
"primes_between_1_and_100"
] | 2 | [
[
"primes_between_1_and_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 74236fd6c71ad4f8c51121cf1912f823621cb82b | e99f4a02dc488d4e491772ec592c2d660761e8d9 | |||
v1.0 | instruct | Filter | Filter_43834_I | I am trying to implement a simple neural network using PyTorch to predict house prices based on a few features like the number of bedrooms, bathrooms, and square footage. I have my dataset ready but I'm not sure how to start with the model. Can you guide me through the basic steps to create and train this neural networ... | import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, TensorDataset
# Define the neural network model
class HousePricePredictor(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(HousePricePredictor, self).__init__()
self.hi... | from solution import create_model, train_model, run_training
import numpy as np
def test_create_model():
model = create_model(input_size=3, hidden_size=5, output_size=1)
assert isinstance(model, HousePricePredictor)
assert hasattr(model, 'hidden')
assert hasattr(model, 'relu')
assert hasattr(model,... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"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 sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\n\nclass HousePricePred... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043834",
"row_id": 43834,
"seed_ids": "['Qwen2.5-72B-Instruct_94360']"
} | 0.308819 | Filter_43834 | I | [
"create_model",
"train_model",
"run_training"
] | 3 | [
[
"run_training",
"create_model"
],
[
"run_training",
"train_model"
]
] | 2 | [] | false | [
"HousePricePredictor"
] | true | pytest | true | [
"numpy",
"torch"
] | false | 9fb9157168a246377c3b52ba12aa3f2a90e33e20 | 332d43e5c0210a6a221377d35cd5fdf9c281218f | |||
v1.0 | instruct | Filter | Filter_43850_I | Write a Python program that simulates a simple text-based blackjack game. The game should allow a single player to play against a dealer. The player can choose to 'hit' (take another card) or 'stand' (stop taking cards). The game should display the player's and dealer's hands and determine the winner based on the stand... | import random
def create_deck():
"""Creates a standard 52 card deck"""
suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']
deck = [{'rank': rank, 'suit': suit} for rank in ranks for suit in suits]
random.shuffle(de... | import pytest
from solution import create_deck, calculate_hand_value
def test_create_deck():
deck = create_deck()
assert len(deck) == 52
def test_create_deck_card_uniqueness():
deck = create_deck()
cards = set()
for card in deck:
card_tuple = (card['rank'], card['suit'])
assert car... | [
{
"docstring": "Creates a standard 52 card deck",
"function_declaration": "def create_deck():",
"function_name": "create_deck",
"parameter_list": "()"
},
{
"docstring": "Calculate the total value of a hand",
"function_declaration": "def calculate_hand_value(hand):",
"function_name": ... | [
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 create_deck():\n \"\"\"Creates a standard 52 card deck\"\"\"\n suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']\n ranks = ['2', '3', '4', '5', '6', '7', '8', '9'... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043850",
"row_id": 43850,
"seed_ids": "['Qwen2.5-72B-Instruct_94391']"
} | 0.426994 | Filter_43850 | I | [
"create_deck",
"calculate_hand_value",
"play_blackjack"
] | 3 | [
[
"play_blackjack",
"calculate_hand_value"
],
[
"play_blackjack",
"create_deck"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 40e6675cf37ea946fcd765ab608c747444102a59 | 768c4526f27dbf5a082f460bd608ee756c821f53 | |||
v1.0 | instruct | Filter | Filter_43910_I | How can I implement a basic recommendation system using Python and machine learning? | import numpy as np
from sklearn.decomposition import TruncatedSVD
def create_user_item_matrix(data, n_users, n_items):
"""
Create a user-item matrix based on the provided data.
Parameters:
- data: List of tuples (user_id, item_id, rating)
- n_users: Total number of users
- n_items: Total n... | import pytest
import numpy as np
from solution import create_user_item_matrix, train_recommendation_system, predict_rating
def test_create_user_item_matrix():
data = [
(0, 0, 5),
(0, 1, 3),
(1, 0, 4),
(1, 1, 2)
]
n_users = 2
n_items = 3
expected_matrix = np.array([
... | [
{
"docstring": "Create a user-item matrix based on the provided data.\n\nParameters:\n- data: List of tuples (user_id, item_id, rating)\n- n_users: Total number of users\n- n_items: Total number of items\n\nReturns:\n- user_item_matrix: A matrix where rows represent users and columns represent items",
"func... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from surprise import Dataset, Reader, SVD\nfrom surprise.model_selection import train_test_split\nfrom surprise.accuracy import rmse\n\ndef create_and_train_model(data):\n \"\"\"\n Creat... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043910",
"row_id": 43910,
"seed_ids": "['Qwen2.5-72B-Instruct_94477']"
} | 0.436757 | Filter_43910 | I | [
"create_user_item_matrix",
"train_recommendation_system",
"predict_rating"
] | 3 | [
[
"train_recommendation_system",
"create_user_item_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"sklearn"
] | false | c69dd0adc98f207c1d84174e1b1507654c710d31 | 9d63c15132b5bfe1b1a0013e71e0abb85353f1ac | |||
v1.0 | instruct | Filter | Filter_43953_I | I need to create a Python script that will automatically check if my website is up and running. If the website is down, the script should send me an email notification. How can I achieve this? | import smtplib
import requests
def check_website(url, email_config):
"""
Checks if the website is up and running. If it is down, sends an email notification.
Parameters:
url (str): The URL of the website to check.
email_config (dict): A dictionary containing the following email configuration:
... | import pytest
from unittest.mock import patch, MagicMock
from solution import check_website, send_email
@patch('requests.get')
def test_check_website_up(mock_get):
mock_get.return_value.status_code = 200
email_config = None # not needed for this test
assert check_website('http://example.com', email_config... | [
{
"docstring": "Checks if the website is up and running. If it is down, sends an email notification.\n\nParameters:\nurl (str): The URL of the website to check.\nemail_config (dict): A dictionary containing the following email configuration:\n - 'smtp_server' (str): SMTP server address.\n - 'smtp_port' (i... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.mime.text import MIMEText\n\ndef check_website(url):\n \"\"\"\n Checks if the website is up and running.\n Returns True if the website is u... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043953",
"row_id": 43953,
"seed_ids": "['Qwen2.5-72B-Instruct_94543']"
} | 0.467023 | Filter_43953 | I | [
"check_website",
"send_email"
] | 2 | [
[
"check_website",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | defc4f4c583d72a27a9a2006fcf0c21cd1895719 | 5d0bfe328261160dc068f7d43e495cbba6295176 | |||
v1.0 | instruct | Filter | Filter_43978_I | Can you help me understand how to use the `map` function in Python to apply a function to each item in a list? I've seen it used in some code, but I'm not sure how it works exactly. | def square(x):
"""
Returns the square of x.
"""
return x * x
def apply_square_to_list(numbers):
"""
Applies the square function to each item in the list of numbers.
"""
return list(map(square, numbers)) | from solution import square, apply_square_to_list
def test_square_positive_number():
assert square(2) == 4
assert square(5) == 25
def test_square_zero():
assert square(0) == 0
def test_square_negative_number():
assert square(-3) == 9
def test_apply_square_to_list():
assert apply_square_to_list([... | [
{
"docstring": "Returns the square of x.",
"function_declaration": "def square(x):",
"function_name": "square",
"parameter_list": "(x)"
},
{
"docstring": "Applies the square function to each item in the list of numbers.",
"function_declaration": "def apply_square_to_list(numbers):",
... | [
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 add(x, y):\n \"\"\"\n Returns the sum of x and y.\n \"\"\"\n return x + y",
"test_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043978",
"row_id": 43978,
"seed_ids": "['Qwen2.5-72B-Instruct_94591']"
} | 0.422106 | Filter_43978 | I | [
"square",
"apply_square_to_list"
] | 2 | [
[
"apply_square_to_list",
"square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d909b456f7b3154387fd20a749897192defddb7a | 982a4c65eb035a89ba4567e13534c5d6539d8dc6 | |||
v1.0 | instruct | Filter | Filter_44002_I | Write a program in Python that generates a list of the first 100 prime numbers and prints them. | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def generate_primes(limit):
primes = []
... | from solution import is_prime, generate_primes, first_100_primes
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
def test_generate_primes():
primes = generate_primes(10)
assert le... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def generate_primes(limit):",
"function_name": "generate_primes",
"parameter_list": "(limit)"
},
{
"docst... | [
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_1 | {
"original_instruction": "",
"prompt_id": "00044002",
"row_id": 44002,
"seed_ids": "['Qwen2.5-72B-Instruct_94624']"
} | 0.588263 | Filter_44002 | I | [
"is_prime",
"generate_primes",
"first_100_primes"
] | 3 | [
[
"first_100_primes",
"generate_primes"
],
[
"generate_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 094af9f1824ff7a46d883ce161e027d4ff605865 | 0e5299ecc9432856ec9a46a798fa3a275dec26cc | |||
v1.0 | instruct | Filter | Filter_44013_I | How can I create a Python script that automatically checks if a website is up and sends an email notification if the website is down? I want to check the website every 5 minutes. | import smtplib
import requests
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website(url):
"""
Checks if the website is up. Returns True if the website is up, False otherwise.
"""
try:
response = requests.get(url)
return respon... | import pytest
from unittest.mock import patch, MagicMock
from solution import check_website, send_email_notification
@patch("solution.requests.get")
def test_check_website_up(mock_get):
mock_get.return_value.status_code = 200
assert check_website("http://example.com") == True
@patch("solution.requests.get")
d... | [
{
"docstring": "Checks if the website is up. Returns True if the website is up, False otherwise.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(url)"
},
{
"docstring": "Sends an email notification.",
"function_declaration": "def... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport requests\nimport time\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef check_website(url):\n \"\"\"\n Checks if the web... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044013",
"row_id": 44013,
"seed_ids": "['Qwen2.5-72B-Instruct_94639']"
} | 0.542087 | Filter_44013 | I | [
"check_website",
"send_email_notification",
"monitor_website"
] | 3 | [
[
"monitor_website",
"check_website"
],
[
"monitor_website",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | d62b92509ec12dc48f456a67e3682ab42ee60ac1 | f784913b8d264540017f0ed760363f91787b9372 | |||
v1.0 | instruct | Filter | Filter_44027_I | I want to create a Python program that simulates a simple dice roll game. The game should allow a user to roll a six-sided die and then tell them if they rolled an even or odd number. How can I do this? | import random
def roll_dice():
"""
Simulates rolling a six-sided die and returns the result.
"""
return random.randint(1, 6)
def is_even(number):
"""
Returns True if the number is even, False otherwise.
"""
return number % 2 == 0
def roll_and_check_even_or_odd():
"""
Rolls a s... | from solution import roll_dice, is_even, roll_and_check_even_or_odd
def test_roll_dice():
for _ in range(1000):
result = roll_dice()
assert 1 <= result <= 6
def test_is_even():
assert is_even(2) == True
assert is_even(4) == True
assert is_even(6) == True
assert is_even(1) == False
... | [
{
"docstring": "Simulates rolling a six-sided die and returns the result.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Returns True if the number is even, False otherwise.",
"function_declaration": "def is_even(numb... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice():\n \"\"\"\n Simulates rolling a six-sided die and returns the result.\n \"\"\"\n return random.randint(1, 6)\n\ndef check_even_odd(number):\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044027",
"row_id": 44027,
"seed_ids": "['Qwen2.5-72B-Instruct_94667']"
} | 0.540006 | Filter_44027 | I | [
"roll_dice",
"is_even",
"roll_and_check_even_or_odd"
] | 3 | [
[
"roll_and_check_even_or_odd",
"is_even"
],
[
"roll_and_check_even_or_odd",
"roll_dice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a78ca8e099675fe5e930fcf71d487a1dfec64299 | 5c920d2769f673578582dab598c1ec6a83e389d8 | |||
v1.0 | instruct | Filter | Filter_44069_I | I need to create a simple web application that allows users to upload a file and then displays the content of the file. The application should be built using Python and Flask. Can you guide me through the process? | from flask import Flask, request, render_template_string
app = Flask(__name__)
UPLOAD_FOLDER = '/tmp'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_E... | import pytest
from flask import Flask, request
from werkzeug.datastructures import FileStorage
from io import BytesIO
from solution import app, allowed_file
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_upload_form_get(client):
response = client.get('/')
ass... | [
{
"docstring": null,
"function_declaration": "def allowed_file(filename):",
"function_name": "allowed_file",
"parameter_list": "(filename)"
},
{
"docstring": null,
"function_declaration": "def upload_form():",
"function_name": "upload_form",
"parameter_list": "()"
},
{
"d... | [
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, render_template_string\n\napp = Flask(__name__)\n\nUPLOAD_FOLDER = 'uploads'\napp.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER\n\n@app.route('/')\ndef homepage():\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044069",
"row_id": 44069,
"seed_ids": "['Qwen2.5-72B-Instruct_94731']"
} | 0.449991 | Filter_44069 | I | [
"allowed_file",
"upload_form",
"upload_file"
] | 3 | [
[
"upload_file",
"allowed_file"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask",
"werkzeug"
] | false | 11f1590eb6fcbdc07201bb5aca43c5a2f557a84e | 73163f7a38513ebc20dc46eca676bc9e519c7ef9 | |||
v1.0 | instruct | Filter | Filter_44083_I | Write a Python program that converts a given temperature from Celsius to Fahrenheit and vice versa. The user should be able to specify the direction of conversion (Celsius to Fahrenheit or Fahrenheit to Celsius) and the temperature value. The program should output the converted temperature rounded to two decimal places... | def celsius_to_fahrenheit(celsius):
"""
Convert Celsius to Fahrenheit.
Parameters:
celsius (float): Temperature in Celsius.
Returns:
float: Temperature in Fahrenheit rounded to two decimal places.
"""
return round((celsius * 9/5) + 32, 2)
def fahrenheit_to_celsius(fahrenheit):
... | import pytest
from solution import convert_temperature, celsius_to_fahrenheit, fahrenheit_to_celsius
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(-40) == -40
assert celsius_to_fahrenheit(37) == 98.6
def te... | [
{
"docstring": "Convert Celsius to Fahrenheit.\n\nParameters:\ncelsius (float): Temperature in Celsius.\n\nReturns:\nfloat: Temperature in Fahrenheit rounded to two decimal places.",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_l... | [
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 Convert Celsius to Fahrenheit.\n \n Args:\n celsius (float): Temperature in Celsius.\n\n Returns:\n float: Temperature in Fa... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044083",
"row_id": 44083,
"seed_ids": "['Qwen2.5-72B-Instruct_94759']"
} | 0.443789 | Filter_44083 | 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 | eaeffb19124d60fa7d454d4686550d623eadbc9e | 34a9044bfbc102c99c40e1d5414ba1b8a7140b74 | |||
v1.0 | instruct | Filter | Filter_44119_I | Can you help me understand how to use the `map` function in Python, especially with multiple arguments? I've seen examples using `itertools.starmap`, but I'm not sure how it differs from the standard `map` function when using functions that take more than one argument. Could you provide a clear example to illustrate th... | from itertools import starmap
def add(x, y):
"""
Returns the sum of x and y.
"""
return x + y
def example_with_map():
"""
Shows example with map using two lists of arguments.
"""
numbers1 = [1, 2, 3]
numbers2 = [4, 5, 6]
return list(map(add, numbers1, numbers2))
def example_wi... | from solution import add, example_with_map, example_with_starmap
def test_example_with_map():
assert example_with_map() == [5, 7, 9]
def test_example_with_starmap():
assert example_with_starmap() == [5, 7, 9]
def test_add():
assert add(1, 1) == 2
assert add(-1, 1) == 0
assert add(0, 0) == 0
a... | [
{
"docstring": "Returns the sum of x and y.",
"function_declaration": "def add(x, y):",
"function_name": "add",
"parameter_list": "(x, y)"
},
{
"docstring": "Shows example with map using two lists of arguments.",
"function_declaration": "def example_with_map():",
"function_name": "ex... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b.\n \"\"\"\n return a + b\n\nimport itertools\n\ndef example_using_map(func, iterable1, iterable2):\n \"\"\"\n Demonstrate... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044119",
"row_id": 44119,
"seed_ids": "['Qwen2.5-72B-Instruct_94813']"
} | 0.420656 | Filter_44119 | I | [
"add",
"example_with_map",
"example_with_starmap"
] | 3 | [
[
"example_with_map",
"add"
],
[
"example_with_starmap",
"add"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4d9f0e103d6fd1a64c0fc6823d5a876275e478fb | 38aef8c6c9377256367bf1d268062662617c83ec | |||
v1.0 | instruct | Filter | Filter_44123_I | I need to create a simple web application that allows users to upload a CSV file, which the application will then process and display the first 10 rows. I'm using Python with Flask. Can you provide a basic example of how to achieve this? | from flask import Flask, request, redirect, url_for, render_template_string
import pandas as pd
from werkzeug.utils import secure_filename
import os
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads'
app.config['ALLOWED_EXTENSIONS'] = {'csv'}
if not os.path.exists(app.config['UPLOAD_FOLDER']):
os.maked... | import pytest
from flask import Flask
from flask.testing import FlaskClient
from io import BytesIO
from solution import app
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_upload_file(client: FlaskClient):
data = {
'file': (BytesIO(b"col1,col2,col3\n1,2,3\... | [
{
"docstring": null,
"function_declaration": "def allowed_file(filename):",
"function_name": "allowed_file",
"parameter_list": "(filename)"
},
{
"docstring": null,
"function_declaration": "def upload_file():",
"function_name": "upload_file",
"parameter_list": "()"
},
{
"d... | [
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, redirect, url_for, render_template_string\nimport pandas as pd\nfrom werkzeug.utils import secure_filename\nimport os\n\napp = Flask(__name__)\napp.config['UP... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044123",
"row_id": 44123,
"seed_ids": "['Qwen2.5-72B-Instruct_94817']"
} | 0.502773 | Filter_44123 | I | [
"allowed_file",
"upload_file",
"upload_file_post"
] | 3 | [
[
"upload_file_post",
"allowed_file"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask",
"pandas",
"werkzeug"
] | false | 80587380a7f6165533cf5d0f48d980949fba9c19 | 52efb34d7ec6c75c5a41b27869d4e0d5f9293b0a | |||
v1.0 | instruct | Filter | Filter_44130_I | How can I use a lambda function to trigger a specific action in AWS, such as sending an email when a new file is uploaded to an S3 bucket? | import boto3
def send_email(subject, body, to_address):
"""
Sends an email using AWS Simple Email Service (SES).
"""
client = boto3.client('ses')
response = client.send_email(
Source='your-email@example.com',
Destination={
'ToAddresses': [to_address],
},
... | from unittest.mock import patch
def test_send_email_success():
with patch('boto3.client') as mock_client:
instance = mock_client.return_value
instance.send_email.return_value = {'MessageId': 'test-id'}
# Import the function
from solution import send_email
r... | [
{
"docstring": "Sends an email using AWS Simple Email Service (SES).",
"function_declaration": "def send_email(subject, body, to_address):",
"function_name": "send_email",
"parameter_list": "(subject, body, to_address)"
},
{
"docstring": "Lambda handler that is triggered when a file is uploa... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nimport boto3\n\ndef lambda_handler(event, context):\n \"\"\"\n AWS Lambda handler function to send an email when a new file is uploaded to an S3 bucket.\n\n Args:\n ev... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044130",
"row_id": 44130,
"seed_ids": "['Qwen2.5-72B-Instruct_94830']"
} | 0.367094 | Filter_44130 | I | [
"send_email",
"lambda_handler"
] | 2 | [
[
"lambda_handler",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"boto3"
] | false | 25ad6e652d4bc88b74ec99781ca7c3aaaaff4cac | 1a57825b11e8bcc70ae95fc7763b3be36e774c8a | |||
v1.0 | instruct | Filter | Filter_44148_I | How can I create a Python function that generates a random integer within a specific range, say between 1 and 100, and then checks if this number is a prime number? I want the function to return the generated number and a boolean indicating whether it is prime or not. | import random
def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
re... | from solution import is_prime, generate_random_prime_status
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(13) == True
assert is_prime(29) == True
# Test known non-prime numbers
assert... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a random integer within the range [start, end], and checks if it is a prime number.\nReturns a... | [
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 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... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044148",
"row_id": 44148,
"seed_ids": "['Qwen2.5-72B-Instruct_94861']"
} | 0.610278 | Filter_44148 | I | [
"is_prime",
"generate_random_prime_status"
] | 2 | [
[
"generate_random_prime_status",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b408b8e2ff91288e8595ca39fae825ffa75efb40 | b71b2d89c89593448f448ef760baa9e950f687c1 | |||
v1.0 | instruct | Filter | Filter_44150_I | I'm working on a project where I need to compare the performance of different sorting algorithms in Python. Can you provide a brief overview of how to implement and compare Bubble Sort, Quick Sort, and Merge Sort in Python? It would be great if you could also include a simple way to measure the execution time for each ... | import time
import random
def bubble_sort(arr):
"""
Bubble Sort implementation
"""
n = len(arr)
for i in range(n - 1):
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):
"""
Q... | from solution import bubble_sort, quick_sort, merge_sort, measure_time
def test_bubble_sort():
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = [11, 12, 22, 25, 34, 64, 90]
assert bubble_sort(arr.copy()) == sorted_arr
def test_quick_sort():
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = [11, 12, 2... | [
{
"docstring": "Bubble Sort implementation",
"function_declaration": "def bubble_sort(arr):",
"function_name": "bubble_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Quick Sort implementation",
"function_declaration": "def quick_sort(arr):",
"function_name": "quick_sort",
"p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nfrom typing import List\n\ndef bubble_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts an array using the bubble sort algorithm.\n \"\"\"\n n = len(arr)\n for i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044150",
"row_id": 44150,
"seed_ids": "['Qwen2.5-72B-Instruct_94863']"
} | 0.523372 | Filter_44150 | I | [
"bubble_sort",
"quick_sort",
"merge_sort",
"merge",
"measure_time"
] | 5 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fb17cc42f5760a922ab4bc185ed6949e11ad1c38 | 36512cfd9ed9f0c35ff58bb77526b432e1b60077 | |||
v1.0 | instruct | Filter | Filter_44297_I | How can I create a simple chatbot using Python and Flask? I want it to respond to basic greetings and farewells. | from flask import Flask, request, jsonify
app = Flask(__name__)
def chatbot_response(message):
greetings = ["hi", "hello", "hey", "greetings"]
farewells = ["bye", "goodbye", "see you", "take care"]
message = message.lower()
if any(greeting in message for greeting in greetings):
return "Hello... | import pytest
from solution import chatbot_response
def test_greeting_response():
assert chatbot_response("Hi") == "Hello! How can I help you today?"
assert chatbot_response("hello") == "Hello! How can I help you today?"
assert chatbot_response("Greetings") == "Hello! How can I help you today?"
assert ... | [
{
"docstring": null,
"function_declaration": "def chatbot_response(message):",
"function_name": "chatbot_response",
"parameter_list": "(message)"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat",
"parameter_list": "()"
}
] | [
1,
1,
0
] | 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\ndef chatbot_response(message):\n greetings = [\"hi\", \"hello\", \"hey\", \"greetings\"]\n farewells = [\"bye\", \"g... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044297",
"row_id": 44297,
"seed_ids": "['Qwen2.5-72B-Instruct_95086']"
} | 0.409157 | Filter_44297 | I | [
"chatbot_response",
"chat"
] | 2 | [
[
"chat",
"chatbot_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 844e678c8263d0b574ad02539c2d547d7c9c2792 | 29e3d8940615f8a837f301a8d61047ff48920695 | |||
v1.0 | instruct | Filter | Filter_44305_I | I need to understand the concept of mutual recursion in programming. Can you explain it to me and provide a simple example in Python? | def is_even(n):
"""
Returns True if n is an even number, False otherwise.
"""
if n == 0:
return True
else:
return is_odd(n - 1)
def is_odd(n):
"""
Returns True if n is an odd number, False otherwise.
"""
if n == 0:
return False
else:
return is_eve... | from solution import is_even, is_odd
def test_is_even():
assert is_even(0) == True
assert is_even(2) == True
assert is_even(4) == True
assert is_even(1) == False
assert is_even(3) == False
def test_is_odd():
assert is_odd(0) == False
assert is_odd(1) == True
assert is_odd(5) == True
... | [
{
"docstring": "Returns True if n is an even number, False otherwise.",
"function_declaration": "def is_even(n):",
"function_name": "is_even",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if n is an odd number, False otherwise.",
"function_declaration": "def is_odd(n):",
"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(n):\n \"\"\"\n Returns True if n is an even number, False otherwise.\n Utilizes mutual recursion with is_odd.\n \"\"\"\n if n == 0:\n return True\n else:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044305",
"row_id": 44305,
"seed_ids": "['Qwen2.5-72B-Instruct_95098']"
} | 0.412208 | Filter_44305 | I | [
"is_even",
"is_odd"
] | 2 | [
[
"is_even",
"is_odd"
],
[
"is_odd",
"is_even"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 67395fdde34d743335d9e5f881b5521e8447deee | e3e1a4db26ac9346e224007dffc5b3ee011d53f0 | |||
v1.0 | instruct | Filter | Filter_44318_I | Write a Python program that converts a given temperature from Celsius to Fahrenheit and vice versa. The program should ask the user to input a temperature and specify whether they want to convert it to Celsius or Fahrenheit. Ensure the program handles invalid inputs gracefully. | 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(value, to_scale):
"""
Converts the given... | from solution import celsius_to_fahrenheit, fahrenheit_to_celsius, convert_temperature
import pytest
def test_celsius_to_fahrenheit():
assert celsius_to_fahrenheit(0) == 32
assert celsius_to_fahrenheit(100) == 212
assert celsius_to_fahrenheit(-40) == -40
assert celsius_to_fahrenheit(37) == 98.6
def te... | [
{
"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": "00044318",
"row_id": 44318,
"seed_ids": "['Qwen2.5-72B-Instruct_95118']"
} | 0.440667 | Filter_44318 | 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 | cc1b7ae0e5893746808c8ebf2be75b41f702f365 | 300300fb53cdcaec860b38464f8b89ca4d3fed97 | |||
v1.0 | instruct | Filter | Filter_44323_I | I need to create a Python script that reads a list of numbers from a text file, one number per line, and calculates the average of these numbers. How can I do this? | def read_numbers_from_file(file_path):
"""
Reads a list of numbers from a text file, one number per line.
:param file_path: Path to the text file.
:return: List of numbers.
"""
numbers = []
with open(file_path, 'r') as file:
for line in file:
numbers.append(float(lin... | import os
import pytest
from solution import read_numbers_from_file, calculate_average, average_from_file
def test_read_numbers_from_file(tmp_path):
# Create a temporary file with numbers
d = tmp_path / "sub"
d.mkdir()
file_path = d / "test_numbers.txt"
numbers = [1.2, 2.4, 3.6, 4.8]
with open(... | [
{
"docstring": "Reads a list of numbers from a text file, one number per line.\n\n:param file_path: Path to the text file.\n:return: List of numbers.",
"function_declaration": "def read_numbers_from_file(file_path):",
"function_name": "read_numbers_from_file",
"parameter_list": "(file_path)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_average_from_file(file_path):\n \"\"\"\n Reads a list of numbers from a text file, one number per line, \n and calculates the average of these numbers.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044323",
"row_id": 44323,
"seed_ids": "['Qwen2.5-72B-Instruct_95130']"
} | 0.638297 | Filter_44323 | I | [
"read_numbers_from_file",
"calculate_average",
"average_from_file"
] | 3 | [
[
"average_from_file",
"calculate_average"
],
[
"average_from_file",
"read_numbers_from_file"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c20dcc756403d3348ccc132a52a8393068355428 | c0d38737dade06d5c68983ef0a91c70d8a7f0ae6 | |||
v1.0 | instruct | Filter | Filter_44327_I | How can I implement a basic chatbot using Python and Flask that can respond to simple user queries? | from flask import Flask, request, jsonify
app = Flask(__name__)
def get_response(user_input):
"""
Responds to simple user queries.
"""
responses = {
"hi": "Hello! How can I help you today?",
"hello": "Hello! How can I help you today?",
"how are you": "I'm a bot, so I'm always f... | from solution import get_response
def test_get_response_greeting():
assert get_response("hi") == "Hello! How can I help you today?"
assert get_response("hello") == "Hello! How can I help you today?"
def test_get_response_status():
assert get_response("how are you") == "I'm a bot, so I'm always functioning... | [
{
"docstring": "Responds to simple user queries.",
"function_declaration": "def get_response(user_input):",
"function_name": "get_response",
"parameter_list": "(user_input)"
},
{
"docstring": null,
"function_declaration": "def chatbot():",
"function_name": "chatbot",
"parameter_l... | [
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(user_input):\n \"\"\"\n Responds to simple user queries.\n \"\"\"\n responses = {\n \"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044327",
"row_id": 44327,
"seed_ids": "['Qwen2.5-72B-Instruct_95136']"
} | 0.392263 | Filter_44327 | I | [
"get_response",
"chatbot"
] | 2 | [
[
"chatbot",
"get_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 3cd3fc55fd55db83db3f0236038ec9882889b36e | ce197ab2c46cacc7bc22414090926fc9ed0d80e1 | |||
v1.0 | instruct | Filter | Filter_44332_I | Write a Python function that takes a list of numbers and returns the largest number that is a prime and also a palindrome. If no such number exists, return -1. | def is_palindrome(n):
return str(n) == str(n)[::-1]
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def largest_prime_palindrome(numbers):
palindromic_primes = [num for num in numbers if is_palindrome(... | from solution import is_palindrome, is_prime, largest_prime_palindrome
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(0) == True
def test_is_prime():
assert is_prime(2) == True
assert is_prime(... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
0,
1,
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 if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef is_palindrome(n):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044332",
"row_id": 44332,
"seed_ids": "['Qwen2.5-72B-Instruct_95147']"
} | 0.711791 | Filter_44332 | I | [
"is_palindrome",
"is_prime",
"largest_prime_palindrome"
] | 3 | [
[
"largest_prime_palindrome",
"is_palindrome"
],
[
"largest_prime_palindrome",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3dd0d0da2b566567c1ae367c8b8dbc3f1904e873 | a833a9181ec0ab6a58576356f612798ae8559610 | |||
v1.0 | instruct | Filter | Filter_44334_I | I need to create a Python script that can monitor the status of a website. The script should check if the website is up and running, and if it's down, it should send an email notification. Can you help me with this? | import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import requests
def check_website_status(url, email_info):
"""
Checks the status of the website. If the website is down, it sends an email notification.
Parameters:
- url (str): The URL of the websit... | from unittest.mock import patch, MagicMock
import pytest
from solution import check_website_status, send_email_notification
@pytest.fixture
def email_info():
return {
'sender_email': 'sender@example.com',
'recipient_email': 'recipient@example.com',
'password': 'password',
'smtp_serv... | [
{
"docstring": "Checks the status of the website. If the website is down, it sends an email notification.\n\nParameters:\n- url (str): The URL of the website to check.\n- email_info (dict): Information needed to send the email.",
"function_declaration": "def check_website_status(url, email_info):",
"fun... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport requests\nfrom email.message import EmailMessage\n\ndef check_website_status(url):\n \"\"\"\n Checks the status of the specified website.\n Returns True if the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044334",
"row_id": 44334,
"seed_ids": "['Qwen2.5-72B-Instruct_95150']"
} | 0.499394 | Filter_44334 | I | [
"check_website_status",
"send_email_notification"
] | 2 | [
[
"check_website_status",
"send_email_notification"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 929780fe10d17df525ec109570cda49504c6f89d | 6116f5544ae2e27264c53639d43fef932fbf258a | |||
v1.0 | instruct | Filter | Filter_44345_I | I am a beginner in Python programming and I'm interested in learning how to create a simple game. Can you guide me through the process of creating a basic text-based adventure game? | import random
def display_intro():
print("You are in a dark forest.")
print("In front of you, you see two paths.")
print("One path leads to a treasure, the other to a monster.")
print()
def choose_path():
path = ''
while path != '1' and path != '2':
path = input("Which path will you ta... | from unittest.mock import patch
import solution
def test_choose_path_valid_input():
with patch('builtins.input', return_value='1'):
assert solution.choose_path() == '1'
with patch('builtins.input', return_value='2'):
assert solution.choose_path() == '2'
def test_check_path_treasure():
... | [
{
"docstring": null,
"function_declaration": "def display_intro():",
"function_name": "display_intro",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def choose_path():",
"function_name": "choose_path",
"parameter_list": "()"
},
{
"docstring": nul... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def display_instructions():\n \"\"\"Display the game instructions.\"\"\"\n print(\"Welcome to the Adventure Game!\")\n print(\"Navigate through the rooms by typing directions: North, ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044345",
"row_id": 44345,
"seed_ids": "['Qwen2.5-72B-Instruct_95170']"
} | 0.376396 | Filter_44345 | I | [
"display_intro",
"choose_path",
"check_path",
"play_game"
] | 4 | [
[
"play_game",
"check_path"
],
[
"play_game",
"choose_path"
],
[
"play_game",
"display_intro"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5921971fa94359c2a131aa1252cc8171ce077378 | 6a288ec451fa80e0f8be2010c3bff42c26123cf4 | |||
v1.0 | instruct | Filter | Filter_44367_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 filter out prime numbers from a list of integers. | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n ** 0.5) + 1
for i in range(3, max_divisor, 2):
if n % i == 0:
return False
retur... | from solution import is_prime, filter_primes
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-5)
assert is_prime(13)
assert not is_prime(15)
def test_filter_primes... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out and returns the prime numbers from a given list of integers.",
"function_declaration": "def filter_pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only even pri... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044367",
"row_id": 44367,
"seed_ids": "['Qwen2.5-72B-Instruct_95207']"
} | 0.764705 | Filter_44367 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 337ea00a255ca0a513329bc57c49e57442240b15 | 7720b7b096ebdf4294a21d7c923d262e2f7d6869 | |||
v1.0 | instruct | Filter | Filter_44390_I | How can I create a Python script that automatically sends an email when a specific condition is met in a data monitoring system? | import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):
"""
Sends an email with the specified subject and body.
"""
msg = MIMEMultipart()
msg['From'] = from_email... | from unittest.mock import patch
from solution import send_email, check_condition_and_send_email
@patch('smtplib.SMTP')
def test_send_email(mock_smtp):
send_email(subject="Test",
body="This is a test email.",
to_email="to@example.com",
from_email="from@example.com",
... | [
{
"docstring": "Sends an email with the specified subject and body.",
"function_declaration": "def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):",
"function_name": "send_email",
"parameter_list": "(subject, body, to_email, from_email, smtp_server, smtp_por... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email(subject: str, body: str, to_email: str, from_email: str, from_password: s... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044390",
"row_id": 44390,
"seed_ids": "['Qwen2.5-72B-Instruct_95245']"
} | 0.48616 | Filter_44390 | I | [
"send_email",
"check_condition_and_send_email"
] | 2 | [
[
"check_condition_and_send_email",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 92a0af5825c74edfc8ba992cd7fb94187b1d5f66 | 5dcf080d05b5023286b028638f8f72f3de4b18f0 | |||
v1.0 | instruct | Filter | Filter_44393_I | How can I create a Python script to automatically send an email when a specific condition is met in a monitored process? | import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):
"""
Send an email using the specified SMTP server and credentials.
Parameters:
subject : str : The subjec... | import pytest
# Mocking libraries for testing
from unittest.mock import patch, MagicMock
# Function to test the send_email function
def test_send_email():
with patch("smtplib.SMTP") as mock_smtp:
send_email(
'Test Subject',
'This is a test email.',
'test@recipient.com',... | [
{
"docstring": "Send an email using the specified SMTP server and credentials.\n\nParameters:\nsubject : str : The subject of the email\nbody : str : The body content of the email\nto_email : str : Recipient email address\nfrom_email : str : Sender email address\nsmtp_server : str : SMTP server address\nsmtp_po... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_user, s... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044393",
"row_id": 44393,
"seed_ids": "['Qwen2.5-72B-Instruct_95251']"
} | 0.549043 | Filter_44393 | I | [
"send_email",
"monitor_and_notify",
"condition_met"
] | 3 | [
[
"monitor_and_notify",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 37b6682f18951eb2ea28f6f66b79441e937ef22f | a66252dd1ae1c385fd2ba8bbb13e784ec6aa3992 | |||
v1.0 | instruct | Filter | Filter_44395_I | Can you help me with a Python script to monitor a website's availability and response time? I want to be notified via email if the website is down or the response time exceeds a certain threshold. | import smtplib
import requests
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject']... | import pytest
import requests
from unittest.mock import patch, Mock
from solution import check_website, send_email
@patch('solution.requests.get')
@patch('solution.send_email')
def test_check_website_success(mock_send_email, mock_get):
mock_get.return_value.status_code = 200
url = "http://example.com"
thre... | [
{
"docstring": null,
"function_declaration": "def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):",
"function_name": "send_email",
"parameter_list": "(subject, body, to_email, from_email, smtp_server, smtp_port, login, password)"
},
{
"docstring": nu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.application import MIMEApplication\nimport time\n\ndef se... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044395",
"row_id": 44395,
"seed_ids": "['Qwen2.5-72B-Instruct_95254']"
} | 0.560133 | Filter_44395 | I | [
"send_email",
"check_website"
] | 2 | [
[
"check_website",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | c6a181013df1d69c942906df6bbe785b3d9f3a76 | 997570de778df78e9558a60cef943911380c3925 | |||
v1.0 | instruct | Filter | Filter_44435_I | Is it possible to design a function in Python that converts a given string to its base64 encoding and then decodes it back to the original string? I would like to see a simple example of how this can be done. | import base64
def encode_to_base64(s):
"""
Encodes a given string to base64.
"""
return base64.b64encode(s.encode()).decode()
def decode_from_base64(b64_string):
"""
Decodes a base64 string back to the original string.
"""
return base64.b64decode(b64_string.encode()).decode()
def enco... | from solution import encode_to_base64, decode_from_base64, encode_and_decode
def test_encode_to_base64():
assert encode_to_base64("hello") == "aGVsbG8="
assert encode_to_base64("world") == "d29ybGQ="
assert encode_to_base64("!") == "IQ=="
def test_decode_from_base64():
assert decode_from_base64("aGVsb... | [
{
"docstring": "Encodes a given string to base64.",
"function_declaration": "def encode_to_base64(s):",
"function_name": "encode_to_base64",
"parameter_list": "(s)"
},
{
"docstring": "Decodes a base64 string back to the original string.",
"function_declaration": "def decode_from_base64(b... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import base64\n\ndef encode_base64(s):\n \"\"\"\n Encodes a given string into base64.\n \"\"\"\n encoded_bytes = base64.b64encode(s.encode('utf-8'))\n encoded_str = encoded_byte... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044435",
"row_id": 44435,
"seed_ids": "['Qwen2.5-72B-Instruct_95306']"
} | 0.668681 | Filter_44435 | I | [
"encode_to_base64",
"decode_from_base64",
"encode_and_decode"
] | 3 | [
[
"encode_and_decode",
"decode_from_base64"
],
[
"encode_and_decode",
"encode_to_base64"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c28e836f09b5a69991d01d2c32f8b7ffb76aa711 | eb2b0c270795d885f1cf4f1a134381dcb3798695 | |||
v1.0 | instruct | Filter | Filter_44444_I | How can I create a basic chatbot using Python and Flask that can respond to simple text inputs? | from flask import Flask, request, jsonify
app = Flask(__name__)
# A simple function to generate responses
def generate_response(user_input):
responses = {
"hello": "Hello! How can I help you today?",
"how are you": "I'm just a bot, but I'm doing great! How about you?",
"bye": "Goodbye! Hav... | import pytest
from solution import app
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_chat_hello(client):
response = client.post('/chat', json={"message": "hello"})
json_data = response.get_json()
assert response.status_code == 200
assert json_data["r... | [
{
"docstring": null,
"function_declaration": "def generate_response(user_input):",
"function_name": "generate_response",
"parameter_list": "(user_input)"
},
{
"docstring": null,
"function_declaration": "def chat():",
"function_name": "chat",
"parameter_list": "()"
}
] | [
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('/chatbot', methods=['POST'])\ndef chatbot():\n user_input = request.json.get('message')\n if user_input:... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044444",
"row_id": 44444,
"seed_ids": "['Qwen2.5-72B-Instruct_95316']"
} | 0.366167 | Filter_44444 | I | [
"generate_response",
"chat"
] | 2 | [
[
"chat",
"generate_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 6d658e4b92f0f312bb89e50a243f843379941c27 | 13e6404a27db0f186d8431d511b09364c1d6e4a9 | |||
v1.0 | instruct | Filter | Filter_44446_I | How can I create a simple chatbot using Python that can answer basic questions like the weather or time? | import datetime
import random
def get_weather():
"""
Returns a simulated weather condition.
"""
weather_conditions = ["sunny", "rainy", "cloudy", "stormy", "snowy"]
return random.choice(weather_conditions)
def get_time():
"""
Returns the current time in HH:MM format.
"""
now = date... | import re
from solution import get_weather, get_time, chatbot_response
def test_get_weather():
weather_options = ["sunny", "rainy", "cloudy", "stormy", "snowy"]
assert get_weather() in weather_options
def test_get_time():
current_time = get_time()
assert re.match(r"\d{2}:\d{2}", current_time) # Check... | [
{
"docstring": "Returns a simulated weather condition.",
"function_declaration": "def get_weather():",
"function_name": "get_weather",
"parameter_list": "()"
},
{
"docstring": "Returns the current time in HH:MM format.",
"function_declaration": "def get_time():",
"function_name": "ge... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import datetime\nimport random\n\ndef get_weather():\n \"\"\"\n Returns a simulated weather condition.\n \"\"\"\n weather_conditions = [\"sunny\", \"rainy\", \"cloudy\", \"stormy\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044446",
"row_id": 44446,
"seed_ids": "['Qwen2.5-72B-Instruct_95320']"
} | 0.463721 | Filter_44446 | I | [
"get_weather",
"get_time",
"chatbot_response"
] | 3 | [
[
"chatbot_response",
"get_time"
],
[
"chatbot_response",
"get_weather"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 30c6f6a8fa0e596bf033516db96b022fd02ce0fc | 756917a6d9a62c3ed9a832711ca2490669165a8b | |||
v1.0 | instruct | Filter | Filter_44472_I | Can you help me understand how to implement a basic neural network using PyTorch? I'm new to deep learning and PyTorch, and I'd like to start with a simple example. | import torch
import torch.nn as nn
import torch.optim as optim
# Define a simple neural network
class SimpleNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(input_size, hidden_size)
self.relu = nn.ReLU()
s... | import torch
from solution import SimpleNN, train_nn
def test_nn_structure():
input_size = 10
hidden_size = 5
output_size = 1
model = SimpleNN(input_size, hidden_size, output_size)
assert isinstance(model.fc1, torch.nn.Linear)
assert isinstance(model.relu, torch.nn.ReLU)
assert isinsta... | [] | [
1,
0,
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\n\n# Define a simple neural network\nclass SimpleNN(nn.Module):\n def __init__(self, input_size, hidden_size, output_size):\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044472",
"row_id": 44472,
"seed_ids": "['Qwen2.5-72B-Instruct_95368']"
} | 0.25658 | Filter_44472 | I | [
"train_nn",
"create_and_train_model"
] | 2 | [
[
"create_and_train_model",
"train_nn"
]
] | 1 | [] | false | [
"SimpleNN"
] | true | pytest | true | [
"torch"
] | false | 6e24e9e6204a4cba636cab0a5848993b0a266559 | ee183c88000e465ef771617031b8158b5e92e52c | |||
v1.0 | instruct | Filter | Filter_44479_I | How can I create a Python script to automate the process of checking a website's availability and notify me if it's down? I want to be notified via email if the website is not responding. | import smtplib
import requests
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, body, to_email):
"""
Sends an email using the provided subject, body, and recipient email address.
"""
from_email = 'your_email@example.com'
password = 'your_em... | from solution import send_email, check_website
import pytest
import requests
from unittest.mock import patch, Mock
@patch('solution.smtplib.SMTP')
def test_send_email(mock_smtp):
mock_server = Mock()
mock_smtp.return_value = mock_server
send_email('Test Subject', 'Test Body', 'to@example.com')
mock_ser... | [
{
"docstring": "Sends an email using the provided subject, body, and recipient email address.",
"function_declaration": "def send_email(subject, body, to_email):",
"function_name": "send_email",
"parameter_list": "(subject, body, to_email)"
},
{
"docstring": "Checks the availability of a web... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef check_website(url):\n \"\"\"\n Checks the availability of the... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044479",
"row_id": 44479,
"seed_ids": "['Qwen2.5-72B-Instruct_95385']"
} | 0.563875 | Filter_44479 | I | [
"send_email",
"check_website"
] | 2 | [
[
"check_website",
"send_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 487edfa7156074460859d5ebe2532575dd61b5ca | 4fb85fc7771274f7d5a4f0666a14671a89ae7647 | |||
v1.0 | instruct | Filter | Filter_44481_I | Can you help me with a basic Python script to automate a task? I need to create a script that will read a list of URLs from a text file, check if each URL is reachable, and then write the status (reachable or not) to another text file. How can I do this? | import requests
def check_url_reachability(url):
"""
Checks if the given URL is reachable.
Returns 'reachable' if the URL is reachable, otherwise 'not reachable'.
"""
try:
response = requests.head(url, timeout=5)
if response.status_code < 400:
return 'reachable'
... | import requests
from solution import check_url_reachability, process_urls
import tempfile
def test_check_url_reachability(monkeypatch):
class MockResponse:
def __init__(self, status_code):
self.status_code = status_code
def mock_head(url, timeout=5):
if url == "http://example.... | [
{
"docstring": "Checks if the given URL is reachable.\nReturns 'reachable' if the URL is reachable, otherwise 'not reachable'.",
"function_declaration": "def check_url_reachability(url):",
"function_name": "check_url_reachability",
"parameter_list": "(url)"
},
{
"docstring": "Reads URLs from... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\n\ndef check_urls(input_file, output_file):\n \"\"\"\n Reads a list of URLs from `input_file`, checks their reachability,\n and writes the results to `output_file`.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044481",
"row_id": 44481,
"seed_ids": "['Qwen2.5-72B-Instruct_95388']"
} | 0.628474 | Filter_44481 | I | [
"check_url_reachability",
"process_urls"
] | 2 | [
[
"process_urls",
"check_url_reachability"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 457ac936d1cd323fd69b7f9d9904a3e07386155a | 41025d7fed8fe976ac25af51776cb4253b099b37 | |||
v1.0 | instruct | Filter | Filter_44486_I | I'm trying to create a simple web application using Flask that displays a greeting message. I want the message to change based on the time of the day (morning, afternoon, evening, night). How can I implement this in my Flask app? | from flask import Flask
from datetime import datetime
app = Flask(__name__)
def get_greeting():
current_hour = datetime.now().hour
if 5 <= current_hour < 12:
return "Good morning!"
elif 12 <= current_hour < 17:
return "Good afternoon!"
elif 17 <= current_hour < 21:
return "Good... | from solution import get_greeting
from unittest.mock import patch
import pytest
@patch('solution.datetime')
def test_greeting_morning(mock_datetime):
mock_datetime.now.return_value = datetime(2023, 10, 9, 8, 0, 0)
assert get_greeting() == "Good morning!"
@patch('solution.datetime')
def test_greeting_afternoon... | [
{
"docstring": null,
"function_declaration": "def get_greeting():",
"function_name": "get_greeting",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def greet():",
"function_name": "greet",
"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\nimport datetime\n\napp = Flask(__name__)\n\ndef get_greeting():\n current_hour = datetime.datetime.now().hour\n if 5 <= current_hour < 12:\n return \"Good... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044486",
"row_id": 44486,
"seed_ids": "['Qwen2.5-72B-Instruct_95393']"
} | 0.489833 | Filter_44486 | I | [
"get_greeting",
"greet"
] | 2 | [
[
"greet",
"get_greeting"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | dc2d4952e05cb15bd0d9a0febacc1ddc9ad1a824 | 5644aa2e1b706bdc8daa0a7a134a0aea2f0abda4 | |||
v1.0 | instruct | Filter | Filter_44489_I | Write a Python program that takes a list of integers and returns the largest number that is a prime number. If there are no prime numbers in the list, the program should return -1. Ensure your program can efficiently handle large lists. | def is_prime(n):
"""
Helper function to determine if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import largest_prime_number
def test_no_primes():
assert largest_prime_number([1, 4, 6, 8, 10]) == -1
def test_all_primes():
assert largest_prime_number([2, 3, 5, 7, 11, 13]) == 13
def test_mixed_numbers():
assert largest_prime_number([4, 6, 15, 3, 19, 10]) == 19
def test_negative_and_posi... | [
{
"docstring": "Helper function to determine if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a list of integers and returns the largest prime number.\nIf there are no prime numbers in the list... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Returns True if n is a prime number, else False. \"\"\"\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_1 | {
"original_instruction": "",
"prompt_id": "00044489",
"row_id": 44489,
"seed_ids": "['Qwen2.5-72B-Instruct_95398']"
} | 0.685974 | Filter_44489 | I | [
"is_prime",
"largest_prime_number"
] | 2 | [
[
"largest_prime_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b9f02145ecd6c2aa089156feba5a04ad89c3be81 | 995254c4a144edfc537455b77fb6fe1395385986 | |||
v1.0 | instruct | Filter | Filter_44516_I | Write a Python program that simulates a simple calculator which can perform basic arithmetic operations like addition, subtraction, multiplication, and division. The user should be able to input two numbers and select the operation they want to perform. The program should then display the result. Make sure to handle di... | def add(a, b):
"""Returns the sum of a and b."""
return a + b
def subtract(a, b):
"""Returns the difference of b subtracted from a."""
return a - b
def multiply(a, b):
"""Returns the product of a and b."""
return a * b
def divide(a, b):
"""Returns the quotient of a divided by b. Handles d... | from solution import add, subtract, multiply, divide, calculator
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(2, 5) == -3
assert subtract(0, 0) == 0
def test_multiply():
assert multiply(2... | [
{
"docstring": "Returns the sum of a and b.",
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the difference of b subtracted from a.",
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculator(a, b, operation):\n \"\"\"\n Simulates a simple calculator for basic arithmetic operations.\n \n Parameters:\n a (float): The first number.\n b (float): The se... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044516",
"row_id": 44516,
"seed_ids": "['Qwen2.5-72B-Instruct_95443']"
} | 0.572347 | Filter_44516 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 007833b35779ffbdeab2e98465886392115b8d50 | d014ac46eacbea59dc7c2e6fbc448aee6d1073ce | |||
v1.0 | instruct | Filter | Filter_44536_I | Can you help me find a way to automate the process of checking if a website is up and running using Python? I would like to run this check every hour and receive an email notification if the site is down. | import requests
import time
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def is_website_up(url):
"""
Checks if the website at the specified URL is up and running.
Parameters:
url (str): The URL of the website to check.
Returns:
... | import pytest
from unittest.mock import patch
import requests
from solution import is_website_up, send_email_notification
def test_is_website_up_success():
with patch('solution.requests.get') as mock_get:
mock_get.return_value.status_code = 200
assert is_website_up("http://example.com") == True
de... | [
{
"docstring": "Checks if the website at the specified URL is up and running.\n\nParameters:\n url (str): The URL of the website to check.\n\nReturns:\n bool: True if the website is up (status code 200), False otherwise.",
"function_declaration": "def is_website_up(url):",
"function_name": "is_web... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport time\nimport smtplib\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef is_website_up(url):\n \"\"\"\n Checks if the web... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044536",
"row_id": 44536,
"seed_ids": "['Qwen2.5-72B-Instruct_95475']"
} | 0.546988 | Filter_44536 | I | [
"is_website_up",
"send_email_notification",
"monitor_website"
] | 3 | [
[
"monitor_website",
"is_website_up"
],
[
"monitor_website",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 0de547c66c93ced2f3328d14e52095457e4f45a0 | 5acd70155d010700ca4a2534515ed98329f0b515 | |||
v1.0 | instruct | Filter | Filter_44568_I | Write a Python program to convert a given decimal number to its binary representation using recursion. The program should also validate the input to ensure it is a positive integer. If the input is not a positive integer, the program should prompt the user to enter a valid number. | def decimal_to_binary(n):
"""
Converts a given positive integer `n` to its binary representation using recursion.
"""
if n == 0:
return "0"
elif n == 1:
return "1"
else:
return decimal_to_binary(n // 2) + str(n % 2)
def validate_input(n):
"""
Validates the input ... | import pytest
from solution import decimal_to_binary, validate_input, get_binary_representation
def test_decimal_to_binary():
assert decimal_to_binary(1) == "1"
assert decimal_to_binary(4) == "100"
assert decimal_to_binary(10) == "1010"
assert decimal_to_binary(19) == "10011"
def test_validate_input(... | [
{
"docstring": "Converts a given positive integer `n` to its binary representation using recursion.",
"function_declaration": "def decimal_to_binary(n):",
"function_name": "decimal_to_binary",
"parameter_list": "(n)"
},
{
"docstring": "Validates the input to ensure it is a positive integer."... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_binary(n):\n \"\"\"\n Converts a given positive integer `n` to its binary representation using recursion.\n \"\"\"\n if n == 0:\n return \"0\"\n elif n == ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044568",
"row_id": 44568,
"seed_ids": "['Qwen2.5-72B-Instruct_95531']"
} | 0.805674 | Filter_44568 | I | [
"decimal_to_binary",
"validate_input",
"get_binary_representation"
] | 3 | [
[
"get_binary_representation",
"decimal_to_binary"
],
[
"get_binary_representation",
"validate_input"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2c6975423d93be4a1a83d62fca72820cbd8c5b51 | f0b8a0c054a7b5af38b3cf782cb3efdcdfbc3fa9 | |||
v1.0 | instruct | Filter | Filter_44571_I | Write a Python program that reads a CSV file containing a column of dates and calculates the number of weekdays between each date and the current date. The CSV file has a header row and the dates are in the format "YYYY-MM-DD". The output should be a new CSV file with the original dates and the corresponding number of ... | import csv
from datetime import datetime, timedelta
import pandas as pd
def count_weekdays_between_dates(start_date, end_date):
"""
Returns the number of weekdays between start_date and end_date.
"""
day_count = 0
current_date = start_date
while current_date < end_date:
if current_date.... | from solution import count_weekdays_between_dates, process_csv
import datetime
import os
def test_count_weekdays_between_dates():
start_date = datetime.date(2023, 10, 1)
end_date = datetime.date(2023, 10, 15)
assert count_weekdays_between_dates(start_date, end_date) == 10 # 2 full weeks with 5 weekdays ea... | [
{
"docstring": "Returns the number of weekdays between start_date and end_date.",
"function_declaration": "def count_weekdays_between_dates(start_date, end_date):",
"function_name": "count_weekdays_between_dates",
"parameter_list": "(start_date, end_date)"
},
{
"docstring": "Reads a CSV file... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nfrom datetime import datetime, timedelta\n\ndef is_weekday(date):\n \"\"\"\n Returns True if the given date is a weekday, otherwise False.\n \"\"\"\n return date.weekda... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044571",
"row_id": 44571,
"seed_ids": "['Qwen2.5-72B-Instruct_95536']"
} | 0.681197 | Filter_44571 | I | [
"count_weekdays_between_dates",
"process_csv"
] | 2 | [
[
"process_csv",
"count_weekdays_between_dates"
]
] | 1 | [] | false | [] | false | pytest | true | [
"pandas"
] | false | 8a053fcff50986a3859733ea4756defaa4623658 | 5da1138c94cb4af99a4fe8579c95dd4575ce6eb1 | |||
v1.0 | instruct | Filter | Filter_44576_I | Is there a way to create a Python script that can automate the process of checking if a website is up and running, and if it's not, send an email notification? | import requests
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website_status(url):
"""
Checks if the website at the given URL is up and running.
"""
try:
response = requests.get(url)
return response.status_code == 200
ex... | from unittest.mock import patch
import pytest
from solution import check_website_status, send_email_notification, notify_if_website_down
def test_check_website_status():
# Test with a valid URL
with patch('solution.requests.get') as mock_get:
mock_get.return_value.status_code = 200
assert check... | [
{
"docstring": "Checks if the website at the given URL is up and running.",
"function_declaration": "def check_website_status(url):",
"function_name": "check_website_status",
"parameter_list": "(url)"
},
{
"docstring": "Sends an email notification.",
"function_declaration": "def send_ema... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nimport requests\n\ndef check_website(url):\n \"\"\"\n Checks if the website is up and running.\n \"\"\"\n try:\n respon... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044576",
"row_id": 44576,
"seed_ids": "['Qwen2.5-72B-Instruct_95546']"
} | 0.487021 | Filter_44576 | I | [
"check_website_status",
"send_email_notification",
"notify_if_website_down"
] | 3 | [
[
"notify_if_website_down",
"check_website_status"
],
[
"notify_if_website_down",
"send_email_notification"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | bba9f96e2e5965742eef261613c8c1be81865ec8 | 1be59e4aa05310054347c06951a219007afb76ef | |||
v1.0 | instruct | Filter | Filter_44588_I | Explain the concept of mutual recursion in programming. Provide an example in Python. | def is_even(n):
"""
Determines if a number n is even using mutual recursion.
"""
if n == 0:
return True
else:
return is_odd(n - 1)
def is_odd(n):
"""
Determines if a number n is odd using mutual recursion.
"""
if n == 0:
return False
else:
return ... | from solution import is_even, is_odd
def test_is_even():
assert is_even(0) == True
assert is_even(2) == True
assert is_even(4) == True
assert is_even(1) == False
assert is_even(3) == False
def test_is_odd():
assert is_odd(0) == False
assert is_odd(1) == True
assert is_odd(3) == True
... | [
{
"docstring": "Determines if a number n is even using mutual recursion.",
"function_declaration": "def is_even(n):",
"function_name": "is_even",
"parameter_list": "(n)"
},
{
"docstring": "Determines if a number n is odd using mutual recursion.",
"function_declaration": "def is_odd(n):",... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(n):\n \"\"\"\n Returns True if the number n is even, otherwise returns False.\n \"\"\"\n if n == 0:\n return True\n else:\n return is_odd(n - 1)\n\n\nd... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044588",
"row_id": 44588,
"seed_ids": "['Qwen2.5-72B-Instruct_95569']"
} | 0.442576 | Filter_44588 | I | [
"is_even",
"is_odd"
] | 2 | [
[
"is_even",
"is_odd"
],
[
"is_odd",
"is_even"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6dff317dda5d4b6c97ee3caf05f67cf8a518ab9f | cf76753a4c5f8ff9aac1aa043d41f57ba89adb54 | |||
v1.0 | instruct | Filter | Filter_44602_I | How can I implement a basic recommendation system using collaborative filtering in Python? I have a dataset of user ratings for movies, and I want to recommend movies to users based on the ratings of similar users. Can you guide me through the process, including the necessary Python libraries and a simple example? | import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
def load_data():
# Example data: user-item ratings
# In a real scenario, this would be replaced with loading data from a file or database
data = {'user_id': [1, 1, 1, 2, 2, 2, 3, 3],
'movie_id': [101, ... | import pandas as pd
from solution import load_data, create_user_item_matrix, calculate_similarity, get_similar_users, recommend_movies, recommend_for_user
def test_load_data():
data = load_data()
assert isinstance(data, pd.DataFrame)
assert "user_id" in data.columns
assert "movie_id" in data.columns
... | [
{
"docstring": null,
"function_declaration": "def load_data():",
"function_name": "load_data",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def create_user_item_matrix(ratings):",
"function_name": "create_user_item_matrix",
"parameter_list": "(ratings)"... | [
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\nimport pandas as pd\nfrom sklearn.metrics.pairwise import cosine_similarity\n\ndef collaborative_filtering_recommender(user_ratings, user_id, top_n=5):\n \"\"\"\n Rec... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044602",
"row_id": 44602,
"seed_ids": "['Qwen2.5-72B-Instruct_95593']"
} | 0.478224 | Filter_44602 | I | [
"load_data",
"create_user_item_matrix",
"calculate_similarity",
"get_similar_users",
"recommend_movies",
"recommend_for_user"
] | 6 | [
[
"recommend_for_user",
"calculate_similarity"
],
[
"recommend_for_user",
"create_user_item_matrix"
],
[
"recommend_for_user",
"get_similar_users"
],
[
"recommend_for_user",
"load_data"
],
[
"recommend_for_user",
"recommend_movies"
]
] | 5 | [] | false | [] | false | pytest | true | [
"numpy",
"pandas",
"sklearn"
] | false | f44a7bc7c5ea40d331a32e33c4b78ca8fc39fc54 | 429614a5a5ab6863cd48807d5e114215d8bc4e4d | |||
v1.0 | instruct | Filter | Filter_44611_I | Can you help me understand how to use the `map()` function in Python? I'm a bit confused about its syntax and how to apply it to a list of numbers. | def square(x):
"""
Returns the square of the input number x.
"""
return x * x
def use_map_to_square(numbers):
"""
Takes a list of numbers and returns a new list with the square of each number
by using the map() function.
"""
return list(map(square, numbers)) | from solution import square, use_map_to_square
def test_square():
assert square(2) == 4
assert square(0) == 0
assert square(-3) == 9
def test_use_map_to_square():
assert use_map_to_square([1, 2, 3, 4, 5]) == [1, 4, 9, 16, 25]
assert use_map_to_square([0, 0, 0]) == [0, 0, 0]
assert use_map_to_s... | [
{
"docstring": "Returns the square of the input number x.",
"function_declaration": "def square(x):",
"function_name": "square",
"parameter_list": "(x)"
},
{
"docstring": "Takes a list of numbers and returns a new list with the square of each number\nby using the map() function.",
"funct... | [
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 a number.\n \"\"\"\n return x * x\n\ndef apply_square(numbers):\n \"\"\"\n Applies the square function to a list of numbers us... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044611",
"row_id": 44611,
"seed_ids": "['Qwen2.5-72B-Instruct_95602']"
} | 0.467409 | Filter_44611 | I | [
"square",
"use_map_to_square"
] | 2 | [
[
"use_map_to_square",
"square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4c785f68c74d738cb5b14b4fb1f1c5855f9e8e8a | f2a8fc8114203ba15d7d94cd64fc5ff4de34a481 | |||
v1.0 | instruct | Filter | Filter_44625_I | Can you explain how to use the `filter()` function in Python, and provide an example of filtering a list of numbers to only include even numbers? | def is_even(number):
"""
Returns True if the number is even, else False.
"""
return number % 2 == 0
def filter_even_numbers(numbers):
"""
Filters a list of numbers to only include even numbers.
:param numbers: List of integers
:return: List of even integers
"""
return list(... | from solution import is_even, filter_even_numbers
def test_is_even():
assert is_even(2) == True
assert is_even(3) == False
assert is_even(0) == True
assert is_even(-2) == True
assert is_even(-3) == False
def test_filter_even_numbers():
assert filter_even_numbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]... | [
{
"docstring": "Returns True if the number is even, else False.",
"function_declaration": "def is_even(number):",
"function_name": "is_even",
"parameter_list": "(number)"
},
{
"docstring": "Filters a list of numbers to only include even numbers.\n\n:param numbers: List of integers\n:return: ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_even(number):\n \"\"\"\n Returns True if number is even, else False.\n \"\"\"\n return number % 2 == 0\n\ndef filter_even_numbers(numbers):\n \"\"\"\n Filters the give... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044625",
"row_id": 44625,
"seed_ids": "['Qwen2.5-72B-Instruct_95630']"
} | 0.717498 | Filter_44625 | I | [
"is_even",
"filter_even_numbers"
] | 2 | [
[
"filter_even_numbers",
"is_even"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f55485def1179e2f97c5a9d506a0d11519c6d3d | 5479788683f56e7d4d1231c7137a6ce15edb7ee0 | |||
v1.0 | instruct | Filter | Filter_44626_I | Can you help me understand how to use a specific function in a programming language? I'm trying to learn how to use the `filter()` function in Python to filter out even numbers from a list. | def is_even(number):
"""
Returns True if the number is even, else False.
"""
return number % 2 == 0
def filter_even_numbers(numbers):
"""
Filters out even numbers from a given list of numbers using the filter function.
"""
return list(filter(is_even, numbers)) | from solution import filter_even_numbers
def test_filter_even_numbers_with_all_evens():
assert filter_even_numbers([2, 4, 6, 8]) == [2, 4, 6, 8]
def test_filter_even_numbers_with_no_evens():
assert filter_even_numbers([1, 3, 5, 7]) == []
def test_filter_even_numbers_with_mixed_numbers():
assert filter_ev... | [
{
"docstring": "Returns True if the number is even, else False.",
"function_declaration": "def is_even(number):",
"function_name": "is_even",
"parameter_list": "(number)"
},
{
"docstring": "Filters out even numbers from a given list of numbers using the filter function.",
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def filter_even_numbers(numbers):\n \"\"\"\n Filters out the even numbers from a list.\n \"\"\"\n return list(filter(lambda x: x % 2 == 0, numbers))",
"test_code": "from soluti... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044626",
"row_id": 44626,
"seed_ids": "['Qwen2.5-72B-Instruct_95634']"
} | 0.617907 | Filter_44626 | I | [
"is_even",
"filter_even_numbers"
] | 2 | [
[
"filter_even_numbers",
"is_even"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e61b4cd414b39c1516c3186c766b155b5ecee2d9 | b26b98626aaae9f0f8dd6a4d94279d5b8fcc4c79 | |||
v1.0 | instruct | Filter | Filter_44635_I | Can you help me with a Python script to automate the process of downloading files from a list of URLs and saving them to a specific directory? The script should also log the status of each download (success or failure) and the time taken for each download. | import os
import requests
import logging
from time import time
def download_file(url, save_dir):
"""
Downloads a file from the given URL and saves it to the specified directory.
Logs the status and time taken for the download.
"""
if not os.path.exists(save_dir):
os.makedirs(save_dir)
... | import os
import tempfile
from solution import download_file, download_files_from_list
def test_download_file_success(monkeypatch):
class MockResponse:
@staticmethod
def raise_for_status():
pass
@staticmethod
def iter_content(chunk_size=8192):
return iter([b... | [
{
"docstring": "Downloads a file from the given URL and saves it to the specified directory.\nLogs the status and time taken for the download.",
"function_declaration": "def download_file(url, save_dir):",
"function_name": "download_file",
"parameter_list": "(url, save_dir)"
},
{
"docstring"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport requests\nimport logging\nfrom time import time\n\ndef download_file(url, save_dir):\n \"\"\"\n Downloads a file from the given URL and saves it to the specified direct... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044635",
"row_id": 44635,
"seed_ids": "['Qwen2.5-72B-Instruct_95646']"
} | 0.630226 | Filter_44635 | I | [
"download_file",
"download_files_from_list"
] | 2 | [
[
"download_files_from_list",
"download_file"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 368db24ba26b81208480aaf77837a1699464123c | f93e2b777494244843055a95d746760dda03bad1 | |||
v1.0 | instruct | Filter | Filter_44639_I | Write a Python function to calculate the Euclidean distance between two points in 2D space. The function should take two tuples as input, each representing a point (x, y) in 2D space, and return the Euclidean distance between them. Use the standard formula for Euclidean distance, which is the square root of the sum of ... | import math
def euclidean_distance(point1, point2):
"""
Calculate the Euclidean distance between two points in 2D space.
Parameters:
point1 (tuple): The first point as a tuple (x, y).
point2 (tuple): The second point as a tuple (x, y).
Returns:
float: The Euclidean distance betwee... | from solution import euclidean_distance, check_solution
def test_euclidean_distance_same_point():
assert euclidean_distance((0, 0), (0, 0)) == 0
assert euclidean_distance((3, 4), (3, 4)) == 0
def test_euclidean_distance_positive_coordinates():
assert math.isclose(euclidean_distance((1, 2), (4, 6)), 5, rel... | [
{
"docstring": "Calculate the Euclidean distance between two points in 2D space.\n\nParameters:\npoint1 (tuple): The first point as a tuple (x, y).\npoint2 (tuple): The second point as a tuple (x, y).\n\nReturns:\nfloat: The Euclidean distance between point1 and point2.",
"function_declaration": "def euclid... | [
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 euclidean_distance(point1, point2):\n \"\"\"\n Calculates the Euclidean distance between two 2D points.\n \n Parameters:\n point1 (tuple): A tuple representin... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044639",
"row_id": 44639,
"seed_ids": "['Qwen2.5-72B-Instruct_95652']"
} | 0.664705 | Filter_44639 | I | [
"euclidean_distance",
"check_solution"
] | 2 | [
[
"check_solution",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9d663bb1751685677253148090bf949516226e91 | 81b2d70ff0b6b5d4afea7167cbc930b09aa7665f | |||
v1.0 | instruct | Filter | Filter_44648_I | Write a Python function that takes a list of integers and returns a new list containing only the elements that are prime numbers. The function should also handle an empty list and return an empty list in that case. Use the most efficient method to check for prime numbers and ensure your solution is optimized for larger... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return Tru... | from solution import filter_primes, is_prime
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(17) == True
assert is_prime(20) == False
def test_filter_primes():
assert filter_primes([2, 3, 4, ... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new list containing only the prime numbers from the input list.",
"function_declaration": "def filter_primes(number... | [
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 if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef filter_primes(numbers):... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044648",
"row_id": 44648,
"seed_ids": "['Qwen2.5-72B-Instruct_95669']"
} | 0.733252 | Filter_44648 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 586be0738412aa0719c3c45d8bfde1a3e2b5450c | 65cab89d616d708de86b7bd2a929ebda0e8a20eb | |||
v1.0 | instruct | Filter | Filter_44652_I | I need to convert a 3D numpy array of shape (128, 128, 3) into a flattened 2D array of shape (128*128, 3) for further processing. Could you provide me with a Python function to accomplish this task? Additionally, I'm interested in understanding the performance of this function, so could you include a simple timing mech... | import numpy as np
import time
def flatten_3d_array(array_3d):
"""
Flattens a 3D numpy array of shape (128, 128, 3) into a 2D numpy array of shape (128*128, 3).
Parameters:
array_3d (np.ndarray): The 3D numpy array to be flattened.
Returns:
np.ndarray: The resulting 2D numpy array.
""... | import numpy as np
from solution import flatten_3d_array, measure_flatten_time
def test_flatten_shape():
array_3d = np.random.rand(128, 128, 3)
flattened_array = flatten_3d_array(array_3d)
assert flattened_array.shape == (128*128, 3)
def test_flatten_content():
array_3d = np.array([[[1, 2, 3], [4, 5, ... | [
{
"docstring": "Flattens a 3D numpy array of shape (128, 128, 3) into a 2D numpy array of shape (128*128, 3).\n\nParameters:\narray_3d (np.ndarray): The 3D numpy array to be flattened.\n\nReturns:\nnp.ndarray: The resulting 2D numpy array.",
"function_declaration": "def flatten_3d_array(array_3d):",
"fu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport time\n\ndef flatten_3d_array(arr):\n \"\"\"\n Flattens a 3D numpy array of shape (128, 128, 3) into a 2D array of shape (128*128, 3).\n \n Parameters:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044652",
"row_id": 44652,
"seed_ids": "['Qwen2.5-72B-Instruct_95677']"
} | 0.579385 | Filter_44652 | I | [
"flatten_3d_array",
"measure_flatten_time"
] | 2 | [
[
"measure_flatten_time",
"flatten_3d_array"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 90b7cae7e0d0c1ef10908784751499f79c377fb5 | 3db91137655c231a18652ed07cf1aac5b0da15b9 | |||
v1.0 | instruct | Filter | Filter_44656_I | Write a code snippet in Python that prints the Fibonacci sequence up to a given number n, where n is the number of terms to be printed. Each number should be on a new line. Ensure that your code is optimized for performance. | def fibonacci_sequence(n):
"""
Prints the Fibonacci sequence up to n terms.
"""
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
fib_seq = [0, 1]
for i in range(2, n):
next_term = fib_seq[-1] + fib_seq[-2]
fib_seq.append(nex... | from solution import fibonacci_sequence, print_fibonacci_sequence
import io
import sys
def test_fibonacci_sequence_zero():
assert fibonacci_sequence(0) == []
def test_fibonacci_sequence_one():
assert fibonacci_sequence(1) == [0]
def test_fibonacci_sequence_two():
assert fibonacci_sequence(2) == [0, 1]
d... | [
{
"docstring": "Prints the Fibonacci sequence up to n terms.",
"function_declaration": "def fibonacci_sequence(n):",
"function_name": "fibonacci_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Prints each term of the Fibonacci sequence up to n terms on a new line.",
"function_decla... | [
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 Prints the Fibonacci sequence up to n terms.\n \"\"\"\n if n <= 0:\n return\n a, b = 0, 1\n for _ in range(n):\n print(a)\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044656",
"row_id": 44656,
"seed_ids": "['Qwen2.5-72B-Instruct_95683']"
} | 0.742653 | Filter_44656 | I | [
"fibonacci_sequence",
"print_fibonacci_sequence"
] | 2 | [
[
"print_fibonacci_sequence",
"fibonacci_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f582f4ba3a7a428c8d528e6828f58f7c53ddae71 | 2be2c3c8b526c8a1e3c950ba86ee4bb53ef83261 | |||
v1.0 | instruct | Filter | Filter_44677_I | How can I design a Python script to automate the process of checking the availability of a list of websites? I want the script to output the status of each website (e.g., "Online", "Offline") and also log any errors encountered during the process. | import requests
from datetime import datetime
def check_website_status(websites):
"""
Returns the status of the given websites.
:param websites: List of website URLs
:return: Dictionary with website URL as key and its status ("Online", "Offline") as value
"""
status_dict = {}
for website in... | from solution import check_website_status, log_error
import os
import requests
from unittest.mock import patch
def test_check_website_status_online():
websites = ["http://example.com"]
with patch("requests.get") as mock_get:
mock_get.return_value.status_code = 200
status = check_website_st... | [
{
"docstring": "Returns the status of the given websites.\n:param websites: List of website URLs\n:return: Dictionary with website URL as key and its status (\"Online\", \"Offline\") as value",
"function_declaration": "def check_website_status(websites):",
"function_name": "check_website_status",
"p... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\n\ndef check_website_status(urls):\n \"\"\"\n Checks the availability of a list of websites and returns their status.\n \n Parameters:\n urls (list): List of web... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044677",
"row_id": 44677,
"seed_ids": "['Qwen2.5-72B-Instruct_95723']"
} | 0.599591 | Filter_44677 | I | [
"check_website_status",
"log_error"
] | 2 | [
[
"check_website_status",
"log_error"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 6a48591052ec090f70ddcea76a30eb381872ae96 | d6e08af8821fecdf28cf0b77952fb639aafaa71f | |||
v1.0 | instruct | Filter | Filter_44695_I | Write a Python program to calculate the sum of all prime numbers between 1 and a given number n. The program should also include a function to check if a number is prime. Ensure the program is efficient for large values of n. | def is_prime(num):
"""
Check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6... | from solution import is_prime, sum_of_primes
def test_is_prime():
# Test prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
# Test non-prime numbers
assert is_prime(4) == False
assert is_prime(1) == False
# Test larger prime value
assert is_prime(29) == True
# Test ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Calculate the sum of all prime numbers between 1 and n (inclusive).",
"function_declaration": "def sum_of_primes(n):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if the given number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044695",
"row_id": 44695,
"seed_ids": "['Qwen2.5-72B-Instruct_95748']"
} | 0.662749 | Filter_44695 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | acc09ea09034767ced53af4877ba5df7e4baf9ba | 79bd3fb00b89ae05588602ff92d037d232bc20ed | |||
v1.0 | instruct | Filter | Filter_44700_I | Write a Python program to generate random sentences using a predefined list of words. The sentences should be grammatically correct and make sense. The program should be able to generate a specified number of sentences, each with a random length. Ensure that the sentences start with a capital letter and end with a full... | import random
def generate_random_sentence(words, min_length=5, max_length=12):
"""
Generates a random sentence from a given list of words.
The sentence will have a random length between min_length and max_length.
The sentence will start with a capital letter and end with a full stop.
"""
sente... | from solution import generate_random_sentence, generate_random_sentences
words = ["the", "quick", "brown", "fox", "jumps", "over", "lazy", "dog"]
def test_generate_random_sentence():
sentence = generate_random_sentence(words)
assert sentence[0].isupper()
assert sentence[-1] == '.'
assert all(word.lowe... | [
{
"docstring": "Generates a random sentence from a given list of words.\nThe sentence will have a random length between min_length and max_length.\nThe sentence will start with a capital letter and end with a full stop.",
"function_declaration": "def generate_random_sentence(words, min_length=5, max_length=... | [
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 generate_random_sentence(words, min_length=3, max_length=10):\n \"\"\"\n Generate a random sentence from a predefined list of words.\n \n Args:\n words (lis... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044700",
"row_id": 44700,
"seed_ids": "['Qwen2.5-72B-Instruct_95755']"
} | 0.792745 | Filter_44700 | I | [
"generate_random_sentence",
"generate_random_sentences"
] | 2 | [
[
"generate_random_sentences",
"generate_random_sentence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 324786475f4794e77097bfe11ac22d2335a63c22 | 57936d5cdb6ab782d8d709741b102f88338a2abc | |||
v1.0 | instruct | Filter | Filter_44711_I | I'm looking to develop a simple application using Python that can help me track my daily water intake. I want it to have a basic GUI and be able to save the data locally. Can you guide me through the process of creating this application? | import sqlite3
from tkinter import Tk, Label, Entry, Button
def create_table():
"""
Create the table for storing water intake data if it doesn't exist.
"""
conn = sqlite3.connect('water_intake.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS intake
(id INTEGER PRI... | import sqlite3
import os
from solution import create_table, add_water_intake
def setup_module(module):
"""Set up the module - remove the database file if it exists"""
try:
os.remove('water_intake.db')
except OSError:
pass
create_table()
def teardown_module(module):
"""Tear down the... | [
{
"docstring": "Create the table for storing water intake data if it doesn't exist.",
"function_declaration": "def create_table():",
"function_name": "create_table",
"parameter_list": "()"
},
{
"docstring": "Add a water intake record to the database.",
"function_declaration": "def add_wa... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import tkinter as tk\nfrom tkinter import messagebox, Label, Entry, Button\nimport os\n\nclass WaterTrackerApp:\n def __init__(self, root):\n self.root = root\n self.root.titl... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044711",
"row_id": 44711,
"seed_ids": "['Qwen2.5-72B-Instruct_95770']"
} | 0.352133 | Filter_44711 | I | [
"create_table",
"add_water_intake",
"submit",
"main"
] | 4 | [
[
"submit",
"add_water_intake"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e36ad54edf8387413aa4d5588dddc46aba9526b6 | a9a105a91b945cf30c62b0c5a2a59de21aa28a75 | |||
v1.0 | instruct | Filter | Filter_44712_I | Can you help me write a function in Python that checks if a number is prime and returns a boolean value? I want to use this function to filter out prime numbers from a list. | def is_prime(n):
"""
Returns True if n is a prime number, 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):
if n % i == 0:
return False
return True
def filter... | 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(18) == False
assert is_prime(19) == True
assert is_prime(-1) == False
assert is_prime(0) == Fal... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out prime numbers from a list and returns a list of prime numbers.",
"function_declaration":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044712",
"row_id": 44712,
"seed_ids": "['Qwen2.5-72B-Instruct_95771']"
} | 0.793605 | Filter_44712 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 91416e891e16f246a236bbdb0d1d77adc5474665 | 706970d6e75e37a236d897adcd2e648998d19ba1 | |||
v1.0 | instruct | Filter | Filter_44714_I | Write a Python function to implement the Merge Sort algorithm on a list of integers. Ensure your function is well-documented, including a brief explanation of the Merge Sort algorithm, and provide a simple example of how to use your function. | def merge_sort(arr):
"""
Performs merge sort on a list of integers.
Merge sort is a divide-and-conquer algorithm that involves:
1. Dividing the list into two halves.
2. Recursively sorting each half.
3. Merging the two sorted halves to produce a single sorted list.
:param arr: List of inte... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([5]) == [5]
def test_merge_sort_sorted():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted():
assert merge_sort([5,... | [
{
"docstring": "Performs merge sort on a list of integers.\n\nMerge sort is a divide-and-conquer algorithm that involves:\n1. Dividing the list into two halves.\n2. Recursively sorting each half.\n3. Merging the two sorted halves to produce a single sorted list.\n\n:param arr: List of integers to be sorted.\n:r... | [
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 Implements the Merge Sort algorithm to sort a list of integers.\n \n Merge Sort is a divide-and-conquer algorithm that divides the list into two hal... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044714",
"row_id": 44714,
"seed_ids": "['Qwen2.5-72B-Instruct_95774']"
} | 0.585691 | Filter_44714 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0fadbf2ba393783fbeaedce8f5035ee0b315e60c | 071869378640277581b15f3ed4b9fdd806e00538 | |||
v1.0 | instruct | Filter | Filter_44717_I | Can you help me write a Python function to find the intersection of two lists, but only for elements that are prime numbers? The function should return a sorted list of the intersecting prime numbers without duplicates. If there are no prime numbers in the intersection, the function should return an empty list. | 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 intersection_of_primes, is_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(13) == True
assert is_prime(1) == False
assert is_prime(0)... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the intersection of two lists, only for elements that are prime numbers.\nThe result should be a sorted list of the ... | [
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 that checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044717",
"row_id": 44717,
"seed_ids": "['Qwen2.5-72B-Instruct_95779']"
} | 0.697412 | Filter_44717 | I | [
"is_prime",
"intersection_of_primes"
] | 2 | [
[
"intersection_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 70c42028e02d2e27586eda6d253c120b6facffe4 | ed2530033cfff69c38aa622ec311eea0baff78a7 | |||
v1.0 | instruct | Filter | Filter_44725_I | I am working on a Python project and I need to create a function that can calculate the least common multiple (LCM) of a list of numbers. The function should be able to handle a variable number of arguments, not just a fixed set. Can you provide a Python code snippet that accomplishes this? Additionally, I would like t... | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // gcd(a, b)
def lcm_multiple(*numbers):
"""
Returns the least common multiple of a list of numbers.
"""
if not numbers:
return 1 # lcm of e... | from solution import lcm_multiple
def test_lcm_single_number():
assert lcm_multiple(5) == 5
assert lcm_multiple(10) == 10
def test_lcm_two_numbers():
assert lcm_multiple(4, 6) == 12
assert lcm_multiple(21, 6) == 42
assert lcm_multiple(2, 8) == 8
def test_lcm_multiple_numbers():
assert lcm_mul... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the least common multiple of a list of numbers.",
"function_declaration": "def lcm_multiple(*numbers):",... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Returns the least common multiple of a and b.\n \"\"\"\n return abs(a * b) // math.gcd(a, b)\n\ndef lcm_of_li... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044725",
"row_id": 44725,
"seed_ids": "['Qwen2.5-72B-Instruct_95791']"
} | 0.683771 | Filter_44725 | I | [
"lcm",
"lcm_multiple"
] | 2 | [
[
"lcm_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6af007bd5ed4ec6ff76c19e15ab6fcabd0b25b9 | 8393d0a52913161a98b9ef364004eae027cf6120 | |||
v1.0 | instruct | Filter | Filter_44728_I | Write a function in Python that takes a list of integers and returns the largest prime number in the list. If there are no prime numbers in the list, the function should return None. | def is_prime(n):
"""Checks if a number is prime."""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def largest_prime(numbers):
"""
Returns the largest prime number in the list of integers.
If there are no prime... | from solution import is_prime, largest_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(1) == False
assert is_prime(0) == False
def test_largest_prime():
... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number in the list of integers.\nIf there are no prime numbers, returns None.",
"function_declarati... | [
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 if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef largest_prime(numbers)... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044728",
"row_id": 44728,
"seed_ids": "['Qwen2.5-72B-Instruct_95797']"
} | 0.745083 | Filter_44728 | I | [
"is_prime",
"largest_prime"
] | 2 | [
[
"largest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50ee18f8299867871543588bee522f597b5ea79c | c3976f7350e24bff113f0051d3a7d9b64502fb69 | |||
v1.0 | instruct | Filter | Filter_44729_I | How can I use Python to generate a random number between 1 and 100, and then check if this number is a prime number? | import random
def generate_random_number():
"""
Generates a random number between 1 and 100.
"""
return random.randint(1, 100)
def is_prime(n):
"""
Checks if a given number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == ... | from solution import generate_random_number, is_prime, random_prime_check
def test_generate_random_number():
for _ in range(100):
number = generate_random_number()
assert 1 <= number <= 100
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) ==... | [
{
"docstring": "Generates a random number between 1 and 100.",
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": "Checks if a given number n is a prime number.",
"function_declaration": "def is_pri... | [
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_number():\n \"\"\"\n Generates a random number between 1 and 100 inclusive.\n \"\"\"\n return random.randint(1, 100)\n\ndef is_prime(n):\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044729",
"row_id": 44729,
"seed_ids": "['Qwen2.5-72B-Instruct_95800']"
} | 0.573435 | Filter_44729 | I | [
"generate_random_number",
"is_prime",
"random_prime_check"
] | 3 | [
[
"random_prime_check",
"generate_random_number"
],
[
"random_prime_check",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0d20e0017b61393c968670319a270a9ee9beab91 | cf8b42c8f2e0f56924c7ce9ca267e9c84b5842ac | |||
v1.0 | instruct | Filter | Filter_44732_I | I want to create a Python program that simulates a simple game of rock-paper-scissors. Can you help me with the code? I want it to be able to play against the computer, which randomly selects its move. The program should also keep track of the score and allow the user to decide when to quit the game. | import random
def get_computer_choice():
"""
Returns a random choice for the computer from 'rock', 'paper', or 'scissors'.
"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(player_choice, computer_choice):
"""
Takes the player's choice and computer's choice and deter... | from solution import determine_winner, get_computer_choice
def test_determine_winner():
assert determine_winner('rock', 'scissors') == 'player'
assert determine_winner('scissors', 'rock') == 'computer'
assert determine_winner('paper', 'rock') == 'player'
assert determine_winner('rock', 'paper') == 'com... | [
{
"docstring": "Returns a random choice for the computer from 'rock', 'paper', or 'scissors'.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Takes the player's choice and computer's choice and determin... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_move():\n \"\"\"\n Returns a randomly chosen move for the computer.\n \"\"\"\n return random.choice([\"rock\", \"paper\", \"scissors\"])\n\ndef de... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044732",
"row_id": 44732,
"seed_ids": "['Qwen2.5-72B-Instruct_95803']"
} | 0.371145 | Filter_44732 | I | [
"get_computer_choice",
"determine_winner",
"play_game"
] | 3 | [
[
"play_game",
"determine_winner"
],
[
"play_game",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1475035593dc5f9b09ddd4326eb496b6d964ab9e | c0b3625eb40f40bcec415c3d3f47c8a1f4527008 | |||
v1.0 | instruct | Filter | Filter_44736_I | I need help with a Python script that can generate random user data for testing purposes. The data should include a username, email, and a random password. Can you provide a script that does this? | import random
import string
def generate_random_username():
"""
Generates a random username.
"""
return ''.join(random.choices(string.ascii_lowercase, k=8))
def generate_random_email(username):
"""
Generates a random email using the provided username.
"""
domains = ["example.com", "tes... | from solution import generate_random_username, generate_random_email, generate_random_password, generate_random_user_data
import re
def test_generate_random_username():
username = generate_random_username()
assert len(username) == 8
assert username.islower()
assert username.isalpha()
def test_generate... | [
{
"docstring": "Generates a random username.",
"function_declaration": "def generate_random_username():",
"function_name": "generate_random_username",
"parameter_list": "()"
},
{
"docstring": "Generates a random email using the provided username.",
"function_declaration": "def generate_r... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\nimport faker\n\ndef generate_random_user_data():\n \"\"\"\n Generates random user data including username, email, and password.\n \"\"\"\n fake = fake... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044736",
"row_id": 44736,
"seed_ids": "['Qwen2.5-72B-Instruct_95808']"
} | 0.53046 | Filter_44736 | I | [
"generate_random_username",
"generate_random_email",
"generate_random_password",
"generate_random_user_data"
] | 4 | [
[
"generate_random_user_data",
"generate_random_email"
],
[
"generate_random_user_data",
"generate_random_password"
],
[
"generate_random_user_data",
"generate_random_username"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 55ce236250a8cc6dcdb1f8a1de993faeb15ef007 | e58644f7ed500e445830e62739683318cd9b138d | |||
v1.0 | instruct | Filter | Filter_44748_I | How can I create a simple Python script to monitor the disk usage of a Linux server and alert if the usage exceeds a certain threshold? | import shutil
import smtplib
from email.mime.text import MIMEText
def get_disk_usage():
"""
Returns the percentage of disk usage.
"""
total, used, free = shutil.disk_usage("/")
return (used / total) * 100
def send_alert_email(threshold):
"""
Sends an email alert if disk usage exceeds the t... | from solution import get_disk_usage, send_alert_email
def test_get_disk_usage(monkeypatch):
def mock_disk_usage(path):
return (100, 70, 30) # Mocked to represent 70% usage
monkeypatch.setattr(shutil, 'disk_usage', mock_disk_usage)
assert get_disk_usage() == 70.0
def test_send_alert_email(monkeypa... | [
{
"docstring": "Returns the percentage of disk usage.",
"function_declaration": "def get_disk_usage():",
"function_name": "get_disk_usage",
"parameter_list": "()"
},
{
"docstring": "Sends an email alert if disk usage exceeds the threshold.",
"function_declaration": "def send_alert_email(... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import shutil\nimport smtplib\nfrom email.mime.text import MIMEText\n\ndef get_disk_usage():\n \"\"\"\n Returns the percentage of disk usage.\n \"\"\"\n total, used, free = shutil.... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044748",
"row_id": 44748,
"seed_ids": "['Qwen2.5-72B-Instruct_95826']"
} | 0.519548 | Filter_44748 | I | [
"get_disk_usage",
"send_alert_email"
] | 2 | [
[
"send_alert_email",
"get_disk_usage"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4077e15343fd16d258e2e3e2a0ea0b32e318af43 | 604f6243ef103ac010c041ee8a51aabbcc74ba4b | |||
v1.0 | instruct | Filter | Filter_44780_I | I need to write a Python function that calculates the standard deviation of a given list of numbers. However, I want to do this without using any built-in functions or libraries that directly calculate standard deviation, mean, or perform square root operations. Can you help me write this function? Additionally, I need... | import math
def read_numbers_from_file(file_path):
"""
Reads numbers from a file, with each number on a new line, and returns a list of these numbers.
"""
numbers = []
with open(file_path, 'r') as file:
for line in file:
numbers.append(float(line.strip()))
return numbers
de... | import os
import pytest
from solution import read_numbers_from_file, standard_deviation, square_root
def test_square_root():
assert abs(square_root(4) - 2) < 1e-10
assert abs(square_root(9) - 3) < 1e-10
assert abs(square_root(2) - math.sqrt(2)) < 1e-10
with pytest.raises(ValueError):
square_roo... | [
{
"docstring": "Reads numbers from a file, with each number on a new line, and returns a list of these numbers.",
"function_declaration": "def read_numbers_from_file(file_path):",
"function_name": "read_numbers_from_file",
"parameter_list": "(file_path)"
},
{
"docstring": "Computes the squar... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def mean(numbers):\n \"\"\"\n Calculate the mean (average) of a list of numbers.\n \"\"\"\n total = 0\n count = 0\n for number in numbers:\n total += number\n c... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044780",
"row_id": 44780,
"seed_ids": "['Qwen2.5-72B-Instruct_95877']"
} | 0.668974 | Filter_44780 | I | [
"read_numbers_from_file",
"square_root",
"standard_deviation"
] | 3 | [
[
"standard_deviation",
"square_root"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8225d5b5c8265e3a0a047fff260a10ead071bb89 | e43dd271df0426f71144c0f9237b7ad5712769c6 | |||
v1.0 | instruct | Filter | Filter_44814_I | Can you help me create a Python script to automate the process of checking the availability of a list of websites and logging the results? I want to know if they are up or down, and also measure the response time. | import requests
import time
import logging
def check_website(url):
"""
Checks the availability of a website and measures the response time.
Args:
- url (str): The URL of the website to check.
Returns:
- dict: A dictionary with the website's status and response time.
"""
result = {
... | from solution import check_website, check_websites
import pytest
test_urls = [
"https://www.google.com", # Should be up
"https://www.nonexistentwebsite123456789.com" # Should be down
]
def test_check_website_up():
result = check_website("https://www.google.com")
assert result['status'] == 'up'
a... | [
{
"docstring": "Checks the availability of a website and measures the response time.\nArgs:\n- url (str): The URL of the website to check.\n\nReturns:\n- dict: A dictionary with the website's status and response time.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport time\nimport logging\n\ndef check_website(url):\n \"\"\"\n Checks the availability of a website and measures the response time.\n Args:\n - url (str): The U... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044814",
"row_id": 44814,
"seed_ids": "['Qwen2.5-72B-Instruct_95933']"
} | 0.622186 | Filter_44814 | I | [
"check_website",
"log_results",
"check_websites"
] | 3 | [
[
"check_websites",
"check_website"
],
[
"check_websites",
"log_results"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | c41c7565e10991f0c251f8f4c14a9fb298be6c51 | 8fe9d3c00ba439d0883948b74d7d51a107b0def6 | |||
v1.0 | instruct | Filter | Filter_44815_I | Write a Python program that takes a list of numbers and returns the largest number that is also a prime number. If there are no prime numbers in the list, the program should return a message indicating that there are no prime numbers. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def largest_prime(numbers):
"""
Returns the largest prime number in the list.
If there is no prime num... | from solution import is_prime, largest_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(11) == True
assert is_prime(1) == False
assert is_prime(0) == False... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number in the list.\nIf there is no prime number, returns a message indicating so.",
"function_decla... | [
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 Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00044815",
"row_id": 44815,
"seed_ids": "['Qwen2.5-72B-Instruct_95934']"
} | 0.716332 | Filter_44815 | I | [
"is_prime",
"largest_prime"
] | 2 | [
[
"largest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9bb857603d566d9d64b502fdf8d9f66133ef93de | d74f035ae07f75231727d835a1adad02f1b046e2 | |||
v1.0 | instruct | Filter | Filter_44822_I | How can I use a loop to print out all the prime numbers between 1 and 100 in Python? | def is_prime(num):
"""Helper function to check if a number is prime."""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def print_primes():
"""Print all prime numbers between 1 and 100."""
for num in range(1, 1... | from io import StringIO
import sys
from solution import is_prime, print_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
assert is_prime(97) == True
assert is_prime(1) == Fa... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Print all prime numbers between 1 and 100.",
"function_declaration": "def print_primes():",
"functi... | [
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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044822",
"row_id": 44822,
"seed_ids": "['Qwen2.5-72B-Instruct_95944']"
} | 0.606094 | Filter_44822 | I | [
"is_prime",
"print_primes"
] | 2 | [
[
"print_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3155a3210ae618324905f5af5f3edeb2792cfa3 | 4794baf130dfbd5c80d42976c426f06814ea6aa2 | |||
v1.0 | instruct | Filter | Filter_44873_I | Write a Python program that calculates the sum of all prime numbers between 1 and a given number n. The program should prompt the user to input the value of n and then output the sum of all prime numbers from 1 to n. Ensure the program is efficient and handles edge cases, such as when n is less than 2. | def is_prime(num):
"""
Returns True if the number is prime, otherwise False.
"""
if num <= 1:
return False
if num == 2:
return True # 2 is the only even prime number
if num % 2 == 0:
return False
for i in range(3, int(num**0.5)+1, 2):
if num % i == 0:
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_sum_of_primes():
... | [
{
"docstring": "Returns True if the number is prime, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers between 1 and the given number n.",
"function_declaration":... | [
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 Returns True if the number is prime, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True # 2 is the... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00044873",
"row_id": 44873,
"seed_ids": "['Qwen2.5-72B-Instruct_96036']"
} | 0.636797 | Filter_44873 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9360082c352c6cd82ae8a4c5c822ec46a48d1c8a | 97421f6bb1aa11b02a4135a9ec325b816d269633 | |||
v1.0 | instruct | Filter | Filter_44894_I | Write a Python function that implements a simple text-based game where the player navigates through a maze to find a treasure. The maze is represented by a 2D grid where '0' represents an open path, '1' represents a wall, 'T' is the treasure, and 'P' is the player's starting position. The function should allow the play... | def display_maze(maze):
for row in maze:
print(' '.join(row))
print()
def find_player_position(maze):
for row_index, row in enumerate(maze):
for col_index, cell in enumerate(row):
if cell == 'P':
return (row_index, col_index)
return None
def is_valid_move(ma... | from solution import find_player_position, is_valid_move
def test_find_player_position():
maze = [
['P', '0', '1', '0', 'T'],
['1', '0', '1', '0', '1'],
['1', '0', '0', '0', '1'],
['1', '1', '0', '1', '1'],
['1', '0', '0', '0', '1']
]
assert find_player_position(maze... | [
{
"docstring": null,
"function_declaration": "def display_maze(maze):",
"function_name": "display_maze",
"parameter_list": "(maze)"
},
{
"docstring": null,
"function_declaration": "def find_player_position(maze):",
"function_name": "find_player_position",
"parameter_list": "(maze... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def print_maze(maze):\n for row in maze:\n print(\" \".join(row))\n print()\n\ndef find_position(maze, target):\n for row_idx, row in enumerate(maze):\n for col_idx, col... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00044894",
"row_id": 44894,
"seed_ids": "['Qwen2.5-72B-Instruct_96062']"
} | 0.557721 | Filter_44894 | I | [
"display_maze",
"find_player_position",
"is_valid_move",
"play_maze_game"
] | 4 | [
[
"play_maze_game",
"display_maze"
],
[
"play_maze_game",
"find_player_position"
],
[
"play_maze_game",
"is_valid_move"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 8d4b984e8a4566b197371e08d59126dd73fcc08d | 5d9dddabe0adb694c3e299c59e92d42ed5f3cb4b |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.