source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_instruct_75k
51,721
Write a Python function to process a list of conditional statements and return the first "ask" condition encountered. The function should return an empty list if no "ask" condition is found. The code should start with: ```python from typing import List, Tuple def find_ask_condition(ifs: List[Tuple[str, ...]]) -> Tupl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_ask_condition(ifs: List[Tuple[str, ...]]) -> Tuple[str, ...]: """ Find and return the first "ask" condition in a list of conditional statements. Args: ifs (List[Tuple[str, .....
magic_instruct_75k
51,754
Write a Python function to calculate the minimum number of operations required to transform one string into another. The transformation is case-insensitive, and you can only perform one operation at a time: either insert a character, delete a character, or replace a character. The function should take in two strings `s...
Here is the Python code to solve the given problem in the markdown block: ```python def minEditDistance(source: str, target: str) -> int: """ Calculate the minimum number of operations required to transform the source string into the target string. The operations allowed are: insert a character, delete a ch...
magic_instruct_75k
51,759
Write a Python function to calculate the sum of all the even numbers in a given list. The function should take a list of integers as input and return the sum of all the even numbers in the list. If the list is empty or does not contain any even numbers, the function should return 0. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The su...
magic_instruct_75k
51,764
Write a Python function to find the height of the person who is neither the tallest nor the shortest in a given list of integers representing the heights of people standing in a line. The function should return the height of the person who is in the middle of the range of heights. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_middle_height(heights: List[int]) -> int: """ Find the height of the person who is neither the tallest nor the shortest in a given list of heights. Args: heights (List[int]): A list...
magic_instruct_75k
51,770
Write a Python function to count the occurrences of each favorite number in a given list of integers. The function should return a dictionary where the keys are the unique favorite numbers and the values are the counts of how many times each number appears in the list. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_favorite_numbers(favorites: List[int]) -> Dict[int, int]: """ Counts the occurrences of each favorite number in the given list. Args: favorites (List[int]): A list of integer...
magic_instruct_75k
51,773
Write a Python function `setLSB` that takes an integer `num` as input and sets the least significant bit (LSB) of this integer to the LSB of the player's nickname ID. The player's nickname ID is obtained from a `gg` object, which has two methods: `getNickname()` and `getNicknameID()`. The `getNickname()` method returns...
Here is the Python code to solve the given problem in the markdown block: ```python def setLSB(num: int) -> int: """ Sets the least significant bit (LSB) of the input integer `num` to the LSB of the player's nickname ID. Args: num (int): The integer whose LSB needs to be set. Returns: ...
magic_instruct_75k
51,783
Write a Python function to validate a given logging configuration dictionary. The function should check if the dictionary follows the expected structure and contains necessary keys and values. The logging configuration dictionary is expected to adhere to the structure defined by the Python logging module's `dictConfig`...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_logging_config(config_dict: dict) -> bool: """ Validates a given logging configuration dictionary to ensure it adheres to the expected structure. Args: config_dict (dict): A dictionary representing the ...
magic_instruct_75k
51,786
Write a Python function to count the number of dates in a list that are greater than or equal to a specified date. The dates are represented as strings in the format "YYYY-MM-DD". The specified date will also be provided as a string in the same format. Your function should consider dates greater than or equal to the sp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_dates_greater_or_equal(dates: List[str], specified_date: str) -> int: """ Counts the number of dates in the given list that are greater than or equal to the specified date. Args: d...
magic_instruct_75k
51,795
Write a Python function to simulate the process of adding a user to a group in a user pool. The function should take in the user pool ID, username, and group name as input parameters and return a response indicating the success or failure of the operation. The function should also handle cases where the user or group d...
Here is the Python code to solve the given problem in the markdown block: ```python def add_user_to_group(user_pool_id: str, username: str, group_name: str) -> str: """ Simulates the process of adding a user to a group in a user pool. Args: user_pool_id (str): The ID of the user pool. usern...
magic_instruct_75k
51,811
Write a Python function to validate the title of a book. The function should check if the title contains any words and if it has a non-zero length. If the title is valid, the function should return `True`; otherwise, it should return `False`. The function signature is: ```python def validate_title(title_data: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_title(title_data: str) -> bool: """ Validates the title of a book by checking if it contains any words and if it has a non-zero length. Args: title_data (str): The title of the book to be validated. ...
magic_instruct_75k
51,830
Write a Python function to calculate the sum of the squares of the even numbers in a given list of integers. The function should take a list of integers as input and return the sum of the squares of the even numbers in the list. If the list is empty or does not contain any even numbers, the function should return 0. T...
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(nums: List[int]) -> int: """ Calculate the sum of the squares of the even numbers in a given list of integers. Args: nums (List[int]): A list of integers. ...
magic_instruct_75k
51,897
Write a Python function to manage chunks of a game world in a Minecraft Pocket Edition (MCPE) server. The function should efficiently store and retrieve chunks based on their positions. Each chunk contains information such as its position, blocks, entities, and other relevant data. The function should also provide a me...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple, Any, List class Chunk: """ Represents a chunk of the game world. Attributes: position (Tuple[int, int]): The position of the chunk in the game world. blocks (Dict[Tuple[int, ...
magic_instruct_75k
51,898
Write a Python function to dynamically generate a setup configuration for a Python package based on the provided dictionary. The function should take a dictionary `package` as input and return the setup configuration as a formatted string. The dictionary contains various details about the package, such as its URL, down...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_setup_config(package: dict) -> str: """ Generates a setup configuration for a Python package based on the provided dictionary. Args: package (dict): A dictionary containing various package details. ...
magic_instruct_75k
51,902
Write a Python function to check the operating system and install a specific tool if the system is running on macOS. The tool to be installed is `realpath`, which resolves all symbolic links in a given path and prints the absolute path. The function should perform the following steps: 1. Check the operating system usin...
Here is the Python code to solve the given problem in the markdown block: ```python import platform import subprocess def install_realpath_on_macos(): """ Checks the operating system and installs the `realpath` tool on macOS. This function performs the following steps: 1. Checks if the operating syste...
magic_instruct_75k
51,909
Write a Python function to find the complementary DNA nucleotide for a given nucleotide. The function should take a single character representing a DNA nucleotide ('A', 'C', 'G', or 'T') as input and return its complementary nucleotide based on the following rules: - 'A' (adenine) pairs with 'T' (thymine) - 'C' (cytosi...
Here is the Python code to solve the given problem in the markdown block: ```python def complementary_nucleotide(nucleotide: str) -> str: """ Returns the complementary DNA nucleotide for a given nucleotide. Args: nucleotide (str): A single character representing a DNA nucleotide ('A', 'C', 'G', or ...
magic_instruct_75k
51,921
Write a Python function to implement a simple key-value store. The key-value store should have two methods: `get_value` and `set_value`. The `get_value` method should take a key as an argument and return the corresponding value if it exists, or `None` if the key is not found. The `set_value` method should take a key an...
Here is the Python code to solve the given problem in the markdown block: ```python def key_value_store(): """ Implements a simple key-value store using a dictionary. Returns: tuple: A tuple containing two functions: - set_value: A function to set a key-value pair in the store. ...
magic_instruct_75k
51,951
Write a Python function to count the occurrences of each type of migration operation in a list of migration operations. Each migration operation is represented as a tuple containing the operation type and the model name involved. The function should return a dictionary where the keys are the operation types and the val...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def count_migration_operations(migration_operations: List[Tuple[str, str, str]]) -> Dict[str, int]: """ Counts the occurrences of each type of migration operation in a list of migration oper...
magic_instruct_75k
51,962
Write a Python function to extract and return the unique set of all requirements across different dependency categories from a given dictionary. The dictionary `extras_require` represents package dependencies and their corresponding requirements. Each key in the dictionary represents a dependency category, and the valu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Set def extract_unique_requirements(extras_require: Dict[str, List[str]]) -> Set[str]: """ Extracts and returns the unique set of all requirements across different dependency categories. Args...
magic_instruct_75k
51,994
Write a Python function to parse a list of command-line arguments and extract the value of the "endpoint" argument if it is present. The "endpoint" argument is always followed by the URL endpoint value. If the "endpoint" argument is not present, the function should return an empty string. 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 parse_endpoint_argument(args: List[str]) -> str: """ Parses a list of command-line arguments and returns the value of the "endpoint" argument if present. Args: args (List[str]): A list o...
magic_instruct_75k
51,997
Create a Python class `OTP` that generates one-time passwords (OTPs) for a secure authentication system. The class should allow the user to set the length of the OTP and generate a random OTP of the specified length. The class should have the following specifications: - **Class Name**: `OTP` - **Attributes**: - `len...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string class OTP: def __init__(self): """ Initialize the OTP class with a default length of 6. """ self.length = 6 # Default length of the OTP def setLength(self, l: int): ...
magic_instruct_75k
52,040
Write a Python function to retrieve the phone code of a given country from a list of country-phone code pairs. The function should take in the country name as input and return the corresponding phone code. If the country name is not found in the list, the function should return "Not Found". The list of country-phone c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_phone_code(country_name: str, l_country_phone_code: List[str]) -> str: """ Retrieves the phone code of a given country from a list of country-phone code pairs. Args: country_name (st...
magic_instruct_75k
52,045
Implement a specialized stack data structure in Python that supports the following operations: `push`, `pop`, `peek`, and `getMin`. The stack should efficiently handle these operations in O(1) time complexity. The `peek` method should return the top element of the stack without removing it, and the `getMin` method shou...
Here is the Python code to solve the given problem in the markdown block: ```python class SpecializedStack: def __init__(self): """ Initialize the specialized stack with two lists: - stack: to store the elements of the stack - min_stack: to store the minimum elements """ ...
magic_instruct_75k
52,054
Write a Python function to calculate the maximum possible profit from buying and selling a single share of stock given a list of daily stock prices. If no profit is possible, return 0. The function should start with: ```python from typing import List def max_profit(prices: List[int]) -> int: ```
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 possible profit from buying and selling a single share of stock. Args: prices (List[int]): A list of integers representing...
magic_instruct_75k
52,061
Write a Python function to process a list of messages, each containing a specific command and text, and return the result of performing the command on the text. The messages follow a specific format: `<valid_message>:<command>:<text>`. If a message does not adhere to this format, it should be considered invalid. The f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def process_messages(n: int, messages: List[str]) -> List[str]: """ Processes a list of messages, each containing a specific command and text, and returns the result of performing the command o...
magic_instruct_75k
52,101
Write a Python function to filter out `None` values from a list of annotations and return a new list containing only the non-None annotations. The function should be named `filter_annotations` and should take a list of annotations as input. Each annotation can be of any type, including `None`. The function should retur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Any def filter_annotations(annotations: List[Optional[Any]]) -> List[Any]: """ Filters out None values from a list of annotations and returns a new list containing only the non-None annotation...
magic_instruct_75k
52,103
Write a Python function to determine the order in which software packages should be installed to satisfy their dependencies. The function should take a list of tuples as input, where each tuple represents a package and its dependencies. The first element of the tuple is the package name, and the second element is a lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def install_packages(packages: List[Tuple[str, List[str]]]) -> List[str]: """ Determine the order in which software packages should be installed to satisfy their dependencies. Args: p...
magic_instruct_75k
52,117
Write a Python function to replace occurrences of the placeholder `'%modname%'` with a specified module name in a list of folder prefixes. The function should modify the input list in place and return the modified list. The function should start with: ```python from typing import List def replace_modname(folder_prefix...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_modname(folder_prefixes: List[str], mod_name: str) -> List[str]: """ Replaces occurrences of the placeholder '%modname%' with the specified module name in the list of folder prefixes. Ar...
magic_instruct_75k
52,141
Write a Python function to find the maximum value for each unique "group" in a list of dictionaries. Each dictionary in the list contains a "group" key and a "value" key. The function should return a new list of dictionaries, where each dictionary contains the "group" and the maximum "value" for that group. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_max_values(input_list: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Find the maximum value for each unique "group" in a list of dictionaries. Args: input_list (List[Dict...
magic_instruct_75k
52,150
Write a Python function to convert a given tensor layout from its current format to a desired format. The tensor layout is represented as a string, e.g., "NCHW" or "OIHW", where each letter represents a dimension (e.g., N for batch size, C for channels, H for height, and W for width). The function should take the curre...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union def convert_layout(current_layout: str, desired_layout: str) -> Union[str, None]: """ Converts the current tensor layout to the desired layout if possible. Args: current_layout (str): The c...
magic_instruct_75k
52,156
Write a Python function to implement a simplified user account and wallet management system. The function should create a user account, generate a wallet for the user, and process a payment of 100 units from the user's wallet to another user's wallet. The function should use the provided helper functions: `create_accou...
Here is the Python code to solve the given problem in the markdown block: ```python def manage_user_account_and_payment(receiver_user_id: str) -> None: """ Manages the creation of a user account, generation of a wallet, and processing of a payment. Args: receiver_user_id (str): The ID of the user w...
magic_instruct_75k
52,157
Write a Python function to automate the build process for OpenCV with specific configuration options. The function should generate a shell script that sets the following build options and then runs the `make` command to compile the source code: - `BUILD_EXAMPLES` set to `OFF` - `BUILD_TESTS` set to `OFF` - `BUILD_DOCS`...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_opencv_build_script() -> str: """ Generates a shell script to automate the build process for OpenCV with specific configuration options. Returns: str: The generated shell script as a string. """ ...
magic_instruct_75k
52,166
Write a Python function to remove a specific entry from a list of dictionaries based on the provided `business_id` and `user_id`. Each dictionary in the list represents a business entity and contains the keys `business_id` and `user_id`. The function should take in the list of dictionaries, `business_id`, and `user_id`...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_entry(entries: list, business_id: int, user_id: int) -> list: """ Removes a specific entry from a list of dictionaries based on the provided `business_id` and `user_id`. Args: entries (list): A list of di...
magic_instruct_75k
52,184
Write a Python function to find the maximum score from a given list of integers representing the scores of a game. The function should return the maximum score. The code should start with: ```python from typing import List def find_max_score(scores: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_score(scores: List[int]) -> int: """ Find the maximum score from a given list of integers representing the scores of a game. Args: scores (List[int]): A list of integers represe...
magic_instruct_75k
52,191
Write a Python function to invert each string in a given list of strings. Inverting a string means reversing the order of its characters. The function should take a list of strings as input and return a new list where each string is inverted. The code should start with: ```python from typing import List def invert_st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def invert_strings(string_list: List[str]) -> List[str]: """ Inverts each string in the given list of strings. Args: string_list (List[str]): A list of strings to be inverted. Returns: ...
magic_instruct_75k
52,196
Write a Python function to calculate the sum of all even numbers in a given list. The function should take a list of integers as input and return the sum of all the even numbers in the list. If the list is empty or does not contain any even numbers, the function should return 0. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in a given list. Args: numbers (List[int]): A list of integers. Returns: int: The sum ...
magic_instruct_75k
52,218
Write a Python function to implement a custom linked list data structure that supports the basic operations of adding elements to the end of the list, removing elements from the list, and checking if a specific element is present in the list. The function should be implemented as a class named `CustomLinkedList` with m...
Here is the Python code to solve the given problem in the markdown block: ```python class CustomLinkedList: class Node: def __init__(self, data): self.data = data self.next = None def __init__(self): self.head = None self.count = 0 def add(self, data): ...
magic_instruct_75k
52,222
Write a Python function to format a dictionary of HTTP headers into a string where each header is represented as a key-value pair separated by a colon and a space, with each pair on a new line. The function should handle any dictionary of headers, including those with non-string values, and ensure that the output strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def format_headers(headers: Dict[str, str]) -> str: """ Formats a dictionary of HTTP headers into a string where each header is represented as a key-value pair separated by a colon and a space, with ...
magic_instruct_75k
52,225
Write a Python function to simulate a dice game where two dice are rolled. The function should calculate the sum of the two dice and determine if the two dice rolled the same number. If the two dice rolled the same number, the function should return "You rolled a double!". Otherwise, it should return the sum of the two...
Here is the Python code to solve the given problem in the markdown block: ```python import random def dice_game() -> str: """ Simulates rolling two six-sided dice, calculates their sum, and determines if the two dice rolled the same number. Returns: str: A string indicating whether the dice rolled...
magic_instruct_75k
52,227
Write a Python function to determine whether a given number is prime or not. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should take an integer input `n` and return a boolean value indicating whether `n` is prime or not. If `n` is not a positive ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determine whether a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ # ...
magic_instruct_75k
52,236
Write a Python function to extract the number of stars (represented by `<gh_stars>`) from a given code snippet. The number of stars is within the range of 10 to 100. The function should return the extracted number of stars as an integer. The code should start with: ```python def extract_stars(code_snippet: str) -> int...
Here is the Python code to solve the given problem in the markdown block: ```python def extract_stars(code_snippet: str) -> int: """ Extracts the number of stars from a given code snippet. The code snippet contains a pattern `<gh_stars>X-Y`, where X is the number of stars and Y is the upper limit of th...
magic_instruct_75k
52,245
Write a Python function to generate a specific pattern based on user input. The function should take an integer `n` as input and construct a string according to the following rules: - The string should consist of `n` lines. - Each line should contain a sequence of numbers from 1 to the line number, separated by "+" sig...
Here is the Python code to solve the given problem in the markdown block: ```python def generatePattern(n: int) -> str: """ Generates a pattern of strings based on the input integer `n`. The pattern consists of `n` lines, where each line contains a sequence of numbers from 1 to the line number, separat...
magic_instruct_75k
52,249
Write a Python function to validate a given profile dictionary based on specific rules. The profile dictionary contains keys representing different attributes, and each attribute's value is an object with attributes `opt` and `max`. Both `opt` and `max` are tuples of four integers. The function should validate the prof...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_profile(profile: dict) -> bool: """ Validate the given profile dictionary based on specific rules. Args: profile (dict): A dictionary where keys are attribute names and values are objects with attribute...
magic_instruct_75k
52,256
Write a Python function to count the number of unique signals received from a list of signals, considering case insensitivity. Each signal is represented as a string and may contain alphanumeric characters. The function should handle empty input lists by returning 0. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_signals(signals: List[str]) -> int: """ Counts the number of unique signals received from a list of signals, considering case insensitivity. Args: signals (List[str]): A lis...
magic_instruct_75k
52,270
Write a Python function to convert a string of key-value pairs into a dictionary. The input string is formatted as a series of key-value pairs separated by commas, with each key and value separated by a colon. The function should correctly parse this string and return a dictionary. Additionally, fix any bugs in the pro...
Here is the Python code to solve the given problem in the markdown block: ```python def fixture_data_item_to_dict(data_item: str) -> dict: """ Converts a string of key-value pairs into a dictionary. Args: data_item (str): A string containing key-value pairs separated by commas, ...
magic_instruct_75k
52,292
Write a Python function to calculate the sum of all even Fibonacci numbers up to a given limit. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones. The function should take an integer `limit` as input and return the sum of all even Fibonacci numbers that are less...
Here is the Python code to solve the given problem in the markdown block: ```python def even_fibonacci_sum(limit: int) -> int: """ Calculate the sum of all even Fibonacci numbers up to a given limit. Args: limit (int): The upper limit for the Fibonacci numbers to be considered. Returns: ...
magic_instruct_75k
52,294
Write a Python function to categorize a list of strings representing metadata tags into different groups based on their prefixes. Each tag has a prefix followed by a double colon (`::`) and a space, followed by the actual tag content. The function should return a dictionary where the keys are the prefixes and the value...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def categorize_tags(tags: List[str]) -> Dict[str, List[str]]: """ Categorizes a list of metadata tags into different groups based on their prefixes. Args: tags (List[str]): A list of s...
magic_instruct_75k
52,303
Write a Python function to construct a dictionary representing weather data from a meteorological station. The dictionary should include specific parameters such as the meteorological station code, surface level measurement, and coordinates. The function should take in the meteorological area code, surface level measur...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_weather_data(meteo_area: str, surface_level: float, px: int, py: int) -> dict: """ Constructs a dictionary representing weather data from a meteorological station. Args: meteo_area (str): The meteorolo...
magic_instruct_75k
52,305
Create a Python class `PacketEventLogger` that manages packet event logging for a real-time communication application. The class should have the following methods: - `InsertPacketEvent`: Logs a packet event with the given parameters. - `GetPacketEventsAndReset`: Retrieves all logged packet events and resets the log. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any class PacketEventLogger: def __init__(self): """ Initialize the PacketEventLogger with an empty dictionary to store packet events. """ self.packet_events: Dict[int,...
magic_instruct_75k
52,379
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, the function should return 0. The code should start with: ```python from typing import List d...
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
52,394
Write a Python function to reverse a given string in-place. The function should take a list of characters as input and reverse the characters within the list without using any additional memory (i.e., the reversal should be done within the same list). The code should start with: ```python from typing import List def r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_string_in_place(s: List[str]) -> None: """ Reverses the given list of characters in-place. Args: s (List[str]): The list of characters to be reversed. Returns: None:...
magic_instruct_75k
52,411
Write a Python function to calculate the last number in the Fibonacci sequence up to a given index. The function should handle invalid input gracefully and return the last number in the Fibonacci sequence up to the given index. The Fibonacci sequence is a series of numbers in which each number is the sum of the two pre...
Here is the Python code to solve the given problem in the markdown block: ```python def last_fibonacci(x: int) -> int: """ Calculate the last number in the Fibonacci sequence up to a given index. Args: x (int): The index up to which the Fibonacci sequence should be calculated. Returns: ...
magic_instruct_75k
52,434
Write a Python function to filter keyword arguments based on a specified prefix. The function should take a variable number of keyword arguments and return a dictionary containing only the keyword arguments whose keys start with the given prefix. If no keyword arguments match the prefix, the function should return an e...
Here is the Python code to solve the given problem in the markdown block: ```python def filter_kwargs_by_prefix(prefix: str, **kwargs) -> dict: """ Filters keyword arguments based on a specified prefix. Args: prefix (str): The prefix that the keys of the keyword arguments should start with. ...
magic_instruct_75k
52,436
Write a Python function to compare two version strings following the semantic versioning format. The function should return: - `1` if `version1` is greater than `version2` - `-1` if `version1` is less than `version2` - `0` if `version1` is equal to `version2` The version strings consist of three non-negative integers ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_versions(version1: str, version2: str) -> int: """ Compare two version strings following the semantic versioning format. Args: version1 (str): The first version string to compare. version2 (str):...
magic_instruct_75k
52,447
Write a Python function to decode a given cipher represented as a 2D array of characters. Each row in the cipher represents a word, and the characters in each row form the word. The original message is obtained by concatenating the decoded words in the order they appear in the cipher. The function should return the ori...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def decode_cipher(cipher: List[List[str]]) -> str: """ Decodes a given cipher represented as a 2D array of characters and returns the original message. Args: cipher (List[List[str]]): A 2D a...
magic_instruct_75k
52,462
Create a Python class `DynamicArray` that simulates a memory management system for a dynamic array. The class should provide the following functionality: 1. A constructor that initializes the array with a given size and allocates memory for it. 2. A method to access and modify elements of the array. 3. A method to resi...
Here is the Python code to solve the given problem in the markdown block: ```python class DynamicArray: def __init__(self, size: int): """ Initialize the DynamicArray with a given size. Args: size (int): The initial size of the array. """ self.size = size ...
magic_instruct_75k
52,482
Write a Python function that generates the content for a configuration file for a Backend as a Service (BAAS) platform called "EZYBAAS." The function should take several operational configuration settings as input and return a string that represents the content of the configuration file in the required format. The conf...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_config_file_content(baas_name: str, serializers_file_name: str, views_file_name: str, urls_file_name: str, models_file_name: str, tests_file_name: str) -> str: """ Generates the content for a configuration file for ...
magic_instruct_75k
52,488
Write a Python function `summarize_route` that processes a route object and returns a summary of the route in a specific format. The route object contains various details such as total distance, total time, node OSM IDs, points, edges, distances from the starting node, and times from the starting node. The function sho...
Here is the Python code to solve the given problem in the markdown block: ```python def summarize_route(route: dict) -> str: """ Summarizes the given route object into a formatted string. Args: route (dict): A dictionary containing route information with the following keys: - 'total_dis...
magic_instruct_75k
52,503
Write a Python function to identify fast-moving cryptocurrency markets based on price changes. The function should analyze historical and recent price data for each cryptocurrency and determine which cryptocurrencies have an average percentage price change greater than or equal to a predefined threshold. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def identify_fast_markets(prev_data: List[Dict], latest_data: Dict, config) -> List[str]: """ Identify fast-moving cryptocurrency markets based on price changes. Args: prev_data (List[...
magic_instruct_75k
52,516
Write a Python function to simulate a simple restaurant menu system. The menu system should allow the user to view the menu, add items to their order, view their current order, and place the order. Each menu item consists of a name, price, and a unique identifier. The user should be able to add multiple items to their ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple class MenuItem: def __init__(self, id: int, name: str, price: float): self.id = id self.name = name self.price = price class Restaurant: def __init__(self, menu: List[Menu...
magic_instruct_75k
52,532
Write a Python function to process and analyze gene annotation data. The gene annotation data is represented as a list of annotation objects, where each object contains information about gene annotations for a specific taxonomic identifier or annotation type. The function should return a summary of the gene annotations...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def process_gene_annotations(annoobjs: List[Any]) -> Dict[str, Any]: """ Processes a list of gene annotation objects and returns a summary of the gene annotations. Args: annoobjs ...
magic_instruct_75k
52,576
Write a Python function to convert a given length in yards to inches. The function should take a single parameter, the length in yards, and return the equivalent length in inches. The conversion factor is 36 inches per yard. The function should handle non-negative float values for the input. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def yards_to_inches(yards: float) -> float: """ Converts a given length in yards to inches. Args: yards (float): A non-negative number representing the length in yards. Returns: float: The equivalent le...
magic_instruct_75k
52,603
Write a Python function to simulate a login process that randomly chooses between a successful login and a failed login. The function should accept two callback functions: one for handling successful logins and another for handling failed logins. The successful login callback should receive a dummy user ID and a dummy ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Callable, Tuple import random def simulate_login(success_callback: Callable[[str, str], None], failure_callback: Callable[[str], None]) -> None: """ Simulates a login process that randomly chooses between a s...
magic_instruct_75k
52,622
Write a Python function to rotate a given 2D list (grid) by 90 degrees clockwise. The function should take the original grid as input and return the rotated grid. The grid is represented as a list of lists, where each inner list represents a row in the grid. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import copy def rotate_grid(grid: List[List[int]]) -> List[List[int]]: """ Rotates a given 2D list (grid) by 90 degrees clockwise. Args: grid (List[List[int]]): The original grid to be rotat...
magic_instruct_75k
52,634
Write a Python function to automate the installation of packages on a Linux system using the `apt-get` package manager. The function should handle potential errors during the installation process and provide appropriate feedback to the user. The function should take a list of package names as input and attempt to insta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import subprocess def install_packages(packages: List[str]) -> None: """ Automates the installation of packages on a Linux system using the `apt-get` package manager. Handles potential errors during ...
magic_instruct_75k
52,639
Write a Python function that simulates a simple messaging system. The function should take in a message as input and perform a series of transformations on the message before printing the final output. The transformations include converting all characters to uppercase, replacing all spaces with underscores, and appendi...
Here is the Python code to solve the given problem in the markdown block: ```python def message_transformer(message: str) -> str: """ Transforms the input message by converting all characters to uppercase, replacing all spaces with underscores, and appending a specific string to the end of the transform...
magic_instruct_75k
52,644
Write a Python function to extract the filename from a given FTP URL. The function should take a string representing an FTP URL as input and return the filename extracted from the URL. The FTP URL format is as follows: ``` ftp://<hostname>/<filename> ``` Where `<hostname>` represents the FTP server's hostname and `<fil...
Here is the Python code to solve the given problem in the markdown block: ```python def extract_filename_from_ftp_url(url: str) -> str: """ Extracts the filename from a given FTP URL. Args: url (str): The FTP URL from which to extract the filename. Returns: str: The filename extracted ...
magic_instruct_75k
52,660
Write a Python function to parse a given license file and extract the year and the license type from it. The license file is expected to be in a specific format. The function should take a string `license_text` as input and return a dictionary containing the year and the license type. The dictionary should have the key...
Here is the Python code to solve the given problem in the markdown block: ```python import re def parse_license_info(license_text: str) -> dict: """ Parses the given license text and extracts the year and the license type. Args: license_text (str): The text of the license file. Returns: ...
magic_instruct_75k
52,666
Write a Python function to manage a configuration directory containing multiple repositories. The function should list all repositories if no refinement is specified, and if a refinement is provided, it should list only the repositories matching the refinement. The function should be able to handle both cases: when the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import os import fnmatch def list_repositories(config_dir: str, refine: str = '') -> List[str]: """ List repositories in the given configuration directory. If a refinement pattern is provided, only r...
magic_instruct_75k
52,694
Write a Python function to validate a field value by removing leading and trailing whitespace and applying an optional encoding transformation. The default behavior should be an identity mapper, meaning the function should return the sanitized value as is if no encoding is specified. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_field(field_value: str, encoding=lambda x: x) -> str: """ Validates the field value by removing leading and trailing whitespace and applying an encoding transformation. Args: field_value (str): The valu...
magic_instruct_75k
52,701
Write a Python function to format derivatives of an apple pricing model into a specified string format. The function should take five input parameters representing the derivatives of various quantities with respect to the input price: `dprice`, `dapple_price`, `dtax`, `dapple`, and `dapple_num`. The function should ret...
Here is the Python code to solve the given problem in the markdown block: ```python def format_derivatives(dprice: float, dapple_price: float, dtax: float, dapple: float, dapple_num: float) -> str: """ Formats the derivatives of an apple pricing model into a specified string format. Args: dprice (f...
magic_instruct_75k
52,733
Write a Python function to generate a Cross-Origin Resource Sharing (CORS) configuration for a Flask application based on a list of allowed origins. The function should return a dictionary that represents the CORS configuration, allowing the specified origins to access all resources. The function should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union def generate_cors_config(allowed_origins: List[str]) -> Dict[str, Union[str, List[str]]]: """ Generates a CORS configuration for a Flask application based on a list of allowed origins. ...
magic_instruct_75k
52,734
Write a Bash script that automates the process of taking a snapshot of a Btrfs subvolume, tearing down running Docker containers, creating the snapshot, and then bringing the Docker containers back up. The script should take three input variables: - `$var1`: The path to the directory containing the Docker Compose file....
Here is the Python code to solve the given problem in the markdown block: ```bash #!/bin/bash # Input variables var1="/path/to/docker/compose/directory" var2="/source/subvolume" var3="/destination/subvolume" # Function to handle errors handle_error() { echo "Error: $1" >&2 exit 1 } # Change to the Docker Com...
magic_instruct_75k
52,737
Write a Python function to process a collection of parent-child relationships and return a mapping of each parent to its corresponding children. Each relationship is represented as a tuple containing a parent and a child. The function should handle multiple children for the same parent and ensure that each parent is ma...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def process_relationships(relationships: List[Tuple[str, str]]) -> Dict[str, List[str]]: """ Processes a collection of parent-child relationships and returns a mapping of each parent to its ...
magic_instruct_75k
52,744
Write a Python function to insert a new interval into a list of non-overlapping intervals sorted by their start times, and merge any overlapping intervals if necessary. The function should return the updated list of intervals after the new interval has been inserted and merged if necessary. 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 insert_interval(intervals: List[List[int]], new_interval: List[int]) -> List[List[int]]: """ Insert a new interval into a list of non-overlapping intervals sorted by their start times, and merge ...
magic_instruct_75k
52,757
Write a Python function to simulate the behavior of the `sys.path.insert` method. The function should take in a list of directories, a new directory to be inserted, and an index at which to insert the new directory. If the index is out of range, the new directory should be appended to the end of the list. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def simulate_sys_path_insert(directories: List[str], new_directory: str, index: int) -> List[str]: """ Simulates the behavior of the `sys.path.insert` method by inserting a new directory at the specified...
magic_instruct_75k
52,764
Write a Python function to count the occurrences of each character in a given list of strings. Each string in the list represents a single character. The function should return a dictionary where the keys are the unique characters and the values are the number of times each character appears in the list. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_occurrences(data: List[str]) -> Dict[str, int]: """ Counts the occurrences of each character in a given list of strings. Args: data (List[str]): A list of strings where each ...
magic_instruct_75k
52,767
Write a Python function to validate the correctness of a given string containing various types of brackets. The function should return `True` if the brackets are balanced and properly nested, and `False` otherwise. The types of brackets to consider are `(`, `)`, `[`, and `]`. The code should start with: ```python def ...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_brackets(input_str: str) -> bool: """ Validates the correctness of a given string containing various types of brackets. Args: input_str (str): The string to validate. Returns: bool: True if...
magic_instruct_75k
52,775
Write a Python function to determine the maximum depth of nesting in a given code snippet that contains nested braces `{}`. The function should take a string as input and return an integer representing the maximum depth of nesting. The code should start with: ```python def max_nesting_depth(code_snippet: str) -> int: ...
Here is the Python code to solve the given problem in the markdown block: ```python def max_nesting_depth(code_snippet: str) -> int: """ Calculate the maximum depth of nested braces in a given code snippet. Args: code_snippet (str): A string containing nested braces '{}'. Returns: int:...
magic_instruct_75k
52,786
Write a Python function to process and validate a GAN (Generative Adversarial Network) configuration dictionary. The function should ensure that the configuration dictionary is valid and ready for use in the GAN model. The configuration dictionary has the following structure: ```python { "num_classes": Optional[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any, Optional def process_gan_config(gan_config: Dict[str, Any]) -> Dict[str, Any]: """ Processes and validates a GAN configuration dictionary. Args: gan_config (Dict[str, Any]): The GAN co...
magic_instruct_75k
52,802
Write a Python function `processTableSelection` that simulates the behavior of a method that handles the event when a value is changed in a table. The function should extract specific information from the selected row of the table and return it as a dictionary. The function should take the following parameters: - `tabl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def processTableSelection(tableData: List[List[str]], selectedRow: int) -> Dict[str, str]: """ Extracts specific information from the selected row of a table and returns it as a dictionary. Ar...
magic_instruct_75k
52,805
Write a Python function to simulate a soccer game using the HFO (Half-Field Offense) framework. The function should take in the `game_interface`, `action_type`, `position_x`, `position_y`, and `power` as input parameters, and use the HFO framework to perform a kick action in the soccer game environment. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python def perform_kick_action(game_interface, action_type, position_x, position_y, power): """ Simulates a soccer game action using the HFO framework. Args: game_interface: An instance of the HFO game interface. a...
magic_instruct_75k
52,807
Write a Python function to count the number of vowels and consonants in a given string. The function should be case-insensitive and should consider the English alphabet. The vowels are defined as 'a', 'e', 'i', 'o', 'u'. All other alphabetic characters are considered consonants. The function should return a dictionary ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels_consonants(input_string: str) -> dict: """ Counts the number of vowels and consonants in the given input string. Args: input_string (str): The input string to process. Returns: dict: A ...
magic_instruct_75k
52,824
Write a Python function to escape special characters in a given file name. The function should replace spaces with `'\ '`, left parentheses `'('` with `'\('`, and right parentheses `')'` with `'\)'`. The function should handle any string input representing a file name and return the properly escaped file name. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def escapeFileName(name: str) -> str: """ Escapes spaces and parentheses in a given file name. Args: name (str): The file name to be escaped. Returns: str: The escaped file name with spaces replaced by ...
magic_instruct_75k
52,832
Write a Python function to process a log file containing lines of data representing connections between ports and devices. Each line consists of two items: the port and the device connected to it. The function should return the port connected to a known device, assuming that only one device is used at a time. If no kno...
Here is the Python code to solve the given problem in the markdown block: ```python def find_connected_port(log_file: str) -> str: """ Processes a log file to find the port connected to a known device. Args: log_file (str): A string representing the contents of the log file. ...
magic_instruct_75k
52,843
Write a Python function to count the number of points within a given radius of a specific point in a 2D plane. The function should take in a list of points and their coordinates, as well as the radius and the coordinates of the center point. The function should return the count of points that fall within the specified ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math def vdist(point1: Tuple[float, float], point2: Tuple[float, float]) -> float: """ Calculate the Euclidean distance between two points in a 2D plane. Args: point1 (Tuple[fl...
magic_instruct_75k
52,871
Write a Python function to check if a given string `code` matches a specific pattern defined by a regular expression. The pattern is designed to auto-assign tags to financial transactions based on the code. The pattern should be as follows: - The code should start with a number in the range 100-899, followed by a comma...
Here is the Python code to solve the given problem in the markdown block: ```python import re def check_tag_compliance(code: str) -> bool: """ Check if the given code matches the specified pattern for auto-assigning tags to financial transactions. The pattern is defined as follows: - The code should s...
magic_instruct_75k
52,872
Write a Python function to calculate the Euclidean distance between two points in a 2D plane. Each point is represented as a tuple of two elements, where the first element is the x-coordinate and the second element is the y-coordinate. The function should take two tuples as input and return the distance between them. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import math def calculate_distance(p1: Tuple[float, float], p2: Tuple[float, float]) -> float: """ Calculate the Euclidean distance between two points in a 2D plane. Args: p1 (Tuple[float, ...
magic_instruct_75k
52,878
Write a Python function to process a list of event settings and return a dictionary containing the settings grouped by their keys. Each event setting is represented as a dictionary with the keys "object", "key", and "value". The function should group the settings by their keys and return a dictionary where the keys are...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def group_event_settings(event_settings: List[Dict[str, str]]) -> Dict[str, List[Dict[str, str]]]: """ Groups event settings by their keys. Args: event_settings (List[Dict[str, str]]):...
magic_instruct_75k
52,898
Write a Python function to calculate the size of a range of elements for various types of ranges, including lists, tuples, and custom range types. The function should be able to handle different types of ranges and return the size of the range. The code should start with: ```python from typing import Any, Union def c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Union def calculate_range_size(range_obj: Union[list, tuple, range]) -> int: """ Calculate the size of a range of elements for various types of ranges. Args: range_obj (Union[list, tuple, ra...
magic_instruct_75k
52,909
Write a Python function to calculate the total amount of data transferred into the network, out of the network, and within the network from a list of log entries. Each log entry is a dictionary with keys `"timestamp"`, `"source_ip"`, `"destination_ip"`, `"data_in"`, `"data_out"`, and `"data_us"`. If the data is not ava...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_total_data(log_entries: List[Dict[str, str]]) -> Dict[str, int]: """ Calculate the total amount of data transferred into the network, out of the network, and within the network from a...
magic_instruct_75k
52,917
Create a Python function to manage a data structure that stores information about various tasks, their associated models, and the runtime environment for each model. The function should allow for efficient retrieval and manipulation of this information. Specifically, the function should support the following operations...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Optional def task_model_index() -> Dict[str, Dict[str, str]]: """ Returns a dictionary to store tasks, models, and runtimes. """ return {} def add_task_model_runtime(index: Dict[str, Dict[str, ...
magic_instruct_75k
52,947
Write a Python function to process a list of strings representing programming language classifiers and return a dictionary containing the count of each unique programming language and its corresponding implementations. Each string in the input list is formatted as "Programming Language :: Language Name :: Implementatio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_language_implementations(classifiers: List[str]) -> Dict[str, Dict[str, int]]: """ Processes a list of strings representing programming language classifiers and returns a dictionary c...
magic_instruct_75k
52,950
Write a Python function `process_account_data(bank, account_id)` that retrieves specific information from the Open Banking API response and performs some operations on it. The function should take in two parameters: - `bank`: A string representing the bank name. - `account_id`: A string representing the account ID. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_account_data(bank: str, account_id: str) -> List[str]: """ Retrieves and processes account attributes from the Open Banking API. Args: bank (str): The name of the bank. a...
magic_instruct_75k
52,970
Write a Python function to calculate the mean of a list of numbers. The mean of a list of numbers is calculated by finding the sum of all the numbers in the list and then dividing the sum by the total number of elements in the list. The function should handle both integer and floating-point numbers. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mean(num_list: List[float]) -> float: """ Calculates the mean of a list of numbers. Args: num_list (List[float]): A list of numbers (integers or floating-point numbers). R...
magic_instruct_75k
52,978
Write a Python function to extract and return the verbose names of models along with their associated plural verbose names from a list of model options. Each model option is represented as a dictionary containing the name of the model and its corresponding options. The function should handle cases where the options dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def extract_verbose_names(model_options: List[Dict[str, Dict[str, str]]]) -> Dict[str, str]: """ Extracts and returns the verbose names of models along with their associated plural verbose names. ...
magic_instruct_75k
52,982
Write a Python function to calculate the exponential value of a given number `x` using the Taylor series expansion up to a specified number of terms `n`. The Taylor series expansion for the exponential function is given by: \[ e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \ldots \] The function sho...
Here is the Python code to solve the given problem in the markdown block: ```python def exp(x: float, n: int) -> float: """ Calculate the exponential value of a given number `x` using the Taylor series expansion up to `n` terms. The Taylor series expansion for the exponential function is: e^x = 1 + x +...
magic_instruct_75k
52,993
Write a Python function to verify whether a user belongs to a specific set of groups. The function should take in a user object and a list of group objects, and return `True` if the user is a member of all the specified groups, and `False` otherwise. The user object has a method `groups.all()` which returns a queryset...
Here is the Python code to solve the given problem in the markdown block: ```python def verify_user_groups(user, group_list): """ Verifies whether a user belongs to all the specified groups. Args: user: An object representing the user, which has a method `groups.all()` that returns a queryset of al...
magic_instruct_75k
52,997
Write a Python function to process an INI file content and update the configuration options based on the provided command-line arguments. The function should handle the following command-line options: `--delay`, `--hours`, `--minutes`, and `--seconds`. The INI file should initially have default values for these options...
Here is the Python code to solve the given problem in the markdown block: ```python import re def process_ini_file(ini_content: str, delay: int, hours: int, minutes: int, seconds: int) -> str: """ Processes an INI file content and updates the configuration options based on the provided command-line arguments. ...
magic_instruct_75k
53,014
Write a Python function to generate the necessary code to define a custom admin interface for a given model in a web application. The function should take the name of the model, the module where the model is defined, and the name of the custom admin class as parameters. The function should return a string that represen...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_admin_interface(model_name: str, module_name: str, admin_class_name: str) -> str: """ Generates the necessary code to define a custom admin interface for a given model. Args: model_name (str): The name ...
magic_instruct_75k
53,018
Write a Python function to generate a formatted citation string following the APA (American Psychological Association) style. The function should take in a title, author, year, and web address, and return a string that includes the author's last name, the publication year, the title of the work, and the source from whi...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_citation(title: str, author: str, year: str, web_address: str) -> str: """ Generates a formatted citation string in APA style. Args: title (str): The title of the work. author (str): The full na...