source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_instruct_75k | 43,620 | Write a Python function `calculate_confidence(insight_model_data)` that processes data from an insight model and calculates the confidence level based on the explicit score. The function should handle potential attribute errors and return the confidence level using a specific confidence method. If the `explicit_score` ... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_confidence(insight_model_data):
"""
Calculate the confidence level based on the explicit score from the insight model data.
Args:
insight_model_data: An object containing the data from the insight mode... |
magic_instruct_75k | 43,622 | Write a Python function to calculate a 3D tensor representing the number of objects in each cell of a grid. The grid is divided into cells, and each cell contains a certain number of boxes. The function should take the dimensions of the grid and the number of boxes per cell as input and return the 3D tensor representin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_tensor(cell_size: int, boxes_per_cell: int) -> List[List[List[int]]]:
"""
Calculate a 3D tensor representing the number of objects in each cell of a grid.
Args:
cell_size (int)... |
magic_instruct_75k | 43,628 | Write a Python function to merge two dictionaries, prioritizing the values from the second dictionary in case of key conflicts. The function should take two dictionaries as input and return a new dictionary with the merged key-value pairs. The code should start with:
```python
from typing import Dict
def merge_dicts(d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Merges two dictionaries, prioritizing the values from the second dictionary in case of key conflicts.
Args:
dict1 (Dict): The first dic... |
magic_instruct_75k | 43,639 | Write a Python function to find the column names in a list of database column definitions that match a specified data type. Each column definition is represented as a dictionary with keys "name" for the column name and "type" for the data type. The function should return a list of column names that have the specified d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union, Any
def find_columns_by_type(column_definitions: List[Dict[str, Union[str, Any]]], data_type: str) -> List[str]:
"""
Find the column names in a list of database column definitions that matc... |
magic_instruct_75k | 43,649 | Write a Python function to generate a dictionary that maps each student's score to their corresponding grade based on predefined grading criteria. The function should take a list of integers representing the scores of students and return a dictionary where the keys are the scores and the values are the corresponding gr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_grade_dict(scores: List[int]) -> Dict[int, str]:
"""
Generates a dictionary that maps each student's score to their corresponding grade.
Args:
scores (List[int]): A list o... |
magic_instruct_75k | 43,655 | Write a Python function to find the maximum profit that can be obtained by buying and selling a stock at most once. The function should take a list of integers representing the stock prices over a period of time and return the maximum profit. If no profit can be made, the function should return 0.
The code should star... | 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 buying and selling a stock at most once.
Args:
prices (List[int]): A list of integers repre... |
magic_instruct_75k | 43,667 | Write a Python function to count the number of walls in a given 2D grid. Each '#' character in the grid represents a wall, and each '.' character represents an open space. The function should take a list of strings as input, where each string represents a row in the grid, and return the total number of walls present in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_walls(grid: List[str]) -> int:
"""
Count the number of walls in a given 2D grid.
Args:
grid (List[str]): A list of strings where each string represents a row in the grid.
... |
magic_instruct_75k | 43,670 | Write a Python function to modify CSS styles based on a given set of rules. The function should take in a list of style dictionaries and return a new list with modified styles. Each style dictionary contains key-value pairs representing CSS properties and their values.
You need to implement the function `modify_styles... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def modify_styles(styles: List[Dict[str, str]]) -> List[Dict[str, str]]:
"""
Modifies CSS styles based on specific rules.
Args:
styles (List[Dict[str, str]]): A list of style dictionar... |
magic_instruct_75k | 43,677 | Write a Python function to extract specific metadata from a given configuration dictionary representing a Python package. The function should return a dictionary containing the following metadata:
- Version
- Author
- Author Email
- Description
- License
The function should handle cases where the input dictionary may ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def extract_metadata(config: Dict[str, Any]) -> Dict[str, Any]:
"""
Extracts specific metadata from a given configuration dictionary representing a Python package.
Args:
config (Dict[st... |
magic_instruct_75k | 43,775 | Write a Python script to automate the removal of files with names ending in "-e" within a specified directory and its subdirectories. The script should traverse through the directory structure, identify and delete all such files, and provide appropriate feedback to the user during its execution.
The script should star... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
def remove_files_ending_with_e(directory_path: str) -> None:
"""
Removes all files with names ending in "-e" from the specified directory and its subdirectories.
Args:
directory_path (str): The path to th... |
magic_instruct_75k | 43,788 | Write a Python function to determine whether a given integer `n` is a happy number. A happy number is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endle... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_happy_number(n: int) -> bool:
"""
Determine whether a given integer `n` is a happy number.
A happy number is defined by the following process: Starting with any positive integer,
replace the number by the sum of ... |
magic_instruct_75k | 43,798 | Write a Python function to process a sequence of tokens and update an incremental state based on the previous output tokens. The function should handle different types of tokens and update the incremental state accordingly. The function should start with:
```python
from typing import List, Any, Optional
def process_to... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Optional
def process_tokens(prev_output_tokens: List[Any], incremental_state: Optional[dict] = None) -> dict:
"""
Processes a sequence of tokens and updates an incremental state based on the previo... |
magic_instruct_75k | 43,826 | Create a Python function to manage a simple linked list data structure. The linked list should support basic operations such as insertion at the beginning, deletion of a node with a given value, and traversal to print its elements. The function should be implemented in a way that ensures the correctness of the linked l... | Here is the Python code to solve the given problem in the markdown block:
```python
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def insert_at_beginning(self, data):
"""
Inserts a new ... |
magic_instruct_75k | 43,833 | Write a Python function to count the occurrences of each unique action related to 'Reproduction' transactions from a list of transactions. Each transaction is represented as a dictionary with a 'label' and 'items' key. The 'label' key holds a string representing the type of transaction, and the 'items' key holds a list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_reproduction_actions(transactions: List[Dict[str, List[str]]]) -> Dict[str, int]:
"""
Counts the occurrences of each unique action related to 'Reproduction' transactions.
Args:
... |
magic_instruct_75k | 43,837 | Write a Python function `get_thermo_property(input_type)` that takes a string `input_type` as input and returns the corresponding thermodynamic property. The input types and their corresponding thermodynamic properties are as follows:
- `PT_INPUTS`: Pressure and Temperature
- `DmassT_INPUTS`: Density and Temperature fo... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_thermo_property(input_type: str) -> str:
"""
Returns the corresponding thermodynamic property for the given input type.
Args:
input_type (str): The input type for which the thermodynamic property is to be re... |
magic_instruct_75k | 43,857 | Write a Python function to process a sequence of operations in a neural network according to specific rules. The sequence is represented as a string where each operation is associated with a block number and separated by "=>". The function should modify the sequence based on the following rules:
- Replace "FIRE" with "... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_sequence(sequence: str) -> str:
"""
Processes a sequence of operations in a neural network according to predefined rules.
Args:
sequence (str): The input sequence of operations, formatted as "Block #X-Y:... |
magic_instruct_75k | 43,859 | Write a Python function to find the mode of a given list of integers. The mode is the element that appears most frequently in the list. If there are multiple modes, the function should return the smallest mode. If the list is empty, the function should return `None`.
The function signature is:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_mode(arr: List[int]) -> Optional[int]:
"""
Find the mode of a given list of integers. The mode is the element that appears most frequently.
If there are multiple modes, the functio... |
magic_instruct_75k | 43,860 | Write a Python function to process a list of pre-configured hooks for a software deployment system. Each hook is represented as a string and can have one of the following forms:
1. `"forceLinkCoreFoundationFramework"`: Indicates that the CoreFoundation framework should be forcefully linked during the deployment process... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def process_hooks(preConfigureHooks: List[str]) -> Dict[str, Union[bool, List[str]]]:
"""
Processes a list of pre-configured hooks for a software deployment system.
Args:
preCon... |
magic_instruct_75k | 43,870 | Create a Python function to handle the form submission for toggling the attendance status of a user for a specific event. The function should extract the attendance status from the request, validate the input, and store the status in a dictionary that simulates a database. The function should return a confirmation mess... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def toggle_attendance(request: Dict[str, Union[str, int]], db: Dict[int, Dict[str, Union[int, str]]]) -> str:
"""
Handles the form submission for toggling the attendance status of a user for a spe... |
magic_instruct_75k | 43,896 | Write a Python function to count the number of unique media types associated with each product category. The function should take a list of tuples as input, where each tuple contains a product category name and a list of associated media types. The function should return a dictionary where the keys are the product cate... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def count_unique_media_types(categories: List[Tuple[str, List[str]]]) -> Dict[str, int]:
"""
Counts the number of unique media types associated with each product category.
Args:
... |
magic_instruct_75k | 43,905 | Write a Python function to analyze a given software license text and count the occurrences of specific keywords related to permissions and limitations. The function should be case-insensitive and return a dictionary with the counts of each keyword.
The keywords to be counted are:
- "software"
- "warranties"
- "conditi... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_license_keywords(license_text: str) -> dict:
"""
Analyzes a given software license text and counts the occurrences of specific keywords related to permissions and limitations.
Args:
license_text (str): The... |
magic_instruct_75k | 43,922 | Write a Python function to process command-line arguments and execute the appropriate function based on the provided arguments. The function should support the following functionalities:
1. If no arguments are provided, the function should display a message indicating that no arguments were given.
2. If the argument "h... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_arguments(args: List[str]) -> None:
"""
Processes command-line arguments and executes the appropriate function based on the provided arguments.
Args:
args (List[str]): A list of ... |
magic_instruct_75k | 43,923 | Write a Python function to calculate the total frequencies of each word from a list of tuples, where each tuple contains a string representing a word and an integer representing its frequency. The function should return a dictionary where the keys are the words and the values are the total frequencies of each word acro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def calculate_word_frequencies(word_tuples: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Calculate the total frequencies of each word from a list of tuples.
Args:
word_tuples (... |
magic_instruct_75k | 43,942 | Write a Python function to convert ground coordinates to image coordinates using a given model. The ground coordinates are represented by a tuple of three values (longitude, latitude, altitude), and the image coordinates are represented by a tuple of three values (x, y, z). The model used for the conversion is provided... | Here is the Python code to solve the given problem in the markdown block:
```python
def ground_to_image(model, ground):
"""
Converts ground coordinates to image coordinates using a given model.
Args:
model: An object that has a method `groundToImage` which converts ground coordinates to image coord... |
magic_instruct_75k | 43,947 | Write a Python function to automate the installation of required Python packages for a machine learning project using `pip`. The function should upgrade `pip` to the latest version and then install a list of specified packages. The function should simulate the installation process by printing the commands that would be... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def install_packages(packages: List[str]) -> None:
"""
Simulates the process of upgrading pip and installing a list of specified Python packages.
Args:
packages (List[str]): A list of packag... |
magic_instruct_75k | 43,956 | Implement a `Node` class that represents a hierarchical structure in a software application. Each node can have zero or more child nodes. The class should have the following properties and methods:
- Properties:
- `position`: a tuple representing the current position of the node in a 2D space.
- `children`: a list ... | Here is the Python code to solve the given problem in the markdown block:
```python
class Node:
def __init__(self, position: tuple):
"""
Initialize a Node with a given position and an empty list of children.
Args:
position (tuple): A tuple representing the initial position of th... |
magic_instruct_75k | 43,960 | Write a Python function to handle errors in a serialization library. The function should take in a dictionary containing error information and return a dictionary with the error details, including an optional name associated with the error. The function should validate the input dictionary and ensure that it contains t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def handle_error(error_info: Dict[str, str]) -> Dict[str, Optional[str]]:
"""
Handle errors in a serialization library by processing the provided error information.
Args:
error_inf... |
magic_instruct_75k | 43,982 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down.
The code should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
magic_instruct_75k | 43,988 | Write a Python function to calculate the sum of the absolute values of positive integers from a given list, while skipping any negative numbers. The function should take a list of integers as input and return an integer representing the sum of the absolute values of the positive numbers.
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 sum_positive_abs(numbers: List[int]) -> int:
"""
Calculate the sum of the absolute values of positive integers from a given list, skipping any negative numbers.
Args:
numbers (List[int])... |
magic_instruct_75k | 44,006 | Write a Python function to analyze network bridge data. The function should take a dictionary representing a network bridge configuration as input and return the following information:
- The total number of BPDUs (Bridge Protocol Data Units) sent and received.
- The MAC address of the designated bridge.
- The port ID o... | Here is the Python code to solve the given problem in the markdown block:
```python
def analyze_bridge_data(bridge_data):
"""
Analyzes the network bridge data and returns the total number of BPDUs sent and received,
the designated bridge's MAC address, port ID, and priority, and the designated root bridge's... |
magic_instruct_75k | 44,037 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
magic_instruct_75k | 44,048 | Write a Python function to calculate the average score of a game, excluding the highest and lowest scores from the given list of scores. The function should handle lists with at least two scores and ensure the average is rounded to two decimal places.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average_score(scores: List[int]) -> float:
"""
Calculate the average score of a game, excluding the highest and lowest scores.
Args:
scores (List[int]): A list of non-negative ... |
magic_instruct_75k | 44,049 | Write a Python function to count the occurrences of each unique symbol in a given list of symbols. If the input list is empty, the function should raise a `ValueError` with the message "Input list cannot be empty." The function should return a dictionary where the keys are the unique symbols and the values are the coun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_symbols(symbols: List[str]) -> Dict[str, int]:
"""
Counts the occurrences of each unique symbol in the given list of symbols.
Args:
symbols (List[str]): A list of symbols to ... |
magic_instruct_75k | 44,057 | Write a Python function to generate a summary report from a given table. The table is represented as a list of rows, where each row is a tuple containing a string representing the row heading and a list of tuples representing the column values. Each column tuple consists of a string column heading and a numerical value... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_summary_report(table: List[Tuple[str, List[Tuple[str, float]]]]) -> str:
"""
Generates a summary report from a given table.
The table is represented as a list of rows, where each... |
magic_instruct_75k | 44,072 | Write a Python function `format_dict` that takes a dictionary `call_spec` as input and returns a string representation of its key-value pairs in the format "(key1=value1, key2=value2, ...)". The keys should be sorted in lexicographical order. The function should adhere to the following constraints:
- The keys in the in... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_dict(call_spec: dict) -> str:
"""
Formats a dictionary into a string representation of its key-value pairs in the format "(key1=value1, key2=value2, ...)".
The keys are sorted in lexicographical order.
Args:
... |
magic_instruct_75k | 44,084 | Write a Python function to process a signal efficiently using a nested loop. The `signal` is a list of integers, and the `getMultiplier` function takes two integer arguments and returns a multiplier. The `size` variable represents the length of the `signal` list. The inner loop calculates a new signal by multiplying ea... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def getMultiplier(i: int, j: int) -> int:
"""
Returns a multiplier based on the given indices.
Args:
i (int): The first index.
j (int): The second index.
Returns:
int: 1... |
magic_instruct_75k | 44,133 | Write a Python function to parse and analyze a series of movement commands for a robotic system. The movement commands are represented as strings in the format "component:action", where "component" is the specific part of the robot (e.g., left_leg, left_foot) and "action" is the type of movement (e.g., crx, cry, crz, c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def parse_movement_commands(commands: List[str]) -> Dict[str, Dict[str, int]]:
"""
Parses a list of movement commands and returns a dictionary containing the count of each unique movement action fo... |
magic_instruct_75k | 44,138 | Write a Python function to calculate the speed improvement achieved by optimizing the processing time of a video frame. The function should take the time taken for one frame before optimization as input and return a string indicating the speed improvement in the format "X times faster than real", where X is the speed i... | Here is the Python code to solve the given problem in the markdown block:
```python
def speed_improvement(time_taken_per_frame: float) -> str:
"""
Calculate the speed improvement achieved by optimizing the processing time of a video frame.
Args:
time_taken_per_frame (float): The time taken for one ... |
magic_instruct_75k | 44,142 | Write a Python function to calculate the total cost of a customer's order from an online store. The function should take into account the base price of the items, any applicable discounts, and shipping costs. The function should handle different types of discounts, such as percentage-based discounts and fixed amount di... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_cost(base_price: float, discount_type: str, discount_value: float, shipping_cost: float) -> float:
"""
Calculate the total cost of an order after applying a discount and adding shipping costs.
Args:
... |
magic_instruct_75k | 44,146 | Write a Python function to simulate the movement of a target character in a 2D game. The target character should move randomly within a specified rectangular game area to avoid being caught by a monster. The function should take the current position of the target character and the boundaries of the game area as inputs ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import random
def move_target(current_position: Tuple[float, float], min_x: float, min_y: float, max_x: float, max_y: float) -> Tuple[float, float]:
"""
Simulate the movement of a target character in a ... |
magic_instruct_75k | 44,156 | Write a Python function to calculate the total number of ways to reach the top of a staircase where you can climb either 1 or 2 steps at a time. The function should take the number of steps in the staircase as input and return the total number of distinct ways to reach the top. The function should be named `count_ways_... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_ways_to_reach_top(n: int) -> int:
"""
Calculate the total number of ways to reach the top of a staircase with `n` steps,
where you can climb either 1 or 2 steps at a time.
Args:
n (int): The number of ... |
magic_instruct_75k | 44,161 | Write a Python function to simulate the behavior of a subsystem responsible for controlling the lifting mechanism of a robotic vehicle. The subsystem, named `drivelift`, has four functions: `extendFront()`, `retractFront()`, `extendBack()`, and `retractBack()`. Additionally, there are two boolean variables, `frontLiftT... | Here is the Python code to solve the given problem in the markdown block:
```python
def simulate_lift_control(frontLiftToggle: bool, backLiftToggle: bool) -> list:
"""
Simulate the behavior of the drivelift subsystem based on the given boolean toggles.
Args:
frontLiftToggle (bool): Determines wheth... |
magic_instruct_75k | 44,185 | Write a Python function to find all document names in a document management system dictionary that have a specified prefix. The dictionary represents the document management system, where the keys are the document names and the values are the corresponding document metadata. The function should return a list of documen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def find_documents_with_prefix(dms: Dict[str, str], prefix: str) -> List[str]:
"""
Find all document names in a document management system dictionary that have a specified prefix.
Args:
... |
magic_instruct_75k | 44,195 | Write a Python function to transform a list of integers according to the following rules:
1. If the integer is even, it should be divided by 2.
2. If the integer is odd, it should be multiplied by 3 and then increased by 1.
The function should take a list of integers as input and return a new list with the specified t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_list(nums: List[int]) -> List[int]:
"""
Transforms a list of integers according to the following rules:
- If the integer is even, it is divided by 2.
- If the integer is odd, it is ... |
magic_instruct_75k | 44,198 | Write a Python function to process an image by applying a specific operation. The function should have an optional parameter to determine whether the input image should be copied or modified in place. The function should support two operations: "grayscale" and "invert". If the "grayscale" operation is selected, the fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_image(image: List[List[int]], operation: str, copy: bool = False) -> List[List[int]]:
"""
Processes an image by applying a specified operation. The function can either copy the input image or... |
magic_instruct_75k | 44,201 | Write a Python function to count the major versions of required Python packages from a given list. Each package is represented as a string in the format "package_name>=version_number". The major version is considered to be the first digit in the version number. If a package does not specify a version, it should be coun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_package_versions(packages: List[str]) -> Dict[int, int]:
"""
Counts the major versions of required Python packages from a given list.
Args:
packages (List[str]): A list of st... |
magic_instruct_75k | 44,212 | Write a Python function `parse_router_log(log: str) -> dict` that takes a string `log` as input, representing the router log, and returns a dictionary containing the extracted information. The log will be formatted as shown in the code snippet provided.
The log will contain the following information:
- Uptime in the f... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def parse_router_log(log: str) -> dict:
"""
Parses a Cisco router's system log and extracts relevant information.
Args:
log (str): The router log as a string.
Returns:
dict: A dictionary cont... |
magic_instruct_75k | 44,235 | Write a Python function to sort an array of integers in non-decreasing order using a specific sorting algorithm. The sorting algorithm works as follows:
1. Find the minimum value in the array.
2. Swap the minimum value with the first element of the array.
3. Repeat the above steps for the subarray starting from the sec... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_sort(arr: List[int]) -> List[int]:
"""
Sorts the given array of integers in non-decreasing order using a selection sort algorithm.
Args:
arr (List[int]): The array of integers to ... |
magic_instruct_75k | 44,261 | Write a Python function to find the starting positions of all occurrences of a specific pattern within a DNA sequence. The DNA sequence is represented as a string containing only the characters 'A', 'C', 'G', and 'T'. The pattern is a substring of a given length `w`. The function should return a list of starting positi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_pattern_positions(seq: str, w: int, pattern: str) -> List[int]:
"""
Finds the starting positions of all occurrences of a specific pattern within a DNA sequence.
Args:
seq (str): The... |
magic_instruct_75k | 44,288 | Write a Python function to generate an HTML button for a note with a given title and URL. The button should be wrapped in an anchor tag (`<a>`) and should have a specific class and icon. The function should return the HTML string representing the button.
The code should start with:
```python
def generateNoteButton(tit... | Here is the Python code to solve the given problem in the markdown block:
```python
def generateNoteButton(title: str, url: str) -> str:
"""
Generates an HTML button for a note with the given title and URL.
Args:
title (str): The title of the note.
url (str): The URL associated with the not... |
magic_instruct_75k | 44,296 | Write a Python function to format and display a table of student names and their corresponding scores. The function should align the student names to the left with a width of 15 characters and the scores to the right with a width of 5 characters. The table should have a header row that labels the columns as "Student" a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def display_student_scores(students: List[Tuple[str, int]]) -> None:
"""
Formats and displays a table of student names and their corresponding scores.
Args:
students (List[Tuple[str, ... |
magic_instruct_75k | 44,324 | Write a Python function to remove all occurrences of a specific value from a given list of integers. The function should return the modified list after the removal operation. The code should start with:
```python
from typing import List
def remove_value(input_list: List[int], value_to_remove: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_value(input_list: List[int], value_to_remove: int) -> List[int]:
"""
Removes all occurrences of a specific value from a given list of integers.
Args:
input_list (List[int]): The l... |
magic_instruct_75k | 44,360 | Write a Python function to generate an HTML report that contains links to open associated PDF documents for a list of bookings. Each booking object has a `file_document` attribute that holds the path to the corresponding PDF file. The function should take the list of bookings as input and produce a string containing th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_html_report(bookings: List[Dict[str, str]]) -> str:
"""
Generates an HTML report containing links to open associated PDF documents for a list of bookings.
Args:
bookings (... |
magic_instruct_75k | 44,369 | Write a Python function to filter the indices of input data based on their size and optional parameters. The function should perform the following steps:
1. If `max_positions` is provided, filter the indices to include only those whose input data size does not exceed `max_positions`.
2. If `ignore_invalid_inputs` is se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def filter_indices_by_size(indices: List[int], dataset: List[Optional[str]], max_positions: Optional[int] = None, ignore_invalid_inputs: bool = False) -> List[int]:
"""
Filters the indices of t... |
magic_instruct_75k | 44,384 | Write a Python function `process_data` that processes a set of variables and a dictionary containing question state data. The function should perform the following operations:
1. Add a specific string "_added" to each variable in the input set.
2. Modify the input dictionary by adding the length of each value list to t... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_data(variables: set, question_state_dict: dict) -> tuple:
"""
Processes a set of variables and a dictionary containing question state data.
Args:
variables (set): A set of variables (strings) representin... |
magic_instruct_75k | 44,418 | Write a Python function to find the maximum sum of a contiguous subarray within a given list of integers. The function should efficiently compute the maximum sum using an optimal algorithm.
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 | 44,434 | Write a Python function to simulate a simple container management system. The function should take a container name as input and return a tuple containing a dictionary of metadata and the container's content. The metadata dictionary should include information such as content length, object count, bytes used, timestamp,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def container_resp(container_name: str) -> Tuple[Dict[str, str], str]:
"""
Simulates a simple container management system by returning a tuple containing
a dictionary of metadata and the conte... |
magic_instruct_75k | 44,441 | Write a Python function to convert a given Roman numeral string to its corresponding integer value. The Roman numeral is represented by seven different symbols: I, V, X, L, C, D, and M, with corresponding values 1, 5, 10, 50, 100, 500, and 1000 respectively. There are specific cases where a smaller numeral precedes a l... | Here is the Python code to solve the given problem in the markdown block:
```python
def roman_to_int(roman: str) -> int:
"""
Converts a Roman numeral string to its corresponding integer value.
Args:
roman (str): A string representing a valid Roman numeral.
Returns:
int: The integer val... |
magic_instruct_75k | 44,448 | Write a Python function to parse a list of tool and version specifications into a dictionary. Each specification in the list is a string in the format "tool:version". The function should handle invalid input gracefully and return an empty dictionary if the input is invalid.
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, Dict
def parse_tool_versions(specs: List[str]) -> Dict[str, str]:
"""
Parse a list of tool and version specifications into a dictionary.
Args:
specs (List[str]): A list of strings where eac... |
magic_instruct_75k | 44,452 | Write a Python function to implement a Redux reducer that manages the state of selected mages in a fantasy-themed application. The state is represented as a dictionary with a `mageIds` list. The reducer should handle a `toggleMage` action, which toggles the selection of a mage in the `mageIds` list. Additionally, the r... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any, Callable
# Define the setToDb function
def setToDb(key: str, mage_ids: List[int]) -> None:
"""
Simulates saving the list of mage IDs to a database.
Args:
key (str): The key to id... |
magic_instruct_75k | 44,472 | Write a Python function to calculate the final price of a product after applying a discount. The function should take the current price of the product and the discount percentage as input, and then calculate and return the new price after the discount has been applied. The function should handle cases where the discoun... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_discounted_price(current_price: float, discount_percentage: float) -> float:
"""
Calculate the final price of a product after applying a discount.
Args:
current_price (float): The current price of the ... |
magic_instruct_75k | 44,514 | Implement a method `countPointsInType` for the `UnitCellLattice` class that counts the number of points of a specific type within the lattice. The method should utilize the existing methods and properties of the `UnitCellLattice` class to achieve this.
The `UnitCellLattice` class has the following relevant methods and... | Here is the Python code to solve the given problem in the markdown block:
```python
class UnitCellLattice:
def __init__(self, size, points):
self.size = size
self.points = points
self.IAD = 1.0 # Example interatomic distance
def applyTransF(self, TransF):
# Placeholder for tran... |
magic_instruct_75k | 44,519 | Write a Python function to clip the values of a given array to a specified range. The function should take an input array, a minimum value, and a maximum value, and then clip the values of the array to fall within the specified range. The clipped array should be returned as the output. The function should be implemente... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clip_to_range(arr: List[float], min_val: float, max_val: float) -> List[float]:
"""
Clips the values of a given array to a specified range.
Args:
arr (List[float]): The input array whose... |
magic_instruct_75k | 44,525 | Write a Python function to group a list of transactions by their cart ID. Each transaction is represented as a dictionary with the following keys: "cart_id", "product_id", and "quantity". The function should take a list of transactions as input and return a dictionary where the keys are the unique cart IDs and the valu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def group_transactions(transactions: List[Dict[str, Any]]) -> Dict[int, List[Dict[str, Any]]]:
"""
Groups a list of transactions by their cart ID.
Args:
transactions (List[Dict[st... |
magic_instruct_75k | 44,527 | Write a Python function to calculate the total energy produced by a nuclear reaction based on the amount of powder units used and the energy produced per unit. The energy produced is measured in kiloelectronvolts (keV). The function should take two parameters:
- `powder_units`: an integer representing the amount of pow... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_energy(powder_units: int, energy_kev: float) -> str:
"""
Calculate the total energy produced by a nuclear reaction based on the amount of powder units used and the energy produced per unit.
Args:
powde... |
magic_instruct_75k | 44,529 | Write a Python function to process a list of event dictionaries and extract specific attributes from each event. The function should return a modified list where each event dictionary contains the 'name' attribute with the first letter capitalized and the 'date' attribute converted to a human-readable format in the for... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
from datetime import datetime
def process_events(eventos: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
"""
Processes a list of event dictionaries and extracts specific attributes.
Args:... |
magic_instruct_75k | 44,542 | Write a Python function to calculate the sum of the squares of all the even numbers in a given list. The function should take a list of integers as input and return the sum of the squares of all the even numbers in the list.
The code should start with:
```python
from typing import List
def sum_of_squares_of_even_numb... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares_of_even_numbers(arr: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
arr (List[int]): A list of integers.
Returns... |
magic_instruct_75k | 44,550 | Write a Python function to find the first negative value in a given list of integers and return it. If there are no negative values in the list, the function should return 0. The function should be efficient and handle edge cases such as an empty list or a list with no negative values.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def first_negative(values: List[int]) -> int:
"""
Find and return the first negative value in the given list of integers.
If no negative value is found, return 0.
Args:
values (List[int]... |
magic_instruct_75k | 44,551 | Write a Python function to parse and extract specific information from a VCF (Variant Call Format) file. The function should read a VCF file named "input.vcf" and extract the following information:
1. The number of variants in the VCF file.
2. The chromosome, position, reference allele, and alternate allele for each va... | Here is the Python code to solve the given problem in the markdown block:
```python
def parse_vcf_file(file_path: str) -> None:
"""
Parses a VCF file and extracts the number of variants and the chromosome, position, reference allele, and alternate allele for each variant.
Args:
file_path (str): The... |
magic_instruct_75k | 44,568 | Write a Python function to simulate a simple game of dice. The function should generate two random numbers between 1 and 6, representing the outcomes of two dice rolls. The sum of the two numbers should be calculated and returned along with the individual outcomes of each dice roll. The function should return a tuple c... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def roll_dice() -> tuple:
"""
Simulates a simple game of dice by rolling two dice and returning their outcomes and the sum.
Returns:
tuple: A tuple containing the outcomes of the two dice rolls and th... |
magic_instruct_75k | 44,582 | Write a Python function to validate a given string based on a set of rules. The function should return `True` if the string meets all the specified criteria, and `False` otherwise.
The rules for validating the string are as follows:
1. The string must contain at least one uppercase letter.
2. The string must contain a... | Here is the Python code to solve the given problem in the markdown block:
```python
def validate_string(s: str) -> bool:
"""
Validates a string based on the following rules:
1. The string must contain at least one uppercase letter.
2. The string must contain at least one lowercase letter.
3. The str... |
magic_instruct_75k | 44,588 | Write a Python function to modify a given string based on specific rules. The input string consists of lowercase letters and underscores only. The function should perform the following modifications:
1. Replace all occurrences of the substring "clan" with "group".
2. Replace all occurrences of the substring "cells" wit... | Here is the Python code to solve the given problem in the markdown block:
```python
def modify_string(input_str: str) -> str:
"""
Modify the input string based on specific rules.
Args:
input_str (str): The input string consisting of lowercase letters and underscores.
Returns:
str: The ... |
magic_instruct_75k | 44,594 | Write a Python function to calculate the right-hand side (rhs) of a differential equation representing the utilization of lithium metal at the electrode interface for a lithium-ion battery simulation. The function should determine the appropriate parameter based on the domain ("Negative" or "Positive") and use the prov... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_utilization_rhs(domain: str, variables: dict, param) -> float:
"""
Calculate the right-hand side (rhs) of a differential equation representing the utilization of lithium metal at the electrode interface.
Args:... |
magic_instruct_75k | 44,597 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. An increasing subsequence is a subsequence in wh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(p: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence in the given list of integers.
Args:
p (List[int]): The list of intege... |
magic_instruct_75k | 44,620 | Write a Python function to generate a new unique tag ID for a content management system. The function should take the latest tag ID as a string and return the next unique tag ID as an integer. The new tag ID should be one greater than the integer value of the latest tag ID.
The code should start with:
```python
def ge... | Here is the Python code to solve the given problem in the markdown block:
```python
def generateTagID(latestTagID: str) -> int:
"""
Generates a new unique tag ID by incrementing the integer value of the latest tag ID.
Args:
latestTagID (str): The latest tag ID as a string.
Returns:
int... |
magic_instruct_75k | 44,624 | Write a Python function to validate a configuration file for a proxy server. The configuration file is represented by a dictionary with the following keys:
- `address`: a string representing the server address
- `port`: an integer representing the server port
- `proxies`: a list of dictionaries, each containing details... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Optional
def validate_config(config: Dict) -> bool:
"""
Validate a configuration file for a proxy server.
Args:
config (dict): A dictionary representing the configuration file with th... |
magic_instruct_75k | 44,652 | Write a Python function to generate a table of contents for a series of pages in a document based on a given input snippet. The input snippet includes links to the previous and next pages, as well as the current page number. The function should parse the input snippet and produce a formatted table of contents that incl... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def generate_table_of_contents(input_snippet: str) -> str:
"""
Generates a table of contents for a series of pages in a document based on the given input snippet.
Args:
input_snippet (str): A string conta... |
magic_instruct_75k | 44,659 | Write a Python function to find the most frequently occurring key name from a list of strings. If there are multiple key names with the same highest frequency, return the one that appears first in the list. If the input list is empty, return `None`.
The function should start with:
```python
from typing import List, Op... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def most_frequent_key(keynames: List[str]) -> Optional[str]:
"""
Find the most frequently occurring key name from a list of strings.
If there are multiple key names with the same highest fr... |
magic_instruct_75k | 44,685 | Write a Python function to calculate the total amount of money required to purchase all the desired items from a store, given that each desired item must match a size available in the store and that each size can only be used once. The function should take in three parameters:
1. `sizes`: A list of integers representin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import Counter
def calculate_total_cost(sizes: List[int], desired: List[Tuple[int, int]]) -> int:
"""
Calculate the total amount of money required to purchase all the desired item... |
magic_instruct_75k | 44,687 | Write a Python function to implement a custom pagination algorithm for a web application. The function should handle a list of tags that are initially in reverse order and display 10 tags per page. The function should take the current page number as input and return the tags to be displayed on that page.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_pagination(tags_list: List[str], page_number: int) -> List[str]:
"""
Implements a custom pagination algorithm for a web application.
Args:
tags_list (List[str]): A list of tags in... |
magic_instruct_75k | 44,695 | Write a Python function to process all files in a given input directory and store the processed data in a specified output directory. The function should take two arguments: the input directory path and the output directory path. The function should process each file in the input directory by reading its content, perfo... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
from typing import List
def process_files_in_directory(input_dir: str, output_dir: str) -> None:
"""
Process all files in the input directory and store the processed data in the output directory.
Args:
in... |
magic_instruct_75k | 44,703 | Write a Python function to compute two resulting images from an input image using a mask and a reverse mask. The function should take an input image, a mask, and a reverse mask as inputs and return two images: one computed using the mask and the other using the reverse mask. The operations to be performed are element-w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import numpy as np
def compute_images(input_image: np.ndarray, mask: np.ndarray, reverse_mask: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
"""
Computes two resulting images from an input image using a... |
magic_instruct_75k | 44,706 | Write a Python function to calculate the average score for each unique molecular fragment from a list of molecular fragments. Each molecular fragment is represented by a dictionary containing a SMILES string and a score. The function should return a dictionary mapping each unique fragment's SMILES string to its average... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def calculate_average_scores(molecular_fragments: List[Dict[str, Union[str, float]]]) -> Dict[str, float]:
"""
Calculate the average score for each unique molecular fragment from a list of m... |
magic_instruct_75k | 44,710 | Write a Python function to extract unique class names from a given HTML code snippet. The class names are defined within the `class` attribute of HTML tags. The function should return a list of unique class names in the order they appear in the HTML code.
The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_class_names(html_code: str) -> List[str]:
"""
Extracts unique class names from a given HTML code snippet.
Args:
html_code (str): The HTML code snippet from which to ext... |
magic_instruct_75k | 44,719 | Write a Python function to retrieve the top connections based on similarity scores in a given dictionary. The function should take in a dictionary representing the similarity scores between articles and categories, and an optional parameter specifying the number of top connections to retrieve. If the number parameter i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Optional
def get_top_connections(art_to_cat_sim: Dict[str, Dict[str, float]], number: Optional[int] = None) -> List[Tuple[str, str, float]]:
"""
Retrieves the top connections based on simil... |
magic_instruct_75k | 44,776 | Write a Python function to implement the Metropolis-Hastings MCMC (Markov Chain Monte Carlo) algorithm to sample from a given posterior density function. The function should generate samples from the posterior distribution using the Metropolis-Hastings algorithm and analyze the convergence and mixing properties of the ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def metropolis_hastings(posterior_func, initial_state, num_samples, proposal_std):
"""
Implements the Metropolis-Hastings MCMC algorithm to sample from a given posterior density function.
Args:
p... |
magic_instruct_75k | 44,788 | Write a Python function `parse_strategy_params` that takes two lists as input:
1. A list of parameter names.
2. A list of parameter values.
The function should return a dictionary where the keys are the parameter names and the values are the corresponding parameter values. If a parameter name is not present in the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Optional
def parse_strategy_params(param_names: List[str], param_values: List[float]) -> Dict[str, Optional[float]]:
"""
Parses strategy parameters into a dictionary.
Args:
param_name... |
magic_instruct_75k | 44,791 | Write a Python function to calculate the maximum profit that can be obtained by buying and selling a stock at most once, given a list of integers representing the daily stock prices. If it is not possible to make any profit, return 0.
The code should start with:
```python
from typing import List
def max_profit(prices... | 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 buying and selling a stock at most once.
Args:
prices (List[int]): A list of integers where... |
magic_instruct_75k | 44,794 | Create a Python function that simulates a simplified file system navigation. The function should support the `dev` command, which allows users to navigate to different development directories within their home directory. The `dev` command takes a single argument, which represents the subdirectory within the "developing... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
def dev(subdirectory: str) -> None:
"""
Simulates a simplified file system navigation by changing the current directory
to the specified subdirectory within the "developing" directory in the user's home directory.... |
magic_instruct_75k | 44,810 | Write a Python function to count the occurrences of each data type in a given list of data types. The function should return a dictionary where the keys are the data types and the values are the counts of those data types in the input list.
The code should start with:
```python
from typing import List, Dict
def count... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_data_types(data_types: List[str]) -> Dict[str, int]:
"""
Counts the occurrences of each data type in the given list.
Args:
data_types (List[str]): A list of data types to cou... |
magic_instruct_75k | 44,825 | Write a Python function to convert a list of metric names based on specific rules. The function should take a list of metric names as input and return a list of converted metric names according to the following rules:
- If the metric name starts with "mem.", it should be converted to "memory.<metric_name>".
- If the me... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_metric_names(metric_names: List[str]) -> List[str]:
"""
Convert a list of metric names based on specific rules.
Args:
metric_names (List[str]): A list of metric names to be conve... |
magic_instruct_75k | 44,831 | Write a Python function `format_word_count` that takes a dictionary `word2count` as input and returns a list of strings, where each string represents a key-value pair in the format `word\tcount`. The function should handle any dictionary with string keys and integer values.
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 format_word_count(word2count: dict) -> List[str]:
"""
Formats a dictionary of word counts into a list of strings, where each string represents a key-value pair in the format 'word\tcount'.
Args:... |
magic_instruct_75k | 44,837 | Write a Python function to analyze and manipulate HTML code by identifying the number of nested HTML sections (div tags) in a given HTML snippet and determining the depth of nesting for each section. The function should return a dictionary where the keys are the depth of nesting and the values are the count of div tags... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_nested_divs(html_snippet: str) -> Dict[int, int]:
"""
Analyzes the given HTML snippet to count the number of nested div tags and their depths.
Args:
html_snippet (str): A string re... |
magic_instruct_75k | 44,846 | Write a Python function to generate an XML string representing network statistics based on a given dictionary of edge IDs and their corresponding counts. The XML structure should include a root element `<netstats>`, a nested `<interval>` element with predefined attributes, and multiple `<edge>` elements for each edge i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_xml_output(edgeList: Dict[str, int]) -> str:
"""
Generates an XML string representing network statistics based on the given edge list.
Args:
edgeList (Dict[str, int]): A diction... |
magic_instruct_75k | 44,858 | Write a Python function to generate a SQL script that adds a new column to an existing PostgreSQL database table using SQLAlchemy and Alembic. The function should take the following parameters:
- `table_name`: A string representing the name of the existing table to which the new column will be added.
- `column_name`: A... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def generate_add_column_script(table_name: str, column_name: str, column_type: str) -> str:
"""
Generates a SQL script to add a new column to an existing PostgreSQL database table using SQLAlchemy and Alembic.
... |
magic_instruct_75k | 44,881 | Write a Python function to determine if a target element is present in a sorted array of distinct integers that has been rotated at an unknown pivot. If the target is found in the array, return `True`; otherwise, return `False`.
The function signature is:
```python
from typing import List
def search_in_rotated_array(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_in_rotated_array(nums: List[int], target: int) -> bool:
"""
Determine if a target element is present in a sorted array of distinct integers that has been rotated at an unknown pivot.
Args... |
magic_instruct_75k | 44,918 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given sequence of integers. The LIS is defined as the longest subsequence where all elements are in strictly increasing order. The subsequence does not need to be contiguous.
The function 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
def longest_increasing_subsequence(sequence: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence (LIS) in a given sequence.
Args:
sequence (List[int]): The sequ... |
magic_instruct_75k | 44,922 | Write a Python function to count the occurrences of a specific pattern within a given 2D dataset. The dataset and the pattern are both represented as numpy arrays. The function should slide the pattern over the dataset from left to right and from top to bottom, and count the number of times the pattern matches exactly ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def count_pattern_occurrences(dataset: np.array, pattern: np.array) -> int:
"""
Counts the number of occurrences of a specific pattern within a given 2D dataset.
Args:
dataset (np.array): A 2D nu... |
magic_instruct_75k | 44,931 | Write a Python function to determine whether a given string contains a balanced set of block characters. A balanced set of block characters is defined as a set of characters where each opening block character has a corresponding closing block character, and the order of the characters is properly nested. The block char... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_blocks(s: str) -> bool:
"""
Determines whether the given string contains a balanced set of block characters.
Args:
s (str): The string to check for balanced block characters.
Returns:
bo... |
magic_instruct_75k | 44,939 | Write a Python function to filter a dictionary of antigens and their corresponding values based on a specified threshold. The function should return a new dictionary containing only the antigens with values greater than or equal to the specified threshold.
The code should start with:
```python
from typing import Dict
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_antigens(antigen_values: Dict[str, float], threshold: float) -> Dict[str, float]:
"""
Filters a dictionary of antigens and their corresponding values based on a specified threshold.
Args:... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.