source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_instruct_75k
50,342
Write a Python function to filter a list of software packages based on specified criteria. Each package is represented as a dictionary containing the package name, a list of required libraries, and an optional flag. The function should return the names of the packages that meet the specified conditions. The function s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_packages(packages: List[dict], required_lib: str, optional_flag: bool) -> List[str]: """ Filters a list of software packages based on the specified required library and optional flag. Arg...
magic_instruct_75k
50,358
Write a Python function to calculate the average number of days between the current date and the date of publication for a list of news articles. Each article's publication date is represented as a string in the format "YYYY-MM-DD HH:MM:SS". The function should use the `datetime` module to perform the necessary date ca...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from datetime import datetime def average_days_since_publication(dates: List[str]) -> float: """ Calculate the average number of days between the current date and the publication dates of news articles. ...
magic_instruct_75k
50,375
Write a Python function to process a list of Magic: The Gathering cards and their printings, and return a dictionary where the keys are the card names and the values are lists of image URLs for each printing of the card. Each card has a name, mana cost, and type line, and each printing has a corresponding image URL. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def generate_card_image_dict(cards: List[Dict], printings: List[Dict]) -> Dict[str, List[str]]: """ Generates a dictionary where the keys are card names and the values are lists of image URLs for e...
magic_instruct_75k
50,391
Write a Python function to calculate the total balance of an account after processing a list of transactions. Each transaction is represented as a tuple containing the transaction type (either "credit" or "debit") and the transaction amount. The function should take into account the order of transactions and apply them...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_balance(transactions: List[Tuple[str, float]], initial_balance: float) -> float: """ Calculate the total balance of an account after processing a list of transactions. Args: ...
magic_instruct_75k
50,403
Write a Python function to process a list of commands and their arguments. Each command is represented as a list of strings, where the first element is the command name and the subsequent elements are its arguments. The function should support the following commands: 1. `os-apply-config`: This command applies configur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_commands(commands: List[List[str]]) -> List[int]: """ Processes a list of commands and their arguments, returning a list of return codes for each command execution. Args: command...
magic_instruct_75k
50,409
Write a Python function to add a new private column to a specified group in a data frame. The data frame is represented as a list of dictionaries, where each dictionary represents a row in the data frame. The function should take the data frame, the name of the group, and the values for the new private column as input,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def add_private_column_to_group(data_frame: List[Dict[str, Any]], group_name: str, new_column_values: List[Any]) -> List[Dict[str, Any]]: """ Adds a new private column to a specified group in ...
magic_instruct_75k
50,419
Write a Python function to process an array of data and generate a formatted output string. The function should take a list of strings as input, where each string represents a row of data. Each row is formatted as a comma-separated list of values. The function should iterate through the input list, process each row, an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_and_format_data(data: List[str]) -> str: """ Processes an array of data and generates a formatted output string. Args: data (List[str]): A list of strings where each string repre...
magic_instruct_75k
50,425
Write a Python function to process an SMT-LIB script by replacing specific function names with their simplified versions. The function should take a string representing the SMT-LIB script and return the modified script after performing the specified replacements. The replacements to be made are: - Replace "bvurem_i" wi...
Here is the Python code to solve the given problem in the markdown block: ```python def process_smt_script(script: str) -> str: """ Process an SMT-LIB script by replacing specific function names with their simplified versions. Args: script (str): The input SMT-LIB script as a string. Returns: ...
magic_instruct_75k
50,437
Write a Python function to scale a given point in a 2D plane. The point is represented by its coordinates `(x, y)`, and the scaling factor is a positive real number. The function should take the original point and the scaling factor as input and return the scaled point. The function signature should be: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def scale_point(p: Tuple[float, float], scale: float) -> Tuple[float, float]: """ Scales a given point in a 2D plane by a specified scaling factor. Args: p (Tuple[float, float]): The origin...
magic_instruct_75k
50,449
Write a Python function to swap the values of two variables `a` and `b` without using a temporary variable. The function should take two input parameters, `a` and `b`, and return the updated values of `a` and `b` after the swap. The function should be named `swap_without_temp`. The code should start with: ```python de...
Here is the Python code to solve the given problem in the markdown block: ```python def swap_without_temp(a: int, b: int) -> tuple: """ Swaps the values of two variables `a` and `b` without using a temporary variable. Args: a (int): The first variable. b (int): The second variable. Ret...
magic_instruct_75k
50,451
Write a Python function to clean up a list of installed package versions by removing any outdated versions, leaving only the latest version for each package. The function should take a list of strings where each string represents a package version in the format `package_name-version_number`. The function should return ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cleanup_packages(installed_versions: List[str]) -> List[str]: """ Cleans up a list of installed package versions by removing any outdated versions, leaving only the latest version for each packag...
magic_instruct_75k
50,464
Write a Python function to parse a file header and extract the description and date from it. The file header contains a brief description and a date in the format `YYYY-MM-DD`. The function should take the file header as input and return a tuple containing the description and the date. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python import re def parse_file_header(file_header: str) -> tuple: """ Extracts the description and date from a given file header. The file header contains a brief description and a date in the format `YYYY-MM-DD`. The descri...
magic_instruct_75k
50,495
Write a Python function to determine if a given configuration setting string includes the feature "version 2 with negative option" enabled. The configuration setting string contains various parameters and their values, each represented by `--<parameter_name>=<value>`. The function should return `True` if the parameter ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_version_2_with_negative_enabled(setting: str) -> bool: """ Determines if the configuration setting string includes the feature "version 2 with negative option" enabled. Args: setting (str): The configuration ...
magic_instruct_75k
50,510
Write a Python function to calculate the total charge for a filming project based on a list of charges. Each charge is represented as a dictionary with the keys `'name'` (a string) and `'amount'` (a float). If a charge with the name `'filming_non_standard_charge'` is present, it should be multiplied by 1.5 before being...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union def calculate_total_charge(charges: List[Dict[str, Union[str, float]]]) -> float: """ Calculate the total charge for a filming project based on a list of charges. Args: charges ...
magic_instruct_75k
50,512
Write a Python function called `generate_metric_output` that takes two arguments: a string `instance_id` and a dictionary `metric_data`. The function should generate a formatted string based on the provided `metric_data` dictionary and the `instance_id`. The `metric_data` dictionary will contain information about a dat...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_metric_output(instance_id: str, metric_data: dict) -> str: """ Generates a formatted string based on the provided instance ID and metric data. Args: instance_id (str): The ID of the instance. me...
magic_instruct_75k
50,518
Write a Python function to calculate the available space in gigabytes on a storage device, considering the reserved space specified in the settings. The function should take two parameters: `total_space_in_gb` (total space on the device in gigabytes) and `settings` (a dictionary containing the reserved space in gigabyt...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_available_space(total_space_in_gb: float, settings: dict) -> float: """ Calculate the available space in gigabytes on a storage device after considering the reserved space. Args: total_space_in_gb (flo...
magic_instruct_75k
50,545
Write a Python function to perform data transformation and evaluation for time series forecasting. The function should take in input test data, predicted values, a list to store predicted values, an object for data transformation, and the length of the test data. The function should append a copy of the predicted value...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def transform_and_evaluate(X_test: np.ndarray, Y_hat: np.ndarray, Y_hats: list, mmn, len_test: int) -> np.ndarray: """ Perform data transformation and evaluation for time series forecasting. Args: ...
magic_instruct_75k
50,549
Write a Python function to generate URL patterns for race detail views based on a list of race years. Each URL pattern should follow the format `<int:year>-<int:year2>/<slug>/`, where `year` and `year2` are integers representing the start and end years of the race, and `slug` is a string representing the race identifie...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def generate_race_urls(race_years: List[Tuple[int, int]]) -> Dict[str, str]: """ Generate URL patterns for race detail views based on a list of race years. Args: race_years (Lis...
magic_instruct_75k
50,566
Write a Python function to generate segments based on the given parameters. The function `generate_segments` takes several arguments: `starttime`, `endtime`, `includeflags`, `excludeflags`, `writesegments`, and `usegwosc`. The `starttime` and `endtime` represent the start and end times for the segments. The `includefla...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def generate_segments(starttime: int, endtime: int, includeflags: List[str], excludeflags: List[str], writesegments: List[Tuple[int, int, List[str]]], usegwosc: bool) -> List[Tuple[int, int, List[str]]]: ...
magic_instruct_75k
50,567
Write a Python function to group elements of a given list into sublists of a specified size. The function should take two parameters: the list to be grouped and the size of each subgroup. The function should return a new list containing the grouped sublists. If the last subgroup has fewer elements than the specified si...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def group_elements(lst: List[int], size: int) -> List[List[int]]: """ Groups elements of a given list into sublists of a specified size. Args: lst (List[int]): The list to be grouped. ...
magic_instruct_75k
50,576
Write a Python function to generate tweet links from a list of tweet IDs. Each tweet link should be in the format "https://twitter.com/tbot60/status/{tweet_id}". The function should take a list of tweet IDs as input and return a list of tweet links corresponding to each ID. 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 generate_tweet_links(tweet_ids: List[int]) -> List[str]: """ Generates tweet links from a list of tweet IDs. Args: tweet_ids (List[int]): A list of integers representing tweet IDs. ...
magic_instruct_75k
50,577
Write a Python function to count the occurrences of each unique integer in a given list of integers. The function should return a dictionary where the keys are the unique integers and the values are their respective counts. The function should handle empty input lists by returning an empty dictionary. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_unique(nums: List[int]) -> Dict[int, int]: """ Counts the occurrences of each unique integer in the given list. Args: nums (List[int]): The list of integers to count unique o...
magic_instruct_75k
50,578
Write a Python function to generate all unique combinations of climate model configurations for a research project. Each combination consists of a climate model, a regional climate model, and a greenhouse gas emission scenario. The function should return a list of tuples, where each tuple represents a unique combinatio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import itertools def generate_climate_model_combinations() -> List[Tuple[str, str, str]]: """ Generates all unique combinations of climate model configurations. Each combination consists of a...
magic_instruct_75k
50,600
Write a Python function to validate a dataset consisting of pairs of item counts and error codes. The dataset is represented as a list of tuples, where each tuple contains an item count and an error code. The validation rules are as follows: 1. The item count must be a non-negative integer. 2. If the item count is zero...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def validate_data(data: List[Tuple[int, Union[int, None]]]) -> bool: """ Validates a dataset consisting of pairs of item counts and error codes. Args: data (List[Tuple[int, Uni...
magic_instruct_75k
50,601
Write a Python function to calculate the value of the variable `numbee` after the loop has finished executing. The function should take an integer `n` as input, which represents the number of iterations in the loop. The initial value of `numbee` is set to 63 + 42, and in each iteration of the loop, the current value of...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_numbee(n: int) -> int: """ Calculate the value of the variable `numbee` after the loop has finished executing. Args: n (int): The number of iterations in the loop. Returns: int: The value ...
magic_instruct_75k
50,656
Write a Python function to filter and return the names of students who have scored above a specified threshold in a given subject from a list of dictionaries representing student information. Each dictionary contains the keys "name" (string), "age" (integer), and the subject names as keys with their corresponding score...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_students_above_threshold(students: List[Dict[str, any]], subject: str, threshold: int) -> List[str]: """ Returns a list of names of students who have scored above a specified threshold in a...
magic_instruct_75k
50,667
Write a Python function `navigate_rooms(rooms, actions)` that simulates a player navigating through a series of rooms in a text-based game. Each room has a set of available actions, and the player must perform these actions to move to the next room. The function should return the reward obtained after completing the fi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def navigate_rooms(rooms: List[Dict[str, any]], actions: List[str]) -> str: """ Simulates a player navigating through a series of rooms based on a sequence of actions. Args: ...
magic_instruct_75k
50,668
Write a Python function `process_string` that takes a string as input and performs a series of text processing operations on it. The function should follow these steps in sequence: 1. Remove any leading or trailing whitespace from the input string. 2. Convert the string to lowercase. 3. Replace any occurrence of the su...
Here is the Python code to solve the given problem in the markdown block: ```python def process_string(input_string: str) -> str: """ Process the input string according to a set of rules: 1. Remove any leading or trailing whitespace. 2. Convert the string to lowercase. 3. Replace any occurrence of t...
magic_instruct_75k
50,695
Write a Python function `isDuplicatedOffer` that checks if a new offer with the same name and category already exists in the filtered offers obtained by calling the `filterMyOffers` method. The `filterMyOffers` method filters offers based on certain criteria and returns a list of filtered offers. Each offer in the filt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def isDuplicatedOffer(self, name: str, categoryId: int) -> bool: """ Checks if a new offer with the same name and category already exists in the filtered offers. Args: self (object ref...
magic_instruct_75k
50,711
Write a Python function to find the length of the shortest subarray that, when sorted, makes the entire array sorted in non-decreasing order. If the array is already sorted, return 0. The function should start with: ```python from typing import List def findUnsortedSubarray(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def findUnsortedSubarray(nums: List[int]) -> int: """ Find the length of the shortest subarray that, when sorted, makes the entire array sorted in non-decreasing order. Args: nums (List[int]...
magic_instruct_75k
50,720
Write a Python function to generate a list of date strings in the format "month-half-year" for a given range of years. Each date string should include a three-letter month abbreviation from a predefined tuple, a letter representing the half of the month from another predefined tuple, and the year from the given range. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def generate_date_strings(start_year: int, end_year: int, months: Tuple[str], halves: Tuple[str]) -> List[str]: """ Generate a list of date strings in the format "month-half-year" for a given rang...
magic_instruct_75k
50,723
Write a Python function to analyze particle shower data from a high-energy physics experiment. The function should take a dictionary of parsed arguments as input and return the result of the analysis as a float value. The dictionary contains the following keys: - 'nbins': Number of bins in histograms (integer) - 'tmax'...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def analyze_shower_data(args: dict) -> float: """ Analyzes particle shower data based on the provided arguments. Args: args (dict): A dictionary containing the following keys: - 'nbin...
magic_instruct_75k
50,727
Write a Python function to determine if a given dictionary is an instance of the `OrderedDict` class from the `collections` module. The function should return `True` if the input dictionary is an `OrderedDict`, and `False` otherwise. The code should start with: ```python from collections import OrderedDict def is_ord...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import OrderedDict def is_ordered_dict(dictionary: dict) -> bool: """ Determines if the given dictionary is an instance of the `OrderedDict` class. Args: dictionary (dict): The dictionary to be che...
magic_instruct_75k
50,738
Write a Python function to serialize a given step value into a JSON object and then convert it into a list of characters. The function should take an integer `step` as input and return a list of characters containing the serialized JSON object. The function should perform the following steps: 1. Create a JSON object u...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import json def end_signal(step: int) -> List[str]: """ Serialize a given step value into a JSON object and convert it into a list of characters. Args: step (int): The step value to be seria...
magic_instruct_75k
50,742
Create a Python function to manage topic subscriptions for a messaging application. The system should allow clients to subscribe to various topics and receive messages related to those topics. Implement a data structure and associated functions to manage the topic subscriptions. Specifically, you need to: 1. Define a `...
Here is the Python code to solve the given problem in the markdown block: ```python class TopicQueue: def __init__(self, topic: str): """ Initialize a TopicQueue node with a given topic. Args: topic (str): The topic to be stored in the node. """ self.topic = topi...
magic_instruct_75k
50,744
Write a Python function to manage the emailing of PDF reports to users based on certain conditions. The function should interact with a database of users and their AWS keys, and use a template to generate the email content. The following requirements should be met: 1. The function should use a template named 'emailPDF...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime from typing import List class User: def __init__(self, email: str, aws_keys: List[str], report_last_emailed_at: datetime.datetime = None): self.email = email self.aws_keys = aws_keys self.rep...
magic_instruct_75k
50,769
Write a Python function `calculate_sum` that takes two integer parameters `a` and `b`, and returns the sum of these two numbers. However, if the sum is less than or equal to zero, the function should return zero instead. The function should adhere to the following specifications: - If the sum of `a` and `b` is greater ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sum(a: int, b: int) -> int: """ Calculate the sum of two integers `a` and `b`. If the sum is greater than zero, return the sum. If the sum is less than or equal to zero, return zero. Args: a (int):...
magic_instruct_75k
50,798
Write a Python script that automates the build process for a project using Emscripten, a toolchain for compiling C and C++ code to WebAssembly. The script should accomplish the following tasks: 1. Navigate to the directory containing the Emscripten toolchain. 2. Execute the `make` command to build the project. 3. Copy ...
Here is the Python code to solve the given problem in the markdown block: ```python import os import shutil import subprocess def build_emscripten_project(emscripten_dir: str) -> None: """ Automates the build process for a project using Emscripten. Args: emscripten_dir (str): The directory contain...
magic_instruct_75k
50,799
Write a Python function to process a list of tuples representing header mappings. Each tuple contains four elements: the renamed header, the original header, a transformation function, and a flag indicating whether an error should be raised if the original header is not found. The function should iterate through the li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable, Dict def process_header_map(header_map: List[tuple], data: Dict[str, str]) -> Dict[str, str]: """ Processes a list of header mappings and returns a dictionary with renamed headers and their tr...
magic_instruct_75k
50,811
Write a Python function to calculate the total amount of rainwater that can be trapped between a series of buildings represented by their heights. Each building has a width of 1 unit. The function should take a list of non-negative integers representing the heights of the buildings and return the total trapped rainwate...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def trapped_rainwater(heights: List[int]) -> int: """ Calculate the total amount of rainwater that can be trapped between buildings. Args: heights (List[int]): A list of non-negative integer...
magic_instruct_75k
50,821
Write a Python function to determine the minimum number of rectangles required to cover all the points in a 2D plane. Each rectangle is defined by its bottom-left and top-right coordinates. The function should take a list of points as input and return the minimum number of rectangles needed to cover all the points. It ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def min_rectangles(points: List[Tuple[int, int]]) -> int: """ Calculate the minimum number of rectangles required to cover all the points in a 2D plane. Args: points: A list of tuples...
magic_instruct_75k
50,825
Write a Python function to generate an engine string based on given parameters. The function should take two arguments: `style` and `aspiration`. The `style` argument is a dictionary where keys are style names and values are lists of possible cylinder counts. The `aspiration` argument is a string representing the aspir...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import Dict, List def generate_engine_string(style: Dict[str, List[int]], aspiration: str) -> str: """ Generates an engine string based on the provided style dictionary and aspiration type. Args: ...
magic_instruct_75k
50,826
Write a Python function to validate a given cron expression. A cron expression is a string representing a schedule, typically used to execute tasks at regular intervals. The expression consists of five space-separated fields representing minute, hour, day of the month, month, and day of the week. Each field can contain...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_cron(cron_expression: str) -> bool: """ Validates a given cron expression. Args: cron_expression (str): The cron expression to validate. Returns: bool: True if the cron expressio...
magic_instruct_75k
50,830
Write a Python function to filter a list of GitHub repository information based on a given threshold for the number of stars. Each repository is represented as a dictionary with keys "filename" and "gh_stars". The function should return a new list containing only the repositories that have a number of stars greater tha...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_repositories(repositories: List[Dict[str, any]], stars_threshold: int) -> List[Dict[str, any]]: """ Filters a list of GitHub repository information based on a given threshold for the num...
magic_instruct_75k
50,835
Write a Python function to calculate the total size of intermediate representations in a neural network. The intermediate representations are stored in a list, where each element represents the size of the representation in a hidden layer. Your function should take this list as input and return the total size of all in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def total_intermediate_size(intermediate_sizes: List[int]) -> int: """ Calculate the total size of intermediate representations in a neural network. Args: intermediate_sizes (List[int]): A l...
magic_instruct_75k
50,836
Write a Python function to select the remaining titans from a list of available titans. The function should take in two parameters: `NUM_TITANS`, an integer representing the total number of titans, and `picked`, a list of integers representing the titans that have already been picked. The function should return a list ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def select_remaining_titans(NUM_TITANS: int, picked: List[int]) -> List[int]: """ Selects the remaining titans from a list of available titans. Args: NUM_TITANS (int): The total number of ti...
magic_instruct_75k
50,848
Write a Python function to create mini-batches from a given dataset. The function should take the dataset, batch size, and the number of complete batches as input and return a list of mini-batches. Each mini-batch should consist of a tuple containing subsets of the input data and corresponding output labels. The funct...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def create_mini_batches(dataset: Tuple[List[float], List[float]], batch_size: int, complete_batch_nums: int) -> List[Tuple[List[float], List[float]]]: """ Create mini-batches from the given datase...
magic_instruct_75k
50,879
Write a Python function to map a given failure type to its corresponding verbose name based on predefined choices. If the input failure type is not found in the choices, the function should return "Unknown Failure Type". The code should start with: ```python def get_verbose_failure_type(failure_type: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def get_verbose_failure_type(failure_type: str) -> str: """ Returns the verbose name for a given failure type based on predefined choices. Args: failure_type (str): The failure type to look up. Returns: ...
magic_instruct_75k
50,892
Write a Python function to generate a unique identifier for a secondary pool in a cloud computing environment. The function should follow these requirements: 1. The identifier should be in the format "secondarypool-<randomIdentifier>", where `<randomIdentifier>` is a randomly generated alphanumeric string. 2. The lengt...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_secondary_pool_identifier(length: int) -> str: """ Generates a unique identifier for a secondary pool in a cloud computing environment. The identifier follows the format "secondaryp...
magic_instruct_75k
50,933
Write a Python function to determine the namespace(s) of a given C++ code snippet. The function should take a string representing a C++ code snippet as input and return a list of strings representing the namespace(s) present in the code. The function should handle nested namespaces and return the namespaces in the orde...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def find_namespaces(code: str) -> List[str]: """ Determine the namespace(s) present in a given C++ code snippet. Args: code (str): A string representing a valid C++ code snippet. ...
magic_instruct_75k
50,941
Write a Python function to calculate the area of a triangle using its side lengths. The function should use Heron's formula, which is given by: \[ \text{Area} = \sqrt{s \cdot (s - a) \cdot (s - b) \cdot (s - c)} \] Where \(s\) is the semi-perimeter of the triangle, calculated as: \[ s = \frac{a + b + c}{2} \] The f...
Here is the Python code to solve the given problem in the markdown block: ```python import math def triangle_area(a: float, b: float, c: float) -> float: """ Calculate the area of a triangle using its side lengths. Args: a (float): The length of the first side of the triangle. b (float): T...
magic_instruct_75k
51,042
Write a Python function to sanitize a list of dictionary entries by removing HTML tags from the "text" field of each entry. Each dictionary entry represents a blog post and contains a "title" and "text" field. The function should return a new list with the HTML tags removed from the "text" field of each entry. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List, Dict def sanitize_entries(entries: List[Dict[str, str]]) -> List[Dict[str, str]]: """ Sanitize a list of dictionary entries by removing HTML tags from the "text" field of each entry. Args...
magic_instruct_75k
51,056
Write a Python function to compare the release information of a software package from two different sources. The release information is embedded in the HTML of the web pages. The function should extract the release information from the given URLs and compare them to determine if there is a newer release available. The ...
Here is the Python code to solve the given problem in the markdown block: ```python import requests from bs4 import BeautifulSoup def compare_release_info(current_url: str, latest_url: str) -> str: """ Compares the release information of a software package from two different sources. Args: current...
magic_instruct_75k
51,079
Write a Python function to modify a given regular expression pattern by replacing all occurrences of the word "apple" with "orange". The function should use the `re` module to perform the replacement. The function should be named `modify_pattern` and should take a single string argument representing the input pattern. ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def modify_pattern(input_pattern: str) -> str: """ Modifies the input regular expression pattern by replacing all occurrences of the word "apple" with "orange". Args: input_pattern (str): The input regula...
magic_instruct_75k
51,092
Write a Python function to extract the names of databases that are configured to use the PostgreSQL database engine (`django.db.backends.postgresql_psycopg2`) from a given dictionary of database configurations. The function should return a list of these database names. The input dictionary will have the following stru...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def get_postgres_databases(configs: Dict[str, Dict[str, str]]) -> List[str]: """ Extracts the names of databases that are configured to use the PostgreSQL database engine. Args: config...
magic_instruct_75k
51,096
Write a Python function to determine the number of unvisited rooms in a building. The function should take a list of all room numbers in the building and a set of room numbers that have already been visited. The function should return the count of unvisited rooms. 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, Set def count_unvisited_rooms(all_rooms: List[int], visited_rooms: Set[int]) -> int: """ Counts the number of unvisited rooms in a building. Args: all_rooms (List[int]): A list of all room ...
magic_instruct_75k
51,098
Write a Python function to generate SQL commands for dropping specified tables and indexes in a database migration script. The function should take two lists as input: one for table names and another for index names. The function should return a string containing the SQL commands to drop the specified tables and indexe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_migration_script(tables: List[str], indexes: List[str]) -> str: """ Generates SQL commands to drop specified tables and indexes. Args: tables (List[str]): A list of table names ...
magic_instruct_75k
51,137
Write a Python function to generate random hand information for a given batch size and number of components. The hand information includes vertices and joint positions. The function should return a dictionary containing the vertices and joint positions for the randomly generated hands. The function signature should be...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_random_hand(batch_size: int, ncomps: int) -> dict: """ Generate random hand information for a given batch size and number of components. Args: batch_size (int): The number of hand in...
magic_instruct_75k
51,151
Write a Python function to parse a configuration file represented as a dictionary and extract specific package information. The function should return a new dictionary containing the extracted information. The extracted information should include the author, the list of packages, and the combined list of dependencies f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def extract_package_info(config_data: Dict) -> Dict: """ Extracts specific package information from a configuration dictionary. Args: config_data (dict): The configuration dictionary c...
magic_instruct_75k
51,160
Write a Python function to transform a given input string by counting the occurrences of each character and constructing a new string based on these counts. The new string should be in the format where each character is followed by its count in the input string. The function should start with: ```python def transform_s...
Here is the Python code to solve the given problem in the markdown block: ```python def transform_string(input_string: str) -> str: """ Transforms the input string by counting the occurrences of each character and constructing a new string based on these counts. Args: input_string (str): The input ...
magic_instruct_75k
51,168
Write a Python function to filter a list of media playlists based on a given document playlist ID. Each media playlist is represented as a dictionary with the following structure: ```python { 'id': int, 'name': str, 'document_playlist_id': int } ``` The function should take in a list of media playlists and ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_media_playlists(media_playlists: List[Dict[str, any]], document_playlist_id: int) -> List[Dict[str, any]]: """ Filters a list of media playlists based on a given document playlist ID. ...
magic_instruct_75k
51,170
Write a Python function `reverse_coordinates(verts, ind_map)` that takes in two parameters: - `verts`: a list of lists representing 3D vertices, where each inner list contains three elements: x-coordinate, y-coordinate, and depth. - `ind_map`: a dictionary mapping (x, y) coordinates to their corresponding indices in th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def reverse_coordinates(verts: List[List[int]], ind_map: Dict[tuple, int]) -> List[List[int]]: """ Reverses the process of appending coordinates to a 3D vertices list and updating an index map. ...
magic_instruct_75k
51,175
Create a Python class `PluginManager` that manages a list of plugins and handles the event of a new plugin becoming available. The class should have the following features: 1. Ability to register and unregister plugins. 2. Maintain a list of available plugins. 3. Implement the `OnPluginAvailable` callback function to h...
Here is the Python code to solve the given problem in the markdown block: ```python class PluginManager: def __init__(self): """ Initialize the PluginManager with an empty list of plugins. """ self.plugins = [] def register_plugin(self, plugin_name: str) -> None: """ ...
magic_instruct_75k
51,178
Write a Python function to convert a 24-bit hexadecimal color code represented as an integer into its corresponding RGB (Red, Green, Blue) representation. The input integer is in the format 0xRRGGBB, where RR, GG, and BB are two-digit hexadecimal numbers representing the intensity of red, green, and blue components, re...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_rgb(hex_color: int) -> tuple: """ Converts a 24-bit hexadecimal color code represented as an integer into its corresponding RGB (Red, Green, Blue) representation. Args: hex_color (int): A 24-bit hexadecim...
magic_instruct_75k
51,184
Write a Python function to determine whether two strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should be case-sensitive, meaning that the comparison should consider t...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(s1: str, s2: str) -> bool: """ Determine whether two strings are anagrams of each other. Args: s1 (str): The first string to compare. s2 (str): The second string to compare. Returns: ...
magic_instruct_75k
51,194
Write a Python function `config2structure` that converts a configuration dictionary to a specific structure based on a given search space. The function should take a `search_space` dictionary and a `config` dictionary as inputs and return a string representing the structure. The `search_space` dictionary contains a ke...
Here is the Python code to solve the given problem in the markdown block: ```python def config2structure(search_space: dict, config: dict) -> str: """ Converts a configuration dictionary to a specific structure based on a given search space. Args: search_space (dict): A dictionary containing the ke...
magic_instruct_75k
51,228
Write a Python function `perform_operation` that takes a list of integers `nums` and a string or integer `k`, and returns the modified list after performing a specific operation based on the value of `k`. - If `k` is the string `'rev'`, reverse the list `nums`. - If `k` is an integer: - If `k` is even, remove the el...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def perform_operation(nums: List[int], k: Union[str, int]) -> List[int]: """ Perform a specific operation on the list `nums` based on the value of `k`. Args: nums (List[int]): A list ...
magic_instruct_75k
51,241
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should return 0 if the input list is empty or does not contain any even numbers. The code should start with: ```python from typing import List def calculate_sum_of_evens(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum_of_evens(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list of integers. Args: numbers (List[int]): A list of integers from which to ca...
magic_instruct_75k
51,243
Write a Python function to generate a front matter for a markdown file used in a static site generator. The front matter should include the path, date, title, tags, and an excerpt. The function should take the path and title as input and return the formatted front matter string. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def gen_frontmatter(path: str, title: str) -> str: """ Generates a front matter for a markdown file used in a static site generator. Args: path (str): The path for the markdown file. ...
magic_instruct_75k
51,244
Write a Python function to implement a pagination system for a web application. The function should take a list of items and a page number as input and return the items that should be displayed on that page. The number of items per page is defined by the constant `PER_PAGE`. If the page number is invalid (less than 1 o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List PER_PAGE = 10 # Define the number of items per page def paginate_items(items: List[int], page_number: int) -> List[int]: """ Returns the items that should be displayed on the specified page. Args:...
magic_instruct_75k
51,246
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should adhere to the following constraints: - You can only use the following programming constructs: `for` loop, `if` statement, and basic arithmetic operations. - You are not allowed to use any built-in functions...
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 the given list of integers. Args: nums (List[int]): A list of integers containing both positive and...
magic_instruct_75k
51,271
Write a Python function to extract the names of model fields from a given string that contains Django model field definitions. Each model field is defined using the `models.CharField` function, and the goal is to extract the names of these fields. The function should return a list of field names extracted from the inpu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_model_fields(input_string: str) -> List[str]: """ Extracts the names of model fields from a given string containing Django model field definitions. Args: input_string (...
magic_instruct_75k
51,313
Implement a simple encoding and decoding algorithm for a specific data format. The encoding algorithm should replace specific vowels in a string with corresponding numbers, while the decoding algorithm should reverse this process to return the original string. The encoding rules are as follows: 1. Replace all occurren...
Here is the Python code to solve the given problem in the markdown block: ```python def encode(s: str) -> str: """ Encodes the input string by replacing specific vowels with corresponding numbers. Args: s (str): The input string to be encoded. Returns: str: The encoded string. """ ...
magic_instruct_75k
51,322
Create a Python class `Pointers` that manages a collection of pointers (represented as integers for simplicity) and provides methods to add and remove pointers from the collection. The class should have the following specifications: - The class should have a constructor that takes an integer `capacity` as a parameter ...
Here is the Python code to solve the given problem in the markdown block: ```python class Pointers: def __init__(self, capacity: int): """ Initializes the Pointers class with a specified capacity. Args: capacity (int): The maximum number of pointers the collection can hold. ...
magic_instruct_75k
51,324
Write a Python function to validate the nesting and balance of `<head>` and `<body>` tags in a given HTML string. The function should return `True` if the tags are properly nested and balanced, and `False` otherwise. The input HTML string will only contain the `<head>` and `<body>` tags, and there will be no other nest...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_html_tags(html: str) -> bool: """ Validates the nesting and balance of <head> and <body> tags in a given HTML string. Args: html (str): The HTML string to be validated. Returns: bool: True ...
magic_instruct_75k
51,334
Write a Python function `format_commands(commands)` that takes a list of strings representing available commands in a text-based adventure game and returns a formatted string. Each command should be displayed on a new line, prefixed with a number indicating its order in the list. The numbering should start from 1 and i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def format_commands(commands: List[str]) -> str: """ Formats a list of commands for display in a text-based adventure game. Args: commands (List[str]): A list of strings where each string re...
magic_instruct_75k
51,338
Write a Python function to implement a simple hash table data structure that supports key-value pairs and handles collisions using separate chaining. The hash table should have the following functionalities: 1. `insert(key, value)`: Insert a key-value pair into the hash table. If the key already exists, update the corr...
Here is the Python code to solve the given problem in the markdown block: ```python class HashTable: def __init__(self, size: int): """ Initialize the hash table with a fixed size. Args: size (int): The size of the hash table. """ self.size = size self.ta...
magic_instruct_75k
51,343
Write a Python function to validate and coerce a user's resampling configuration for a neuroimaging data processing tool using CAT12. The function should ensure that the resampling type and internal resampling value adhere to specific constraints. If the configuration is invalid, the function should raise an appropriat...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_resampling_configuration(resampling_type: str, internal_resampling_value: float) -> tuple: """ Validates and coerces the resampling configuration for a neuroimaging data processing tool using CAT12. Args: ...
magic_instruct_75k
51,372
Write a Python function to select a specific region in an image based on a given color. The image is represented as a 3D NumPy array, where the dimensions correspond to the height, width, and color channels. The color of the region to be selected is specified by a 3-element list representing the RGB values. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def select_region_by_color(image: np.ndarray, color: list) -> list: """ Selects a specific region in an image based on a given color and returns the coordinates of all matching pixels. Args: imag...
magic_instruct_75k
51,381
Write a Python function to convert a 1D array of 16 elements representing a 4x4 matrix in row-major order into a 2D array. The function should ensure that the input array always contains exactly 16 elements and return a 4x4 2D array. The code should start with: ```python from typing import List def load_matrix(matrix...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def load_matrix(matrix: List[float]) -> List[List[float]]: """ Converts a 1D array of 16 elements representing a 4x4 matrix in row-major order into a 2D array. Args: matrix (List[float]): A ...
magic_instruct_75k
51,382
Write a Python function to generate random multidimensional indices for a given number of dimensions. The function should take the number of dimensions as input and return a tuple of random indices within the specified dimensions. The function should use the `numpy` library to generate the random indices. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_random_indices(ndim: int) -> tuple: """ Generate random multidimensional indices for a given number of dimensions. Args: ndim (int): The number of dimensions. Returns: t...
magic_instruct_75k
51,393
Create a Python class `IDCardProcessing` that manages the status of ID card processing for a company. The class should handle the storage of the file path for the back side of the ID card and the status of the processing. The class should have the following specifications: - A private member variable `_back_side_of_id_...
Here is the Python code to solve the given problem in the markdown block: ```python class IDCardProcessing: def __init__(self): """ Initialize the IDCardProcessing class with empty path and pending status. """ self._back_side_of_id_card_path = "" self._status = False def...
magic_instruct_75k
51,418
Write a Python function to find the next greater element for each element in a given array of integers. The function should return an array where each element at index `i` represents the next greater element of `arr[i]` in the input array. If there is no greater element for a particular element, the output array should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def getNextGreaterElement(arr: List[int]) -> List[int]: """ Finds the next greater element for each element in the input array. Args: arr (List[int]): The input array of integers. Retur...
magic_instruct_75k
51,421
Write a Python function to extract the verbose name from a given string that follows the convention of using the `_()` function for translation in Django projects. The `_()` function is commonly used for translating text in Django applications. The input string will always contain a single `_()` function call, and the ...
Here is the Python code to solve the given problem in the markdown block: ```python def extract_verbose_name(input_string: str) -> str: """ Extracts the verbose name from a given string that follows the Django translation convention. Args: input_string (str): The input string containing a single `_...
magic_instruct_75k
51,445
Write a Python function to calculate the distinct 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. The function should be named `climb_stairs` and should take an integer `n` as its parameter, returning an integer representing the number of distinct ways t...
Here is the Python code to solve the given problem in the markdown block: ```python def climb_stairs(n: int) -> int: """ Calculate the number of distinct ways to reach the top of a staircase with n steps. Args: n (int): The number of steps in the staircase. Returns: int: The nu...
magic_instruct_75k
51,451
Write a Python function to simulate a file management system that handles deletion of files and directories based on a list of commands. The function should take a list of commands as input and return the final state of the file system after executing the commands. Each command is a string that represents a file or dir...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def simulate_file_system(commands: List[str]) -> List[str]: """ Simulate a file management system that handles deletion of files and directories based on a list of commands. Args: commands (...
magic_instruct_75k
51,465
Write a Python function `process_data(data)` that takes in a list of dictionaries `data` and returns the modified data after performing the specified transformation. Each dictionary in the list represents an item, and the function should add a new key-value pair to each dictionary where the key is "processed" and the v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def process_data(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Processes a list of dictionaries by adding a new key-value pair to each dictionary. The new key is "processed" and the ...
magic_instruct_75k
51,478
Write a Python function to generate a new Alembic revision file content based on a provided `revision_id`. The function should return a string that represents the content of the revision file, including the necessary imports and the revision identifier. The function should handle the basic structure of an Alembic revis...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_alembic_revision(revision_id: str) -> str: """ Generates the content of a new Alembic revision file based on the provided revision_id. Args: revision_id (str): The unique identifier for the revision. ...
magic_instruct_75k
51,484
Write a Python function to determine if iterable unpacking is unnecessary for a given list of elements. Iterable unpacking is considered unnecessary if the list contains only a single element. The function should return `True` if the unpacking is unnecessary, and `False` otherwise. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def check_unnecessary_iterable_unpacking(elements: List[Any]) -> bool: """ Determines if iterable unpacking is unnecessary for a given list of elements. Args: elements (List[Any]): The ...
magic_instruct_75k
51,495
Create a Python decorator `argscope` that restricts the arguments a function can accept to a specified list of allowed argument names. If any argument outside the specified scope is provided, the function should raise a `ValueError`. The decorator should be a higher-order function that takes a list of allowed argument ...
Here is the Python code to solve the given problem in the markdown block: ```python def argscope(allowed_args): """ A decorator that restricts the arguments a function can accept to a specified list of allowed argument names. Args: allowed_args (list): A list of allowed argument names. Returns...
magic_instruct_75k
51,497
Write a Python function to find the shortest path between two nodes in an undirected graph using Breadth-First Search (BFS). The graph is represented using an adjacency list. The function should take the graph, start node, and end node as input and return the shortest path between the start and end nodes as a list of n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict from collections import deque def bfs_shortest_path(graph: Dict[int, List[int]], start: int, end: int) -> List[int]: """ Find the shortest path between the start node and the end node in an undirec...
magic_instruct_75k
51,505
Write a Python function to strip comments from a given string. The function should remove any comments from the input string and return the result. A comment is defined as any text following a `#` character until the end of the line. The function should handle both single-line and multi-line comments. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python def strip_comments(input_string: str) -> str: """ Strip comments from a given string. Comments are defined as any text following a '#' character until the end of the line. Args: input_string (str): The input string ...
magic_instruct_75k
51,574
Write a Python function to calculate the State of Charge (SoC) of a battery based on the power input from the battery pack. The power input is represented as an array of integers, where each element represents the power supplied by the battery at a specific time. The SoC is represented as an array of floats, where each...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_soc(P_battery: List[int], SoC: List[float]) -> (List[int], List[float]): """ Calculate the State of Charge (SoC) of a battery based on the power input from the battery pack. Args: ...
magic_instruct_75k
51,577
Write a Python function to concatenate a list of strings with newline characters between them and return the resulting multi-line string. The function should handle an empty list by returning an empty string. The code should start with: ```python from typing import List def concatenate_lines(lines: List[str]) -> str:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_lines(lines: List[str]) -> str: """ Concatenates a list of strings with newline characters between them and returns the resulting multi-line string. Args: lines (List[str]): ...
magic_instruct_75k
51,588
Write a Python function to process the configuration for an optical character recognition (OCR) pipeline. The function should generate the absolute path for the folder where annotated images will be saved and calculate the total margin for the fields, including both horizontal and vertical margins. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python def process_ocr_config(folder_path: str, field_margin: float) -> (str, float): """ Processes the OCR configuration by generating the absolute path for the folder where annotated images will be saved and calculating the total...
magic_instruct_75k
51,641
Write a Python script to automate the management of Docker containers and instances of Elasticsearch. The script should perform the following tasks in sequence: 1. Stop all running instances of Elasticsearch using the script `stop_all.sc`. 2. Remove all existing instances of Elasticsearch using the script `remove_all_i...
Here is the Python code to solve the given problem in the markdown block: ```python import subprocess def manage_elasticsearch_and_docker(): """ Automates the management of Docker containers and Elasticsearch instances. This function performs the following tasks in sequence: 1. Stops all running insta...
magic_instruct_75k
51,645
Write a Python function to apply a lambda function represented as a string to each element in a list of integers. The function should take two parameters: a list of integers and a string representing a lambda function. The function should return a list of the results after applying the lambda function to each integer i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def apply_lambda(int_list: List[int], lambda_str: str) -> List[int]: """ Applies a lambda function represented as a string to each integer in the input list. Args: int_list (List[int]): A li...
magic_instruct_75k
51,651
Write a Python function to calculate the average brightness of a list of image paths. Each image path follows a specific format: "image_xxx.jpg", where "xxx" represents a three-digit number indicating the brightness level of the image. The function should extract the brightness level from each image path and compute th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def average_brightness(image_paths: List[str]) -> float: """ Calculate the average brightness of a list of image paths. Each image path follows the format "image_xxx.jpg", where "xxx" is a three-dig...
magic_instruct_75k
51,661
Write a Python function to filter a list of stock symbols based on their price-to-earnings (P/E) ratios and the presence of a specific character in the stock symbol. The function should return a list of stock symbols that meet the following criteria: 1. The P/E ratio should be less than or equal to 15. 2. The stock sym...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def screen_stocks(stocks: Dict[str, int]) -> List[str]: """ Filters a list of stock symbols based on their P/E ratios and the presence of a specific character in the symbol. Args: stoc...
magic_instruct_75k
51,671
Write a Python function to clean a search term by removing stop words from it. Stop words are common words (e.g., "the", "is", "in") that are often filtered out from search queries because they do not significantly contribute to the meaning of the query. The function should take a search term and a list of stop words a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def clean_search_term(search_term: str, stop_words: List[str]) -> str: """ Cleans a search term by removing stop words and normalizing spaces. Args: search_term (str): The search t...