source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_instruct_75k | 38,230 | Write a Python function to automate the configuration of certain tools in a development environment. The function should perform the following tasks:
1. Create a symbolic link from a source directory to a target directory.
2. Clear the cache for the Node Version Manager (nvm) using the command `nvm cache clear`.
The f... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import subprocess
def configure_environment(source_dir: str, target_dir: str) -> None:
"""
Automates the configuration of certain tools in a development environment.
This function performs the following tasks:
... |
magic_instruct_75k | 38,231 | Write a Python function to parse and extract specific fields from a given JSON object representing a command packet. The JSON object contains nested fields, and the function should return a new dictionary with the extracted information in a structured format.
The JSON object has the following structure:
```json
{
"c... | Here is the Python code to solve the given problem in the markdown block:
```python
def parse_command_packet(command_packet: dict) -> dict:
"""
Parses and extracts specific fields from a given JSON object representing a command packet.
Args:
command_packet (dict): A JSON object representing a comma... |
magic_instruct_75k | 38,234 | Write a Python function to simulate the process of installing a missing Recovery HD partition on a Mac system. The function should take a list of existing partitions and return the updated list with the added Recovery HD partition. The Recovery HD partition is always named "Recovery HD" and is guaranteed not to be pres... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def install_recovery_hd(existing_partitions: List[str]) -> List[str]:
"""
Simulates the process of installing a missing Recovery HD partition on a Mac system.
Args:
existing_partitions (List... |
magic_instruct_75k | 38,253 | Create a Python function `custom_assert` that mimics the behavior of the built-in `assert` statement. The function should take a condition, an optional error message, and an optional encoder class for customizing error message encoding. Additionally, it should accept arbitrary keyword arguments for further customizatio... | Here is the Python code to solve the given problem in the markdown block:
```python
class EliotJSONEncoder:
"""
A placeholder class for encoding messages. In a real-world scenario, this class would implement encoding logic.
"""
def encode(self, msg):
return msg # Placeholder implementation
def... |
magic_instruct_75k | 38,256 | Write a Python function to transpose a given matrix. Transposing a matrix involves converting its rows into columns and vice versa. The function should handle matrices of any size and correctly transpose them. The code should start with:
```python
from typing import List
def transpose_matrix(matrix: List[List[int]]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Transposes the given matrix by converting its rows into columns and vice versa.
Args:
matrix (List[List[int]]): A 2D lis... |
magic_instruct_75k | 38,259 | Write a Python function that simulates the installation of a web hosting control panel called CyberPanel on a Ubuntu server. The function should take the server operating system as an argument and return a list of actions to be performed in sequence. Each action should be a string representing a shell command.
The fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def install_cyberpanel(server_os: str) -> List[str]:
"""
Simulates the installation of CyberPanel on a Ubuntu server by returning a list of shell commands to be executed in sequence.
Args:
s... |
magic_instruct_75k | 38,304 | Write a Python function to calculate the distance between two points on a 2D plane using their coordinates. The function should take four parameters: the x and y coordinates of the first point, and the x and y coordinates of the second point. The distance should be calculated using the Euclidean distance formula and ro... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_distance(x1: float, y1: float, x2: float, y2: float) -> float:
"""
Calculate the Euclidean distance between two points on a 2D plane.
Args:
x1 (float): The x-coordinate of the first point.... |
magic_instruct_75k | 38,325 | Write a Python function to extract the publication month from a given message and convert it to its corresponding numerical representation. The message contains the publication date in the format "MMM YYYY" (e.g., "Mar 2022" for March 2022). If the message does not contain any valid month abbreviation, the function sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_pub_month(message: str) -> str:
"""
Extracts the publication month from a given message and converts it to its corresponding numerical representation.
Args:
message (str): The message containing the publ... |
magic_instruct_75k | 38,332 | Write a Python function to calculate the sum of all even numbers in a given list of integers. If the input list is empty or does not contain any even numbers, the function should return 0. The function should be named `sum_even_numbers` and should take a single parameter, which is a list of integers.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_even_numbers(nums: List[int]) -> int:
"""
Calculate the sum of all even numbers in a given list of integers.
Args:
nums (List[int]): A list of integers.
Returns:
int: Th... |
magic_instruct_75k | 38,339 | Write a Python function to simulate the process of applying database migrations to a Django project. The function should take a list of migration operations as input and apply these operations to a database schema. Each operation is represented as a tuple with the following format:
```python
(operation_type, model_name... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def apply_migrations(operations: List[Tuple[str, str, str, str]]) -> Dict[str, List[Tuple[str, str]]]:
"""
Simulates the process of applying database migrations to a Django project.
Arg... |
magic_instruct_75k | 38,346 | Write a Python function to find the intersection of multiple sets. The function should take a list of sets as input and return a set containing the elements that are common to all the sets. If the input list is empty, the function should return an empty set.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def findIntersection(sets: List[Set[int]]) -> Set[int]:
"""
Find the intersection of multiple sets.
Args:
sets (List[Set[int]]): A list of sets, each containing distinct integers.
... |
magic_instruct_75k | 38,354 | Write a Python function to process and extract relevant information from a JSON object representing a security finding in AWS Security Hub. The function should return a dictionary containing specific fields from the JSON object.
The function signature is:
```python
def processSecurityFinding(finding: dict) -> dict:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def processSecurityFinding(finding: dict) -> dict:
"""
Processes a JSON object representing a security finding in AWS Security Hub and extracts relevant information.
Args:
finding (dict): A JSON object representing ... |
magic_instruct_75k | 38,364 | Write a Python function to count the number of unique y-coordinates present in a list of tuples representing possible moves in a game. Each tuple contains two integers representing the x and y coordinates of the move. The function should start with:
```python
from typing import List, Tuple
def count_unique_y_coordinat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_unique_y_coordinates(smoves: List[Tuple[int, int]]) -> int:
"""
Counts the number of unique y-coordinates in a list of tuples representing moves.
Args:
smoves (List[Tuple[in... |
magic_instruct_75k | 38,382 | Write a Python function to find the longest palindromic substring in a given string `s`. A palindrome is a sequence of characters that reads the same forward and backward. The function should return the longest palindromic substring found in `s`. If there are multiple longest palindromic substrings, return any one of t... | Here is the Python code to solve the given problem in the markdown block:
```python
def longestPalindrome(s: str) -> str:
"""
Find the longest palindromic substring in the given string `s`.
Args:
s (str): The input string in which to find the longest palindromic substring.
Returns:
str... |
magic_instruct_75k | 38,389 | Create a Python class `Worksheet` that represents a worksheet and provides methods for accessing its data. The class should have the following functionalities:
1. A method `worksheets` that returns a list containing the worksheet itself.
2. A method `get_all_values` that returns the data contained within the worksheet... | Here is the Python code to solve the given problem in the markdown block:
```python
class Worksheet:
def __init__(self, data):
"""
Initializes a Worksheet object with the given data.
Args:
data (list): A list of lists representing the worksheet data.
"""
self.dat... |
magic_instruct_75k | 38,399 | Write a Python function to retrieve licensing information from an IBM Security Access Manager (ISAM) appliance. The function should be able to operate in check mode and force mode, as well as handle potential errors that may occur during the retrieval process. The function should return a dictionary containing the lice... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_licensing_info(isamAppliance, check_mode=False, force=False):
"""
Retrieve the licensing information from an ISAM appliance.
Args:
isamAppliance: Instance of the ISAM appliance.
check_mode (bool): Bo... |
magic_instruct_75k | 38,403 | Write a Python function to prepend a specified number of spaces to a given string. The function should handle cases where the padding value is negative or zero. The code should start with:
```python
def prepend_padding(data: str, padding: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def prepend_padding(data: str, padding: int) -> str:
"""
Prepends a specified number of spaces to the given string.
Args:
data (str): The input string to which spaces will be prepended.
padding (int): The nu... |
magic_instruct_75k | 38,413 | Create a Python class `BankAccount` that simulates a simple bank account. The class should have methods for depositing funds, withdrawing funds, and checking the current balance. Additionally, the class should keep track of the total number of transactions (deposits and withdrawals) made on the account.
The class shou... | Here is the Python code to solve the given problem in the markdown block:
```python
class BankAccount:
def __init__(self):
"""
Initialize the BankAccount with a balance of 0 and 0 transactions.
"""
self.balance = 0
self.transactions = 0
def deposit(self, amount):
... |
magic_instruct_75k | 38,422 | Write a Python function to filter a list of dictionaries based on specific conditions. Each dictionary represents a data item with keys 'type' and 'status', both of which are integers. The function should return a list of dictionaries that meet the following criteria:
1. If the data item's type is 0 and status is 0, it... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def filter_data(data_list: List[Dict[str, Union[int, str]]]) -> List[Dict[str, Union[int, str]]]:
"""
Filters a list of dictionaries based on specific conditions.
Args:
data_lis... |
magic_instruct_75k | 38,453 | Write a Python function to filter a list of dictionaries representing image processing operations. Each dictionary contains the keys `model_name` and `name`, representing the model name and operation name, respectively. The function should return a new list containing only the dictionaries where the `model_name` is 'te... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_image_operations(operations: List[Dict[str, str]]) -> List[Dict[str, str]]:
"""
Filters a list of dictionaries representing image processing operations.
Args:
operations (Li... |
magic_instruct_75k | 38,472 | Write a Python function to find the maximum product of any three numbers in a given list of integers. If the input list contains less than three integers, the function should return 0. The function should be efficient and handle both positive and negative numbers.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_product_of_three(nums: List[int]) -> int:
"""
Calculate the maximum product of any three numbers in the given list.
Args:
nums (List[int]): The list of integers from which to find th... |
magic_instruct_75k | 38,476 | Write a Python function to generate the HTML representation of a simplified HTML tree structure. Each node in the tree is represented by a class `HtmlTree` with attributes `tag`, `content`, and `children`. The `children` attribute is a list of `HtmlTree` objects. The function should recursively generate the HTML string... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
class HtmlTree:
def __init__(self, tag: str, content: str, children: List['HtmlTree'] = None):
self.tag = tag
self.content = content
self.children = children if children is not None e... |
magic_instruct_75k | 38,482 | Write a Python function to automate the setup of a disk image for a Linux system. The function should perform the following tasks:
1. Connect the disk image file to a network block device (NBD) using `qemu-nbd`.
2. Create a partition table and partitions on the connected disk image using `gdisk`.
3. Create a filesystem... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def setup_disk_image(imagefile: str, mountpoint: str) -> List[str]:
"""
Automates the setup of a disk image for a Linux system.
Args:
imagefile (str): The path to the disk image file.
... |
magic_instruct_75k | 38,498 | Write a Python function to automate the installation of a tool called "Kubebuilder" on a Linux system. The function should perform the following steps:
1. Move the Kubebuilder binary from the `/tmp` directory to a long-term location at `/usr/local/kubebuilder`, where `${kb_version}` represents the version of Kubebuilde... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import shutil
def install_kubebuilder(kb_version: str, os_type: str, arch_type: str):
"""
Automates the installation of Kubebuilder on a Linux system.
Args:
kb_version (str): The version of Kubebuilder.
... |
magic_instruct_75k | 38,508 | Write a Python function to process a list of items and return a specific result based on certain conditions. The function should take in a list of items and a result, and return a processed result along with the final result. The processed result should be a set containing unique items from the input list, and the fina... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Set, Tuple
def process_items(items: List[str], result: Any) -> Tuple[Set[str], Any]:
"""
Processes a list of items and returns a set of unique items along with the original result.
Args:
... |
magic_instruct_75k | 38,524 | Write a Python function to upload job binaries to Hadoop Distributed File System (HDFS) and return a list of paths to the uploaded binaries. The function should take in a list of job binaries, proxy configurations, HDFS user, and job directory. Each job binary is represented as a dictionary with keys `'name'` and `'raw... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def upload_job_binaries(job_binaries: List[Dict[str, str]], proxy_configs: Dict[str, str], hdfs_user: str, job_dir: str) -> List[str]:
"""
Uploads job binaries to Hadoop Distributed File System (HD... |
magic_instruct_75k | 38,558 | Write a Python function that takes a list of numbers as input and returns a new list containing the square of each number in the input list. Additionally, the function should print the type of the first element in the input list. The function should be named `square_and_print_type`.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def square_and_print_type(numbers: List[int]) -> List[int]:
"""
Takes a list of numbers, prints the type of the first element, and returns a new list containing the square of each number.
Args:
... |
magic_instruct_75k | 38,584 | Write a Python function to perform DNS lookup and create a TCP socket based on the obtained IP address. The function should take a domain name as input and perform the following steps:
1. Lookup the IP address for the given domain using a hypothetical `lookup_ip_address` function.
2. If the address is obtained successf... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
# Hypothetical functions for DNS lookup and TCP socket creation
def lookup_ip_address(domain: str) -> Optional[str]:
"""
Hypothetical function to lookup the IP address for a given domain.
Args:
... |
magic_instruct_75k | 38,593 | Create a Python function that simulates the execution of a test runner script (`test_runner.sh`) and provides a summary of the test results. The function should:
1. Run a series of predefined test cases.
2. Display the test results, including the number of passed and failed tests.
3. Provide a summary of the test execu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def run_tests(test_cases: List[Tuple[str, bool]]) -> None:
"""
Simulates the execution of a series of test cases and provides a summary of the test results.
Args:
test_cases (List[Tup... |
magic_instruct_75k | 38,604 | Write a Python function to convert a given input string containing special markdown syntax for subscript into the corresponding HTML output. The input string will contain text with the following pattern: `H_{2}O`, where the underscore and curly braces denote the subscript. Your program should identify and replace the s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def convert_subscript_to_html(input_str: str) -> str:
"""
Converts a given input string containing markdown subscript syntax to the corresponding HTML output.
Args:
input_str (str): The input string conta... |
magic_instruct_75k | 38,612 | Create a Python class `SceneManager` that manages a dictionary of scene paths and their corresponding scene data. The class should provide methods for adding new scenes, retrieving scene data, and updating scene paths. Additionally, the class should support context management using the `with` statement to ensure proper... | Here is the Python code to solve the given problem in the markdown block:
```python
class SceneManager:
"""
A class to manage a dictionary of scene paths and their corresponding scene data.
Methods:
add_scene(scene_path, scene_data): Adds a new scene to the dictionary.
get_scene(scene_path)... |
magic_instruct_75k | 38,613 | Write a Python function to automate the process of registering and localizing JavaScript assets for a WordPress plugin. The function should perform the following tasks:
1. Check if the variable `has_assets_front_js` is set to 'y'.
2. If the variable is set to 'y', copy the file `front.js` from the directory specified i... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import shutil
def register_and_localize_js_assets(has_assets_front_js: str, _TOOLSDIR: str, _ASSETS_DIR: str, plugin_version: str) -> None:
"""
Automates the process of registering and localizing JavaScript assets for... |
magic_instruct_75k | 38,619 | Write a Python function to sort a list of dictionaries based on the "age" key in ascending order. If two dictionaries have the same "age", their order should remain unchanged. The function should use a custom sorting algorithm and return the sorted list of dictionaries.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def custom_sort(data: List[Dict[str, int]]) -> List[Dict[str, int]]:
"""
Sorts a list of dictionaries based on the "age" key in ascending order.
If two dictionaries have the same "age", their o... |
magic_instruct_75k | 38,620 | Write a Python function to construct a list of parameters based on the provided command-line flags. The function should take a namespace object `args` containing boolean attributes that indicate whether certain features should be enabled or disabled. The function should append specific strings to the `params` list base... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def construct_params(args) -> List[str]:
"""
Constructs a list of parameters based on the provided command-line flags.
Args:
args: A namespace object containing boolean attributes that indic... |
magic_instruct_75k | 38,642 | Write a Python function to count the occurrences of specific nucleotide patterns in a given DNA sequence. The function should efficiently handle large DNA sequences and return a dictionary with the patterns as keys and their respective counts as values.
The code should start with:
```python
from typing import List, Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_nucleotide_patterns(dna_sequence: str, patterns: List[str]) -> Dict[str, int]:
"""
Counts the occurrences of specific nucleotide patterns in a given DNA sequence.
Args:
dna_s... |
magic_instruct_75k | 38,653 | Write a Python function `get_decimal_sum(decimal_digit_words)` that takes a list of strings `decimal_digit_words` as input. Each string in the list represents a word for a decimal digit in the American number system. The function should convert these words into their corresponding decimal numbers and return the sum of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_decimal_sum(decimal_digit_words: List[str]) -> float:
"""
Converts a list of words representing decimal digits into their corresponding decimal numbers and returns their sum.
Args:
d... |
magic_instruct_75k | 38,663 | Write a Python function to extract a substring from a given string `ziffern` based on the specified start index `a` (inclusive) and end index `b` (exclusive). The function should handle edge cases such as invalid indices and empty strings.
The code should start with:
```python
def get_substring(ziffern: str, a: int, b... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_substring(ziffern: str, a: int, b: int) -> str:
"""
Extracts a substring from the given string `ziffern` from index `a` (inclusive) to index `b` (exclusive).
Args:
ziffern (str): The string from which to ext... |
magic_instruct_75k | 38,684 | Write a Python function to calculate the maximum profit that can be obtained by making at most one transaction (i.e., buying one share and selling one share of the stock) from a given list of daily stock prices. The function should ensure that the stock is sold before it is bought again. The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be obtained by making at most one transaction
(buying one share and selling one share) from a given list of daily s... |
magic_instruct_75k | 38,693 | Write a Python function to generate a secure access token using a secret key and a user ID. The access token is generated by concatenating the user ID with the secret key and then applying a cryptographic hash function (SHA-256) to the concatenated string. The function should take a user ID as input and return the gene... | Here is the Python code to solve the given problem in the markdown block:
```python
import hashlib
SECRET_KEY = '127TUMI'
def generate_access_token(user_id: str) -> str:
"""
Generate a secure access token using a secret key and a user ID.
Args:
user_id (str): The user ID to be used for generating... |
magic_instruct_75k | 38,699 | Write a Python function to calculate the sum of all even numbers in a given array. The function should take an array of integers as input and return the sum of all the even numbers in the array. The code should start with:
```python
from typing import List
def sum_of_even_numbers(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(arr: List[int]) -> int:
"""
Calculate the sum of all even numbers in a given array.
Args:
arr (List[int]): The array of integers from which to calculate the sum of ev... |
magic_instruct_75k | 38,701 | Write a Python function to find the maximum sum of a contiguous subarray within a given list of integers. The function should be optimized to achieve a better time complexity than the given implementation. The code should start with:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given list of integers.
Args:
nums (List[int]): The list of integers from which to ... |
magic_instruct_75k | 38,732 | Write a Python function to format file sizes in a human-readable format. The function should take a list of tuples, where each tuple contains a file name and its size in bytes. The function should return a list of formatted strings, where each string represents a file with its size formatted in KB, MB, or GB, depending... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def format_file_entries(files: List[Tuple[str, int]]) -> List[str]:
"""
Formats file sizes in a human-readable format.
Args:
files (List[Tuple[str, int]]): A list of tuples where each... |
magic_instruct_75k | 38,744 | Write a Python function `populate_currency_info` that takes a dictionary `countries_data` as input and populates another dictionary `infos` with currency IDs as keys and currency names as values. If a currency ID already exists in `infos`, the function should not overwrite the existing currency name.
The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def populate_currency_info(countries_data: dict) -> dict:
"""
Populates a dictionary with unique currency IDs and their corresponding names from a nested dictionary.
Args:
countries_data (dict): A dictionary where e... |
magic_instruct_75k | 38,784 | Create a Python function to manage different types of pin sets in a hardware interface library. The library provides an abstract base class `IPinManager` with methods for creating different types of pin sets. The `PinMode` enum is used to specify the mode of the pins. The derived classes must implement the functions to... | Here is the Python code to solve the given problem in the markdown block:
```python
from abc import ABC, abstractmethod
from typing import List, Union
class IPinSet(ABC):
@abstractmethod
def __init__(self, pin_nums: Union[int, List[int]], pin_mode: str):
pass
class IPinManager(ABC):
@abstractmetho... |
magic_instruct_75k | 38,792 | Write a Python function to process a list of dictionaries representing screenshot managers. Each dictionary contains configuration settings for a screenshot manager. The function should generate a status message for each screenshot manager based on its configuration settings and return a list of these status messages. ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union, Any
def process_screenshot_managers(screenshot_managers: List[Dict[str, Union[str, Any]]]) -> List[str]:
"""
Processes a list of screenshot manager configurations and returns a list of stat... |
magic_instruct_75k | 38,796 | Write a Python function to process a Protobuf message descriptor and extract information about its fields and enums. The function should take in a Protobuf message descriptor and return a dictionary containing the name of the message, the names of the message fields, and all the enum types present in the message.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_protobuf_message(message_descriptor: dict) -> dict:
"""
Processes a Protobuf message descriptor and extracts information about its fields and enums.
Args:
message_descriptor (dict): A dictionary represen... |
magic_instruct_75k | 38,805 | Write a Python function to calculate the total cost of items in a shopping cart. Each item in the cart is represented by a tuple containing the price and quantity of the item. The function should take a list of these tuples and return the total cost of all items in the cart.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_total_cost(items: List[Tuple[float, int]]) -> float:
"""
Calculate the total cost of items in a shopping cart.
Args:
items (List[Tuple[float, int]]): A list of tuples wh... |
magic_instruct_75k | 38,807 | Write a Python function to organize a list of data points into batches based on a specified batch size. The function should handle cases where the total number of data points is not evenly divisible by the batch size by including the remaining data points in the last batch.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_batches(data: List[int], batch_size: int) -> List[List[int]]:
"""
Organizes a list of data points into batches based on a specified batch size.
Args:
data (List[int]): The list of... |
magic_instruct_75k | 38,817 | Write a Python function `count_a(input_string)` that takes a string `input_string` as input and returns a new string containing the number of occurrences of the character 'a' in the input string. The function should ignore the case of the characters, meaning both 'a' and 'A' should be considered as occurrences of 'a'.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_a(input_string: str) -> str:
"""
Counts the number of occurrences of the character 'a' in the input string, ignoring case.
Args:
input_string (str): The input string to count the 'a' characters in.
Re... |
magic_instruct_75k | 38,866 | Write a Bash script to automate the configuration, building, and installation of a Message Passing Interface (MPI) library with CUDA support. The script should perform the following steps:
1. Set the environment variable `$HOME_MPI_DIR` to the directory where the MPI source code is located.
2. Set the environment varia... | Here is the Python code to solve the given problem in the markdown block:
```bash
#!/bin/bash
# Set environment variables
HOME_MPI_DIR="/path/to/mpi/source"
DEF_MPI_DIR="mpi_directory"
DEF_MPI_BUILD="/path/to/mpi/installation"
# Change directory to MPI source
cd "$HOME_MPI_DIR/$DEF_MPI_DIR" || { echo "Failed to chang... |
magic_instruct_75k | 38,867 | Write a Python function to calculate the sum of all even numbers in a given list. The function should take a list of integers as input and return the sum of all the even numbers in the list. The code should start with:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
"""
Calculate the sum of all even numbers in the given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The... |
magic_instruct_75k | 38,887 | Write a Python function to format a care plan item's category and version into a human-readable string. The function should take two parameters: a string representing the category of the care plan item and an integer representing the version of the care plan item. The function should return a formatted string that incl... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_careplan_item(category: str, version: int) -> str:
"""
Formats a care plan item's category and version into a human-readable string.
Args:
category (str): A string representing the category of the care pl... |
magic_instruct_75k | 38,889 | Write a Python function to fetch news articles from a given source and prepare the data to be rendered in a web application. The function should take the source name as input and return a list of tuples, where each tuple contains the news article title, description, and image URL. The function should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def fetch_news_articles(source_name: str) -> List[Tuple[str, str, str]]:
"""
Fetches news articles from a given source and prepares the data to be rendered in a web application.
Args:
... |
magic_instruct_75k | 38,908 | Write a Python function to find the maximum sum of a contiguous subarray within a given one-dimensional array of integers. The function should take in an array of integers and return the maximum sum of any contiguous subarray within the given array. The function should be efficient and handle edge cases such as an empt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given array.
Args:
arr (List[int]): The input array of integers.
Returns:
... |
magic_instruct_75k | 38,911 | Write a Python function to analyze the compatibility of a given Python package with different versions of the Python programming language. The function should take the package name and a list of Python versions as input and output a list of compatible and incompatible versions for the given package.
The function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def check_python_compatibility(package_name: str, python_versions: List[str]) -> Tuple[List[str], List[str]]:
"""
Analyzes the compatibility of a given Python package with different versions of th... |
magic_instruct_75k | 38,979 | Write a Python function to generate commands that modify the `/etc/sysctl.conf` file for a Linux server. The function should take a list of tuples, where each tuple contains a comment, a kernel parameter, and the new value for that parameter. The function should produce a string containing the commands to append these ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_sysctl_commands(modifications: List[Tuple[str, str, str]]) -> str:
"""
Generates commands to modify the /etc/sysctl.conf file based on the given list of kernel parameter modifications... |
magic_instruct_75k | 38,980 | Write a Python function to find the maximum value between two given integers without using any comparison operators (e.g., `>`, `<`, `==`) or ternary operators (e.g., `a ? b : c`). The function should use bitwise operations to determine the maximum value.
The code should start with:
```python
def find_max(a: int, b: i... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max(a: int, b: int) -> int:
"""
Find the maximum value between two integers without using comparison operators.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
i... |
magic_instruct_75k | 38,994 | Write a Python function to parse a given code snippet from a file named `keywords.gperf` and extract the keywords, their associated tokens, and syntax properties. The code snippet contains a list of keywords followed by their tokens and syntax properties, separated by commas. The syntax properties are represented using... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def parseKeywords(code_snippet: str) -> dict:
"""
Parses a code snippet from a file named `keywords.gperf` and extracts the keywords, their associated tokens, and syntax properties.
Args:
code_snippet (st... |
magic_instruct_75k | 38,997 | Write a Python function to count the number of failed tests from a given list of test results. Each test result is represented by a boolean value, where `True` indicates a failed test and `False` indicates a passed test. The function should return the total number of failed tests.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_failed_tests(test_results: List[bool]) -> int:
"""
Counts the number of failed tests from a list of boolean values.
Args:
test_results (List[bool]): A list of boolean values where ... |
magic_instruct_75k | 39,002 | Write a Python function to process a list of integers and perform the following operations:
1. Calculate the sum of all the numbers.
2. Determine the maximum and minimum values from the input.
3. Check if the sum is greater than 100.
The function should return a tuple containing the sum, maximum value, minimum value, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def process_numbers(numbers: List[int]) -> Tuple[int, int, int, bool]:
"""
Processes a list of integers and performs the following operations:
1. Calculates the sum of all the numbers.
2. ... |
magic_instruct_75k | 39,016 | Write a Python function to generate a specified number of unique sample IDs based on a given year and project code. The sample IDs should follow the format "YYYY-GCRSR-XXXX", where "YYYY" is the year, "GCRSR" is the project code, and "XXXX" is a unique 4-digit identifier. The function should ensure that each generated ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_sample_ids(year: int, project_code: str, num_samples: int) -> List[str]:
"""
Generate a specified number of unique sample IDs based on the given year and project code.
Args:
yea... |
magic_instruct_75k | 39,025 | Write a Python function to calculate the factorial of a given non-negative integer using an iterative approach. The function should handle edge cases such as negative numbers and non-integer inputs by raising appropriate exceptions. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer.
Args:
n (int): The non-negative integer for which to calculate the factorial.
Returns:
int: The factorial of th... |
magic_instruct_75k | 39,040 | Write a Python function to process a list of service statements and perform specific actions based on the type of statement. Each service statement is represented as a tuple containing the action and any additional parameters. The possible actions include `save_env`, `auto_provision`, `auto_install_dialog`, `setup_dial... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_service_statements(statements: list) -> list:
"""
Processes a list of service statements and returns a list of executed actions.
Args:
statements (list): A list of tuples where each tuple represents a se... |
magic_instruct_75k | 39,067 | Write a Python function to parse a given code snippet and extract references to methods within a specified class. The code snippet contains references to methods in the format `{@link \ClassName\SubClassName::methodName}`. The function should return a list of dictionaries, where each dictionary contains the class name ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import re
def parseCodeSnippet(code_snippet: str) -> List[Dict[str, str]]:
"""
Parses a given code snippet and extracts references to methods within a specified class.
Args:
code_snipp... |
magic_instruct_75k | 39,069 | Write a Python function to generate all possible combinations of pairs where the first element is from a list of integers `A` and the second element is from a list of characters `Z`. Each pair should be represented as a tuple. The function should take two lists as input and return a list of all possible pairs.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from itertools import product
def generate_pairs(A: List[int], Z: List[str]) -> List[Tuple[int, str]]:
"""
Generates all possible combinations of pairs where the first element is from list `A` and... |
magic_instruct_75k | 39,088 | Write a Python function to retrieve the description of a notification type based on its unique type code. The notification types are defined in a list of tuples, where each tuple contains a type code and a description. If the input type code does not match any defined notification type, the function should return "Unkn... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
TYPE_OF_NOTI = [
('comment_answer', 'Notify when someone comments on your answer'),
('question_comment', 'Notify when someone comments on your question'),
('answer_accepted', 'Notify when your... |
magic_instruct_75k | 39,092 | Write a Python function to manage and update the privileges of a process in a simplified Windows environment. The function should take a dictionary representing the current privileges of a process and a list of privileges that need to be enabled. The function should enable the specified privileges if they are not alrea... | Here is the Python code to solve the given problem in the markdown block:
```python
def manage_privileges(current_privileges: dict, privileges_to_enable: list) -> dict:
"""
Manages and updates the privileges of a process by enabling the specified privileges if they are not already enabled.
Args:
cu... |
magic_instruct_75k | 39,096 | Write a Python function to simulate a simple maze navigation game. The maze is represented as a 2D grid where the player starts at a designated starting point 'S' and must navigate through the maze to reach the end point 'E'. The player can move in four directions: up, down, left, and right. The maze is populated with ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import deque
def run_game(maze: List[List[str]]) -> bool:
"""
Simulate a maze navigation game to determine if the player can reach the end point 'E' from the starting point 'S'.
Arg... |
magic_instruct_75k | 39,101 | Write a Python function to split an iterable into batches of a specified size. The function should take two parameters: `iterable` (a list of items to be split into batches) and `n` (the number of items per batch). The function should return a list of batches, where each batch is a sublist of `iterable` containing `n` ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def batch(iterable: List[Any], n: int) -> List[List[Any]]:
"""
Splits an iterable into batches of a specified size.
Args:
iterable (List[Any]): A list of items to be split into batches.... |
magic_instruct_75k | 39,106 | Write a Python function to determine whether a given string is a palindrome. A palindrome is a sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. The function should return "Yes" if the string is a palindrome and "No" otherwise.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(s: str) -> str:
"""
Determine whether the given string is a palindrome.
A palindrome is a sequence of characters that reads the same forward and backward,
ignoring spaces, punctuation, and capitalizati... |
magic_instruct_75k | 39,108 | Write a Python function to determine whether the parentheses in a given string are balanced. A string is considered balanced if it consists of pairs of opening and closing parentheses, with each opening parenthesis having a corresponding closing parenthesis in the correct order. The function should return `True` if the... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_parentheses(s: str) -> bool:
"""
Determines whether the parentheses in the given string are balanced.
Args:
s (str): The input string containing parentheses and other characters.
Returns:
... |
magic_instruct_75k | 39,110 | Write a Python function to join a list of strings into a single string. The function should take a list of strings as input and return a single string that concatenates all the elements of the input list.
The code should start with:
```python
from typing import List
def join_strings(components: List[str]) -> str:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def join_strings(components: List[str]) -> str:
"""
Joins a list of strings into a single string.
Args:
components (List[str]): A list of strings to be joined.
Returns:
str: A s... |
magic_instruct_75k | 39,114 | Write a Python function to calculate the area of a circle given its radius. The function should be able to handle both positive and zero radius values. Additionally, write unit tests to verify the correctness of the area calculation logic.
The code should start with:
```python
import math
def calculate_circle_area(ra... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_circle_area(radius: float) -> float:
"""
Calculate the area of a circle given its radius.
Args:
radius (float): The radius of the circle. Must be a non-negative number.
Returns:
... |
magic_instruct_75k | 39,122 | Write a Python function to reverse the order of directories found in a given list and then delete the directories in the reversed order. The function should take a list of directories as input and return the list of directories in reverse order. Additionally, it should print each directory in the reversed order before ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_and_delete_dirs(dirsFound: List[str]) -> List[str]:
"""
Reverses the order of directories found in a given list and then deletes the directories in the reversed order.
Args:
dirs... |
magic_instruct_75k | 39,142 | Write a Python function to simulate the configuration of a virtual tunnel endpoint (VTEP) for a software-defined networking (SDN) environment. The VTEP manages logical switches, binds virtual machines (VMs) to these switches, and sets up remote connections for inter-host communication. The function should accept a list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def simulate_vtep_config(commands: List[str]) -> Dict[str, Any]:
"""
Simulate the configuration of a virtual tunnel endpoint (VTEP) for an SDN environment.
Args:
commands (List[st... |
magic_instruct_75k | 39,144 | Create a Python class `UMLModelElement` that represents a UML model element. The class should have the following features:
1. A unique identifier for each UML element.
2. Methods to add and retrieve stereotypes, behaviors, data types, associations, interfaces, and deployments associated with the UML element.
3. Methods... | Here is the Python code to solve the given problem in the markdown block:
```python
class UMLModelElement:
def __init__(self, unique_id: str):
"""
Initialize a UMLModelElement with a unique identifier.
Args:
unique_id (str): The unique identifier for the UML model element.
... |
magic_instruct_75k | 39,154 | Write a Python function to calculate the distance from the center of a self-driving car to the edge of the track. The track width is defined as the distance between the two edges of the track. The function should take the track width as a parameter and return the distance from the center of the car to the edge of the t... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_distance_to_edge(track_width: float) -> float:
"""
Calculate the distance from the center of a self-driving car to the edge of the track.
The distance is calculated as 10% of the track width and is rounded to ... |
magic_instruct_75k | 39,214 | Write a Python function to verify if a specific parameter, 'number', exists in a request object and has a specific value, '14443332121'. The request object is a dictionary that contains a 'params' key, which maps to another dictionary of parameters. The function should return `True` if the 'number' parameter exists and... | Here is the Python code to solve the given problem in the markdown block:
```python
def callbackMatchesParams(request: dict) -> bool:
"""
Verifies if the 'number' parameter in the request object has the value '14443332121'.
Args:
request (dict): A dictionary containing a 'params' key, which maps to... |
magic_instruct_75k | 39,257 | Write a Python function to implement a custom `split` function that mimics the behavior of the built-in `split` method for strings. The function should take two arguments: a string to be split and a regular expression pattern. The function should return a list of strings obtained by splitting the input string based on ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def custom_split(input_string: str, pattern: str) -> list:
"""
Splits the input string based on the specified regular expression pattern.
Args:
input_string (str): The string to be split.
pattern ... |
magic_instruct_75k | 39,265 | Write a Python function to find and return a list of unique variable names from a given list of variable names. A variable name is considered unique if it appears only once in the original list. The function should be efficient and handle various edge cases, such as an empty list or a list with all elements being dupli... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def findUniqueVariables(varNameList: List[str]) -> List[str]:
"""
Finds and returns a list of unique variable names from a given list of variable names.
A variable name is considered unique if it app... |
magic_instruct_75k | 39,290 | Write a Python function to process a list of tuples representing medical specialties and their corresponding abbreviations. Each tuple contains two elements: the full name of the medical specialty and its abbreviation. The function should return a dictionary where the keys are the abbreviations and the values are lists... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_specialty_dictionary(specialties: List[Tuple[str, str]]) -> Dict[str, List[str]]:
"""
Create a dictionary from a list of tuples representing medical specialties and their abbrevia... |
magic_instruct_75k | 39,326 | Write a Python function to calculate the sum of all elements in a nested list of integers. The function should handle both empty lists and lists containing integers or nested lists of integers. The function should be named `recursive_sum` and should start with:
```python
from typing import List, Union
def recursive_su... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def recursive_sum(arr: Union[List, int]) -> int:
"""
Calculate the sum of all elements in a nested list of integers.
Args:
arr (Union[List, int]): A list of integers or nested lists o... |
magic_instruct_75k | 39,337 | Write a Python function to convert a given duration into seconds. The function should take a dictionary as input, where the keys represent units of time ('seconds', 'minutes', 'hours') and the values represent the respective quantities. The function should return the total duration in seconds.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_seconds(duration: dict) -> int:
"""
Converts a given duration into total seconds.
Args:
duration (dict): A dictionary where keys are units of time ('seconds', 'minutes', 'hours')
... |
magic_instruct_75k | 39,343 | Write a Python function to perform a specific mathematical operation on a given array of integers. The function should take an array of integers as input and return the resulting array after applying the operation to each element.
The operation to be performed is as follows:
For each element in the array, the element ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def performOperation(arr: List[int]) -> List[int]:
"""
Perform a specific mathematical operation on a given array of integers.
The operation to be performed is as follows:
For each element in th... |
magic_instruct_75k | 39,362 | Write a Python function to determine whether a user with a given role has the permission to delete a course in a role-based access control system. The function should take the user's role as input and return a boolean value indicating whether the user has the "course_delete" permission. The roles and their associated p... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_permission(role: str) -> bool:
"""
Determines whether a user with a given role has the permission to delete a course.
Args:
role (str): The role of the user. Possible values are "Admin", "Instructor", and ... |
magic_instruct_75k | 39,392 | Create a Python class `TimeFitStructMap` that stores time fit structures for various labels. The class should have the following features:
1. A method to initialize the map for a specific label and print the label's data to the console.
2. Methods to add a time fit structure, retrieve a time fit structure for a given t... | Here is the Python code to solve the given problem in the markdown block:
```python
class TimeFitStructMap:
def __init__(self, label: str):
"""
Initialize the TimeFitStructMap for a specific label and print the label's data to the console.
Args:
label (str): The label for which ... |
magic_instruct_75k | 39,403 | Write a Bash script that automates the installation and setup of Elasticsearch version 1.7.6 on various servers. The script should:
1. Set the version of Elasticsearch to be installed as 1.7.6.
2. Construct the URL for downloading the Elasticsearch tarball using the version information.
3. Create the necessary director... | Here is the Python code to solve the given problem in the markdown block:
```bash
#!/bin/bash
# Set the version of Elasticsearch to be installed
VERSION="1.7.6"
# Construct the URL for downloading the Elasticsearch tarball
FILE_BASE="elasticsearch-$VERSION.tar.gz"
FILE_URL="https://download.elastic.co/elasticsearch/e... |
magic_instruct_75k | 39,418 | Write a Python function to simulate a simple vending machine. The vending machine has a set list of items with corresponding prices and initial stock quantities. The user will input money and select an item to purchase. The function should then calculate the change to return to the user and update the stock of the item... | Here is the Python code to solve the given problem in the markdown block:
```python
def vending_machine(item: str, money_inserted: float) -> str:
"""
Simulates a simple vending machine transaction.
Args:
item (str): The item the user wants to purchase.
money_inserted (float): The amount of ... |
magic_instruct_75k | 39,432 | Write a Python function to calculate the sum of the digits of a given integer. The function should handle both positive and negative integers. The code should start with:
```python
def digit_sum(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def digit_sum(n: int) -> int:
"""
Calculate the sum of the digits of a given integer.
Args:
n (int): The integer whose digits are to be summed.
Returns:
int: The sum of the digits of the given integer.
... |
magic_instruct_75k | 39,449 | Write a Python function to sort a dictionary of coordinates where the keys are x-coordinates and the values are y-coordinates. The function should return two lists: one containing the sorted x-coordinates and the other containing the corresponding y-coordinates.
The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def sort_coordinates(coordinates_dict: Dict[int, int]) -> Tuple[List[int], List[int]]:
"""
Sorts a dictionary of coordinates where the keys are x-coordinates and the values are y-coordinates... |
magic_instruct_75k | 39,458 | Write a Python function to center 3D pose data around the root (center hip) joint. The function should take a dictionary `poses_set` containing 3D pose data, where the keys are joint names and the values are tuples representing 3D coordinates. The function should return the modified `poses_set` dictionary with the data... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def center_poses(poses_set: Dict[str, Tuple[float, float, float]]) -> Tuple[Dict[str, Tuple[float, float, float]], Dict[str, Tuple[float, float, float]]]:
"""
Center the 3D pose data around the ro... |
magic_instruct_75k | 39,471 | Write a Python function to validate whether a given dictionary matches a specified pattern. The pattern is represented by another dictionary, where the keys represent the expected keys in the input dictionary, and the values represent the expected value types for those keys. The function should return `True` if the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
def validate_pattern(pattern: dict, input_dict: dict) -> bool:
"""
Validates whether the input dictionary matches the specified pattern.
Args:
pattern (dict): A dictionary representing the expected pattern, where th... |
magic_instruct_75k | 39,478 | Write a Python function `process_access_level(val: List[Union[str, Union[int, str]]]) -> Union[str, int]` that processes and validates input data related to access levels for different users. The function should take a list `val` as input, where `val[1]` is a string representing a username and `val[2]` is the access le... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
ACCESS_LEVELS = {
1: 'admin',
2: 'moderator',
3: 'user'
}
def process_access_level(val: List[Union[str, Union[int, str]]]) -> Union[str, int]:
"""
Processes and validates input data r... |
magic_instruct_75k | 39,482 | Implement a Python class `SubscriptionManager` that manages a list of `Subscription` objects. The `SubscriptionManager` class should have methods to add, remove, and retrieve subscriptions. Each `Subscription` object should have an `id` and a `service` name.
The code should start with:
```python
class Subscription:
... | Here is the Python code to solve the given problem in the markdown block:
```python
class Subscription:
def __init__(self, id: int, service: str):
"""
Initialize a Subscription object with an id and a service name.
Args:
id (int): A unique identifier for the subscription.
... |
magic_instruct_75k | 39,491 | Create a Python class `DatasetManager` that manages datasets for a machine learning project. The class should provide functionality for adding, removing, and listing datasets, as well as for checking if a dataset exists. Additionally, the class should ensure that dataset names are unique and follow a specific naming co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
class DatasetManager:
def __init__(self):
"""
Initialize an empty list to store dataset names.
"""
self.datasets = []
def add_dataset(self, name: str) -> bool:
... |
magic_instruct_75k | 39,537 | Write a Python function to filter a list of image dataset names based on specific criteria. The function should take a list of image dataset names as input and return a filtered list based on the following conditions:
1. The dataset name should not start with a dot (`.`).
2. The dataset name should not end with a numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_image_datasets(dataset_names: List[str]) -> List[str]:
"""
Filters a list of image dataset names based on specific criteria.
Args:
dataset_names (List[str]): A list of image datas... |
magic_instruct_75k | 39,600 | Create a Python class `FriendManager` that manages friend presence and profile information in a social networking application. Implement a method `DisplayProfileImage` that retrieves and displays the profile image of a friend given their ID. The method should use the `GetProfileImage` method to retrieve the profile ima... | Here is the Python code to solve the given problem in the markdown block:
```python
class FriendManager:
"""
A class to manage friend presence and profile information in a social networking application.
Methods:
DisplayProfileImage(friend_id: int) -> None:
Retrieves and displays the pro... |
magic_instruct_75k | 39,674 | Write a Python function to generate the string representation of a function's signature. The function should take the function name and its parameters as input and return the function's signature as a string. The signature should be in the format "function_name(param1, param2, ...)". If the function has no parameters, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_signature(function_name: str, parameters: List[str]) -> str:
"""
Generates the string representation of a function's signature.
Args:
function_name (str): The name of the functi... |
magic_instruct_75k | 39,683 | Write a Python function `process_text_corpus` that processes a text corpus obtained from a file. The function should perform the following operations:
1. Read the text content from a file using a provided function `get_text_from_file`.
2. Convert all the text to lowercase.
3. Tokenize the text into individual words, re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Callable
import re
from collections import defaultdict
def process_text_corpus(get_text_from_file: Callable[[str], str], file_path: str) -> Dict[str, int]:
"""
Processes a text corpus from a file and re... |
magic_instruct_75k | 39,686 | Implement a Python function `merge_sort` that sorts a given list of integers using the merge sort algorithm. The function should return the sorted list in ascending order. Additionally, ensure that the sorted list obtained from `merge_sort` matches the result obtained from the built-in `sorted` function.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the merge sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.