source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_instruct_75k
44,967
Write a Python function `simulate_button_clicks(buttons)` that takes a list of button names as input and returns the sequence of button clicks as a list of strings. The function should simulate the behavior of clicking each button in the list in the order they are given. The function should handle the following button ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def simulate_button_clicks(buttons: List[str]) -> List[str]: """ Simulate the behavior of clicking buttons in a web application and return the sequence of button clicks as log messages. Args: ...
magic_instruct_75k
44,979
Write a Python function to calculate the nth Fibonacci number using dynamic programming. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should take an integer `n` as input and return the nth Fibonacci number. The funct...
Here is the Python code to solve the given problem in the markdown block: ```python def fib_dp(n: int) -> int: """ Calculate the nth Fibonacci number using dynamic programming. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The nth Fibonacci number. ...
magic_instruct_75k
44,991
Create a Python function that processes a list of migration operations and extracts specific information from it. Each migration operation is represented as a tuple containing the app label and the migration name. The function should extract the app labels and return them as a set. 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, Tuple, Set def extract_app_labels(operations: List[Tuple[str, str]]) -> Set[str]: """ Extracts unique app labels from a list of migration operations. Args: operations (List[Tuple[str, str]]...
magic_instruct_75k
45,003
Write a Python function to simulate the execution of a series of scripts represented by strings. The function should return the index of the first script that fails (returns a non-zero value). If all scripts execute successfully, the function should return -1. The function should use a helper function `runScript` to si...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def runScript(script: str) -> int: """ Simulated function to execute the script and return the result. Args: script (str): The script to be executed. Returns: int: The r...
magic_instruct_75k
45,010
Write a Python function to count the number of columns in a table configuration that are both non-orderable and non-searchable. The configuration is provided as a JSON object (represented as a Python dictionary). Each column is described by its index, whether it is orderable, and whether it is searchable. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_non_orderable_non_searchable_columns(config: dict) -> int: """ Counts the number of columns in the table configuration that are both non-orderable and non-searchable. Args: config (dict): A dictionary repr...
magic_instruct_75k
45,028
Write a Python function to find the most frequently occurring target string from a given list of target strings. If there are multiple target strings with the same highest frequency, return the one that appears first in the list. The function should start with: ```python from typing import List def most_frequent_targe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def most_frequent_target(targets: List[str]) -> str: """ Returns the most frequently occurring target string from the given list. If there are multiple target strings ...
magic_instruct_75k
45,030
Write a Python function to compare two strings based on the specified case sensitivity. The function should take two strings and a case sensitivity flag as input, and return `True` if the strings are equal based on the given sensitivity, and `False` otherwise. The case sensitivity flag can be either `'sensitive'` for c...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(str1: str, str2: str, sensitivity: str) -> bool: """ Compare two strings based on the specified case sensitivity. Args: str1 (str): The first string to compare. str2 (str): The second str...
magic_instruct_75k
45,032
Write a Python function to generate a command string based on a given directive dictionary. The directive dictionary contains information about a command to be executed, including the command template, model ID, and output directory. Your function should replace the template placeholders with actual values provided as ...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_command(directive: dict, fertilizer_scenario: str, sowing_scenario: str, weather_year: str) -> str: """ Generates a command string by replacing placeholders in the command template with actual values. Args: ...
magic_instruct_75k
45,039
Write a Python function to determine the final position of a robot on a grid after executing a series of commands. The robot starts at position (0, 0) and can move in four directions: up ('U'), down ('D'), left ('L'), and right ('R'). Each command moves the robot one unit in the specified direction. The function should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def finalPosition(commands: str) -> Tuple[int, int]: """ Determine the final position of a robot on a grid after executing a series of commands. The robot starts at position (0, 0) and can move in ...
magic_instruct_75k
45,041
Write a Python function to calculate the gap (difference between the highest and lowest values) for each key in a given dictionary of results. The function should return a new dictionary containing the calculated gaps for each key. The code should start with: ```python from typing import Dict, List def calculate_gaps...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def calculate_gaps(results_dict: Dict[str, List[int]]) -> Dict[str, int]: """ Calculate the gap (difference between the highest and lowest values) for each key in the given dictionary of results. ...
magic_instruct_75k
45,043
Create a Python class `SearchManager` that efficiently manages advanced search fields in a web application. Each search field can have various types such as strings, numbers, select options, cascading selections, remote searches, and date/time pickers. Each type of search field has its own set of additional properties....
Here is the Python code to solve the given problem in the markdown block: ```python class SearchManager: def __init__(self): """ Initialize the SearchManager with an empty dictionary to store search fields and their properties. """ self.fields = {} def add_field(self, field_type...
magic_instruct_75k
45,046
Write a Python function to convert class names from a Python convention to a PHP convention. The Python convention uses underscores (_) to separate words, while the PHP convention uses camel case with the first letter of each word capitalized. The function should replace any occurrences of hyphens (-), periods (.), and...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_php_convention(s: str) -> str: """ Converts a class name from Python convention to PHP convention. The Python convention uses underscores (_) to separate words, while the PHP convention uses camel case with t...
magic_instruct_75k
45,053
Write a Python function to simulate the behavior of the given bash script. The function should: 1. Check if the file `${HOME}/.cargo/env` exists. 2. If the file exists, simulate sourcing it by printing a message indicating that the file has been sourced. 3. If the file does not exist, print an error message indicating ...
Here is the Python code to solve the given problem in the markdown block: ```python import os def simulate_source_env_file() -> None: """ Simulates the behavior of sourcing a specific environment file located at `${HOME}/.cargo/env`. This function checks if the file exists and prints a message indicating ...
magic_instruct_75k
45,074
Write a Python function to determine if a given string is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The input string may contain both uppercase and lowercase letters, as well as punctuation and spaces. The function should return `True` if the input string is a pangram,...
Here is the Python code to solve the given problem in the markdown block: ```python def is_pangram(s: str) -> bool: """ Determine if the given string is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. This function checks if the input string contains all the...
magic_instruct_75k
45,092
Write a Python function to generate a command-line argument list for launching a LibreOffice instance with specific configurations. The function should take the port number as a parameter and construct the argument list accordingly. The command-line argument list should include the following elements: 1. `--nologo`: Th...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_libreoffice_args(port: int) -> list: """ Generates a command-line argument list for launching a LibreOffice instance with specific configurations. Args: port (int): The port number to be used for the so...
magic_instruct_75k
45,103
Write a Python function to process a list of URL patterns and return a dictionary containing the count of unique view names for each URL path. Each URL pattern is represented as a string in the format 'app_name/view_name/', and the view name is always the last component of the URL pattern. The function should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_view_names(url_patterns: List[str]) -> Dict[str, int]: """ Processes a list of URL patterns and returns a dictionary containing the count of unique view names for each URL path. Args...
magic_instruct_75k
45,106
Write a Python function to validate and process input parameters for managing AWS CloudFormation stacks and Auto Scaling Groups. The function will receive input parameters and must perform validation checks on these parameters before proceeding with any further actions. The input parameters are as follows: - `exit_cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def validate_and_process_parameters(exit_code: str, region: str, stack_name: str, stack_tag: str, auto_scaling_group: str, is_sub_stack: bool) -> Dict[str, Any]: """ Validates and processes input pa...
magic_instruct_75k
45,125
Write a Python function to calculate the sum of all even numbers in a given list of integers. If the input list is empty or does not contain any even numbers, the function should return 0. The code should start with: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list of integers. Args: numbers (List[int]): A list of integers. Returns: ...
magic_instruct_75k
45,141
Write a Python function `process_file` that processes a file based on its corresponding ID. The function should take two parameters: `file_name` (a string representing the name of the file to be processed) and `file_id` (an integer representing the ID corresponding to the file). The function should return a string indi...
Here is the Python code to solve the given problem in the markdown block: ```python def process_file(file_name: str, file_id: int) -> str: """ Processes a file based on its corresponding ID and returns the result of the processing. Args: file_name (str): The name of the file to be processed. ...
magic_instruct_75k
45,162
Create a Python class hierarchy to represent geometric shapes, including an abstract base class `Shape` and two concrete subclasses `Rectangle` and `Circle`. The `Shape` class should define abstract methods for calculating the area and perimeter of a shape, which must be implemented by its subclasses. The `Rectangle` c...
Here is the Python code to solve the given problem in the markdown block: ```python from abc import ABC, abstractmethod import math class Shape(ABC): """ Abstract base class representing a geometric shape. This class defines two abstract methods: - calculate_area: To be implemented by subclasses to ca...
magic_instruct_75k
45,177
Write a Python function to simulate the gathering of items from a creature by a mountain in a virtual world simulation. The function should take a list of items that the creature possesses and a list of items that the mountain has gathered so far. The function should simulate the process of the mountain gathering items...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def gather_items(creature_items: List[str], gathered_items: List[str]) -> List[str]: """ Simulates the gathering of items from a creature by a mountain. Args: creature_items (List[str]): A l...
magic_instruct_75k
45,183
Write a Python function to automate the installation of Docker on a Debian-based system. The function should add the Docker repository, including the necessary GPG key, and configure the package manager to install Docker from the added repository. The function should perform the following steps: 1. Verify that no argum...
Here is the Python code to solve the given problem in the markdown block: ```python def install_docker(): """ Automates the installation of Docker on a Debian-based system by adding the Docker repository and GPG key. This function performs the following steps: 1. Verifies that no arguments are passed t...
magic_instruct_75k
45,210
Write a Python function to extract and print the alphabets from a Conditional Random Field (CRF) object. The CRF object, `crf`, has methods `GetInputAlphabet()`, `GetOutputAlphabet()`, and `GetWeightsAlphabet()` which return the input, output, and weights alphabets respectively. The alphabets are to be printed to an ou...
Here is the Python code to solve the given problem in the markdown block: ```python def PrintCRFAlphabets(crf, out): """ Extracts and prints the alphabets from a CRF object to an output stream. Args: crf: A CRF object with methods `GetInputAlphabet()`, `GetOutputAlphabet()`, and `GetWeightsAlphabet...
magic_instruct_75k
45,213
Create a Python class `TaskManager` that manages tasks by registering and storing information about them. The class should provide methods to register a new task and check if a task with a given name has been registered. Each task should store its name, description, program path, working directory, and arguments. The ...
Here is the Python code to solve the given problem in the markdown block: ```python class TaskManager: def __init__(self): """ Initializes the TaskManager with an empty dictionary to store tasks. """ self.tasks = {} def registerTask(self, taskName: str, taskDescription: str, pro...
magic_instruct_75k
45,223
Write a Python function called `simulate_dice_game(num_players, num_rounds)` that simulates a simple game of dice rolling. The function should take in two parameters: - `num_players`: an integer representing the number of players in the game (2 <= num_players <= 6). - `num_rounds`: an integer representing the number of...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def simulate_dice_game(num_players: int, num_rounds: int) -> List[int]: """ Simulates a dice game for a specified number of players and rounds. Args: num_players (int): The num...
magic_instruct_75k
45,233
Write a Python function to count the number of valid phrases in a given list, where a valid phrase is one that does not match a provided regular expression pattern. The function should take two parameters: - `phrases`: a list of strings representing phrases - `invalid_re`: a compiled regular expression pattern represen...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List def count_valid_phrases(phrases: List[str], invalid_re: re.Pattern) -> int: """ Count the number of valid phrases in a list that do not match a given regular expression pattern. Args: ...
magic_instruct_75k
45,240
Create a Python class `ScheduledTask` to manage a scheduled task. The class should have methods to view the configuration of the task and to set its running status. The task has attributes for the time it should run, including `on_time`, `on_hour`, and `on_minute`, as well as a boolean attribute `is_running` to indicat...
Here is the Python code to solve the given problem in the markdown block: ```python class ScheduledTask: def __init__(self, on_time, on_hour, on_minute): """ Initialize a ScheduledTask instance. Args: on_time (str): The time the task should run in the format 'HH:MM'. ...
magic_instruct_75k
45,259
Write a Python function to detect a cycle in a singly linked list using Floyd's Tortoise and Hare algorithm. The function should take the head of the linked list as input and return `True` if there is a cycle in the linked list, otherwise it should return `False`. A cycle in a linked list occurs when a node's `next` po...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def hasCycle(head: ListNode) -> bool: """ Detects if there is a cycle in a singly linked list using Floyd's Tortois...
magic_instruct_75k
45,267
Write a Python function to process a list of dictionaries containing tweet data and calculate the total number of retweets and original tweets. Each dictionary in the list represents a tweet and has the following structure: ```python { 'id': <tweet_id>, 'retweets': <number_of_retweets>, 'original': <is_orig...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_tweet_stats(tweets: List[Dict[str, any]]) -> Dict[str, int]: """ Calculate the total number of retweets, original tweets, and the total number of tweets from a list of tweet dictionar...
magic_instruct_75k
45,268
Write a Python function to convert a given integer to its Roman numeral representation. The function should adhere to the standard rules of Roman numerals, including subtractive notation and the maximum repetition of symbols. The input integer `num` will be between 1 and 3999 inclusive. The function should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_roman(num: int) -> str: """ Converts a given integer to its Roman numeral representation. Args: num (int): The integer to be converted, between 1 and 3999 inclusive. Returns: str: The Roman n...
magic_instruct_75k
45,300
Write a Python function `validate_arguments` that processes and validates arguments for various methods in the Foundation framework of macOS/iOS development. The function should take a list of tuples as input, where each tuple contains the method being validated, the index of the argument being validated, and the expec...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def validate_arguments(validation_details: List[Tuple[str, int, str]]) -> List[str]: """ Generates validation assertions for method arguments in the Foundation framework. Args: valida...
magic_instruct_75k
45,310
Write a Python function to calculate the maximum accepted length of application protocol data units (APDUs) and the maximum accepted number of segments for a communication protocol. The function should take in a list of test cases and return the maximum values for both APDU length and segments. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_max_values(test_cases: List[Tuple[int, int]]) -> Tuple[int, int]: """ Calculate the maximum accepted APDU length and the maximum accepted number of segments from a list of test c...
magic_instruct_75k
45,311
Create a Python function to manage compartments affected by burn wounds in a medical simulation software. The function should allow adding new compartments to the list of affected compartments and retrieving the list of affected compartments. The code should start with: ```python from typing import List class SEBurnW...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List class SEBurnWound: def __init__(self): """ Initialize the list to store affected compartments. """ self.m_compartmentsAffected = [] def SetCompartment(self, name: str) ->...
magic_instruct_75k
45,312
Write a Python function to reverse the order of words in a given string. A word is defined as a sequence of non-space characters. The input string may contain leading, trailing, or multiple consecutive spaces between words. The function should handle these cases and return the reversed string with the words in reverse ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words(s: str) -> str: """ Reverses the order of words in a given string. Args: s (str): The input string containing words to be reversed. Returns: str: The string with the words in reverse o...
magic_instruct_75k
45,323
Write a Python function to extract the decimal parts of a list of floating-point numbers and round them to 2 decimal places. The function should handle both positive and negative floating-point numbers. The code should start with: ```python from typing import List def extract_decimals(numbers: List[float]) -> List[flo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_decimals(numbers: List[float]) -> List[float]: """ Extracts the decimal parts of a list of floating-point numbers and rounds them to 2 decimal places. Args: numbers (List[float])...
magic_instruct_75k
45,340
Write a Python function to calculate the sentiment score for a given sentence using a bigram model. The bigram model is represented as a dictionary where the keys are the first words in the bigrams, and the values are dictionaries containing the second words as keys and their corresponding tags and scores. The sentimen...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def calculate_sentiment_score(bigram: Dict[str, Dict[str, Dict[str, Any]]], sentence: str) -> float: """ Calculate the sentiment score for a given sentence using a bigram model. Args: b...
magic_instruct_75k
45,349
Write a Python function to find the maximum length of a contiguous subarray such that the product of all elements in the subarray is less than or equal to a given power limit. The function should take a list of non-negative integers representing the power of electronic devices and an integer `powerlimit` representing t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_contiguous_subarray_length(power: List[int], powerlimit: int) -> int: """ Find the maximum length of a contiguous subarray such that the product of all elements in the subarray is less than o...
magic_instruct_75k
45,399
Write a Python function to simulate a simplified version of a linked list. The function should support the following operations: 1. `push_back(value)`: Add a new node with the given value to the end of the list. 2. `pop_back()`: Remove the last node from the list. 3. `get_size()`: Return the current size of the list. ...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, value): self.value = value self.next = None class LinkedList: def __init__(self): self.head = None self.size = 0 def push_back(self, value): """ ...
magic_instruct_75k
45,410
Write a Python function to validate and process image uploads for a gallery application. The function should ensure that the uploaded images are within the maximum file size limit and that the containers for the images are public if specified by authenticated users. The function should return a tuple indicating whether...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_and_process_image_upload(image_data: bytes, container_name: str) -> tuple: """ Validates and processes an image upload for a gallery application. Args: image_data (bytes): A byte string representing the...
magic_instruct_75k
45,448
Write a Python function to count the number of lines in a given file content that start with a specific prefix. The function should take two parameters: 1. A string `file_content` representing the content of the file. 2. A string `prefix` representing the prefix to search for at the beginning of each line. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python def count_lines_with_prefix(file_content: str, prefix: str) -> int: """ Counts the number of lines in the given file content that start with the specified prefix. Args: file_content (str): The content of the file as...
magic_instruct_75k
45,465
Write a Python function to generate the necessary commands to configure the installed NVIDIA drivers within a container environment. The function should take the NVIDIA installation directory as input and output a string containing the commands to configure the installed NVIDIA drivers. The commands should include sett...
Here is the Python code to solve the given problem in the markdown block: ```python def configure_nvidia_drivers(nvidiaInstallDir: str) -> str: """ Generates the necessary commands to configure the installed NVIDIA drivers within a container environment. Args: nvidiaInstallDir (str): A string repre...
magic_instruct_75k
45,471
Write a Python function to process a list of integers and return a tuple containing the sum of all even numbers and the count of all odd numbers in the list. The function should be named `process_numbers` and should take a single parameter, `numbers`, which is a list of integers. The function should return a tuple wher...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def process_numbers(numbers: List[int]) -> Tuple[int, int]: """ Processes a list of integers and returns a tuple containing the sum of all even numbers and the count of all odd numbers in the ...
magic_instruct_75k
45,497
Write a Python function to display the IP address and name of each virtual machine in a cloud environment. The IP addresses and names of the virtual machines are stored in a dictionary. The function should print each virtual machine's details in the following format: ``` IP Address: 10.0.0.1, VM Name: web-server IP Ad...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def display_vm_details(vm_details: Dict[str, str]) -> None: """ Displays the IP address and name of each virtual machine in the given dictionary. Args: vm_details (Dict[str, str]): A diction...
magic_instruct_75k
45,504
Write a Python function to generate a migration file for a Django project. The migration file should include the necessary dependencies and operations to modify the database schema. The function should take the name of the app and the previous migration file name as input and return the content of the migration file as...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_migration_file(app_name: str, previous_migration: str) -> str: """ Generates the content of a Django migration file based on the provided app name and previous migration file name. Args: app_name (str):...
magic_instruct_75k
45,511
Write a Python function to perform subsampling of regions of interest (ROIs) and ground truth offsets for a machine learning model. The function should take three input arrays: `sample_rois`, `sample_gt_offsets`, and `sample_labels`. The `sample_rois` array contains information about the regions of interest, the `sampl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def subsample_roi_and_gt(sample_rois: List[List[float]], sample_gt_offsets: List[List[float]], sample_labels: List[int]) -> Tuple[List[List[float]], List[List[float]], List[int]]: """ Subsamples t...
magic_instruct_75k
45,517
Write a Python function to calculate the origin (`rays_o`) and direction (`rays_d`) of rays for an image given its height (`H`), width (`W`), intrinsic matrix inverse (`kinv`), and pose. The function should return the origin and direction of the rays for the given image. The code should start with: ```python import nu...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def get_rays_tourism(H: int, W: int, kinv: np.ndarray, pose: np.ndarray) -> (np.ndarray, np.ndarray): """ Calculate the origin and direction of rays for an image given its height, width, intrinsic matrix inve...
magic_instruct_75k
45,526
Write a Python function to reverse a singly linked list in place. The function should take the head of the linked list as input and return the new head of the reversed linked list. The linked list is represented by the `ListNode` class, where each node has a value and a reference to the next node. The function should r...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def reverse_linked_list(head: ListNode) -> ListNode: """ Reverses a singly linked list in place. Args: ...
magic_instruct_75k
45,531
Write a Python function to simulate a simple game called "Alligator Six Making." In this game, two players take turns rolling a six-sided die and adding the number rolled to their current score. The game continues until a player's score reaches or exceeds a target score of 50. The first player to reach or exceed the ta...
Here is the Python code to solve the given problem in the markdown block: ```python import random def alligator_six_making(player1: str, player2: str) -> str: """ Simulates the "Alligator Six Making" game and returns the name of the winning player. Args: player1 (str): The name of the first player...
magic_instruct_75k
45,535
Write a Python function to manage symbolic links to external modules within a project. The function should handle the "external" command to create symbolic links to specified modules and versions in the `./external` directory. The function should validate the input and handle errors gracefully. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python import os def manage_external_modules(command: str) -> None: """ Manages symbolic links to external modules within a project. Args: command (str): A string containing the command to create a symbolic link to an ext...
magic_instruct_75k
45,541
Write a Python function to calculate the sum of all multiples of 3 or 5 below a given number `n`. The function should take an integer `n` as input and return the sum of all the multiples of 3 or 5 that are strictly less than `n`. The code should start with: ```python def sum_of_multiples(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_multiples(n: int) -> int: """ Calculate the sum of all multiples of 3 or 5 below a given number `n`. Args: n (int): The upper limit (exclusive) for finding multiples of 3 or 5. Returns: int: ...
magic_instruct_75k
45,543
Write a Python function to find the maximum sum of a contiguous subarray within a given list of integers. The function should be efficient and handle edge cases such as an empty list or a list with all negative numbers. The code should start with: ```python from typing import List def max_subarray_sum(a: List[int]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_subarray_sum(a: List[int]) -> int: """ Find the maximum sum of a contiguous subarray within the given list of integers. Args: a (List[int]): The list of integers from which to find t...
magic_instruct_75k
45,556
Write a Python function to verify whether a given tuple of numeric ranges is valid. The function should check if the input range tuple contains valid numeric ranges and meets certain criteria. The function should start with: ```python from typing import Tuple, Union def verify_tuple_range(input_range: Union[Tuple[Tup...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Union def verify_tuple_range(input_range: Union[Tuple[Tuple[Union[int, float], Union[int, float]], ...], None], allow_none: bool = True, name: str = None) -> bool: """ Verifies whether a given tuple of...
magic_instruct_75k
45,558
Write a Python function to automate the conversion of tab characters to spaces and vice versa in Makefiles within a specified directory. The function should handle the following operations: 1. Replace tab characters with spaces using an initial tab setting of 2 spaces. 2. Replace tab characters with spaces using a tab ...
Here is the Python code to solve the given problem in the markdown block: ```python import os def convert_makefiles(directory: str) -> None: """ Automates the conversion of tab characters to spaces and vice versa in Makefiles within a specified directory. Args: directory (str): The path to the dir...
magic_instruct_75k
45,567
Write a Python function to calculate the product of two given integers. The function should handle both positive and negative integers, as well as zero. The code should start with: ```python def calculate_product(num3: int, num4: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_product(num3: int, num4: int) -> int: """ Calculate the product of two given integers. Args: num3 (int): The first integer. num4 (int): The second integer. Returns: int: The produc...
magic_instruct_75k
45,581
Write a Python function to count the frequency of each topic in a given list of strings, ignoring case sensitivity. The function should return a dictionary where the keys are the lowercase versions of the topics and the values are their respective frequencies. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_topic_frequency(topics: List[str]) -> Dict[str, int]: """ Count the frequency of each topic in the given list of strings, ignoring case sensitivity. Args: topics (List[str]):...
magic_instruct_75k
45,591
Write a Python function to filter a list of integers based on specific criteria. The function should take a list of integers as input and return a new list containing only the integers that meet the following criteria: 1. Include only positive integers in the filtered list. 2. Exclude any integers that are multiples of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_integers(input_list: List[int]) -> List[int]: """ Filters a list of integers based on the following criteria: 1. Include only positive integers. 2. Exclude any integers that are multip...
magic_instruct_75k
45,597
Write a Python function to parse and extract specific parameters from a configuration file used to control a measurement system. The configuration file contains multiple lines, each representing a different measurement setup. Each line consists of a function call `calc_run` with various parameters passed as keyword arg...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_meas_values(config_file_content: str) -> List[int]: """ Extracts the values of the 'meas' parameter from each 'calc_run' function call in the configuration file content. Args: ...
magic_instruct_75k
45,611
Write a Python function to find the starting gas station index that allows you to travel around a circular route once in the clockwise direction without running out of gas. The function should take two lists as input: `gas`, which represents the amount of gas available at each station, and `cost`, which represents the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def findStartingStation(gas: List[int], cost: List[int]) -> int: """ Find the starting gas station index that allows you to travel around the circuit once in the clockwise direction. Args: g...
magic_instruct_75k
45,622
Write a Python function to determine whether it is possible to make a target value using a given list of coin denominations. Each coin denomination can be used an unlimited number of times. The function should return `True` if the target value can be made, and `False` otherwise. 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 can_make_target(coins: List[int], target: int) -> bool: """ Determine whether it is possible to make the target value using the given coin denominations. Args: coins (List[int]): A list ...
magic_instruct_75k
45,645
Write a Python function to clean a document by removing punctuation, converting all characters to lowercase, and splitting the document into individual words. The function should return a list of clean tokens. The code should start with: ```python import string def clean_tokens(doc: str) -> list: ```
Here is the Python code to solve the given problem in the markdown block: ```python import string def clean_tokens(doc: str) -> list: """ Cleans a document by removing punctuation, converting all characters to lowercase, and splitting the document into individual words. Args: doc (str): The input ...
magic_instruct_75k
45,664
Write a Python function to process a list of integers and return a new list containing only the unique elements from the input list, preserving their original order. The function should start with: ```python from typing import List def process_input(input_data: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def process_input(input_data: List[int]) -> List[int]: """ Returns a new list containing only the unique elements from the input list, preserving their original order. Args: input_data (Li...
magic_instruct_75k
45,676
Write a Python function to determine whether a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself. The function should take a positive integer as input and return a boolean value indicating whether the number is a perfect number or ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_perfect_number(num: int) -> bool: """ Determines whether a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself. Args: ...
magic_instruct_75k
45,677
Write a Python function to construct and return a command string for starting a Celery worker using Docker Compose. The function should take four inputs: - `docker_compose_path`: The path to the Docker Compose file. - `service_name`: The name of the service for which the Celery worker needs to be started. - `log_level`...
Here is the Python code to solve the given problem in the markdown block: ```python def start_celery_worker(docker_compose_path: str, service_name: str, log_level: str, app_name: str) -> str: """ Constructs and returns a command string for starting a Celery worker using Docker Compose. Args: docker...
magic_instruct_75k
45,691
Write a Python function that generates the necessary Django migration code to alter the model options for a specified model. The function should take the name of the model and the field to be used for ordering as input parameters and return the migration code as a string. The migration code should alter the model optio...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_migration_code(model_name: str, ordering_field: str) -> str: """ Generates the Django migration code to alter the model options for the specified model. Args: model_name (str): The name of the model to ...
magic_instruct_75k
45,696
Write a Python function to simulate a simplified version of URL routing in a web framework. The function should take a list of URL patterns and a requested URL, and return the corresponding view function for the requested URL. The URL patterns are represented as a list of tuples, where each tuple contains a URL patter...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_view_function(url_patterns: List[Tuple[str, str]], requested_url: str) -> str: """ Simulates a simplified version of URL routing in a web framework. Args: url_patterns (List[...
magic_instruct_75k
45,716
Write a Python function to find the minimum length of a contiguous subarray in a given array of integers, such that sorting this subarray would make the whole 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 minUnsort...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def minUnsortedSubarray(nums: List[int]) -> int: """ Find the minimum length of a contiguous subarray that, when sorted, would make the entire array sorted in non-decreasing order. Args: num...
magic_instruct_75k
45,732
Write a Python function to reverse an integer while handling overflow conditions. The function should take an integer `x` as input and return the reversed integer. If the reversed integer exceeds the maximum 32-bit signed integer value (2^31 - 1) or is less than the minimum 32-bit signed integer value (-2^31), the func...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_integer(x: int) -> int: """ Reverses an integer while handling overflow conditions. Args: x (int): The integer to be reversed. Returns: int: The reversed integer. If the reversed integer ove...
magic_instruct_75k
45,750
Write a Python function `parse_install_script(code_snippet)` that takes a string `code_snippet` as input and returns a dictionary containing the file names and their corresponding destination directories. The input code snippet is in the following format: ``` install -m 755 <source_file> <destination_directory> ``` Whe...
Here is the Python code to solve the given problem in the markdown block: ```python import re def parse_install_script(code_snippet: str) -> dict: """ Parses the given installation script code snippet and returns a dictionary containing the file names and their corresponding destination directories. A...
magic_instruct_75k
45,757
Write a Python function to process command-line arguments and perform specific actions based on the input. The function should handle the case when the user provides an invalid argument or fails to provide the required input. The function should accept the following command-line options: - `-d <directory>`: Specifies ...
Here is the Python code to solve the given problem in the markdown block: ```python import sys import getopt def process_arguments(argv: list) -> None: """ Process command-line arguments and perform specific actions based on the input. Args: argv (list): The list of command-line arguments. Re...
magic_instruct_75k
45,768
Write a Python function to map a given URL pattern to its corresponding view function name in a Django web application. If the URL pattern does not match any of the predefined paths, the function should return "Not Found". The function should be efficient and handle edge cases such as non-existent URL patterns graceful...
Here is the Python code to solve the given problem in the markdown block: ```python def find_view_function(url_pattern: str) -> str: """ Maps a given URL pattern to its corresponding view function name in a Django web application. If the URL pattern does not match any of the predefined paths, returns "Not F...
magic_instruct_75k
45,789
Write a Python function to encapsulate the service registration process for a pyramid web application. The function should take a service object and an optional name parameter, register the service using the `pyramid_config` object, and then return the registered service object. The function should be named `register_a...
Here is the Python code to solve the given problem in the markdown block: ```python def register_and_return_service(pyramid_config, svc, name=None): """ Registers a service using the provided pyramid configuration object and returns the registered service object. Args: pyramid_config: The pyramid c...
magic_instruct_75k
45,790
Write a Python function to calculate the total amount of a specific token received by a given address from a list of transactions. Each transaction is represented as a dictionary with keys: `'tokenFrom'`, `'amountFrom'`, `'to'`, and `'tokenTo'`. The function should take in the list of transactions, the target token, an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union def calculate_total_received(transactions: List[Dict[str, Union[str, int]]], target_token: str, target_address: str) -> int: """ Calculate the total amount of a specific token received by a ...
magic_instruct_75k
45,793
Create a Python module named `utils` that provides utility functions. The module should include two functions: 1. `calculate_average`: This function takes a list of numbers as input and returns the average of those numbers. If the list is empty, it should return 0. 2. `find_max`: This function takes a list of numbers a...
Here is the Python code to solve the given problem in the markdown block: ```python # utils.py def calculate_average(numbers): """ Calculate the average of a list of numbers. Args: numbers (list): A list of numbers. Returns: float: The average of the input numbers. """ if not numbers:...
magic_instruct_75k
45,827
Write a Python function to convert a string to an integer, considering the following rules: - Ignore any leading whitespace characters in the input string. - Handle the sign of the integer (positive or negative). - Convert the string to an integer, considering overflow cases. - Return the integer value based on the con...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_integer(s: str) -> int: """ Converts a string to an integer, considering the following rules: - Ignore any leading whitespace characters in the input string. - Handle the sign of the integer (positive or ne...
magic_instruct_75k
45,852
Write a Python function to convert an enum variant into a boolean value. The enum `FLTPRSRVW` has two variants: `_0` and `_1`, representing `False` and `True` respectively. Your task is to implement the function `_bits` that takes an instance of `FLTPRSRVW` and returns a boolean value based on the variant. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from enum import Enum class FLTPRSRVW(Enum): _0 = 0 _1 = 1 def _bits(enum_instance: FLTPRSRVW) -> bool: """ Converts an enum variant into a boolean value. Args: enum_instance (FLTPRSRVW): An instance of th...
magic_instruct_75k
45,881
Write a Python function to add two binary strings and return the sum as a binary string. The input strings are both non-empty and contain only characters '1' or '0'. The function should handle binary strings of different lengths and ensure the result is correctly formatted as a binary string. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python def add_binary_strings(a: str, b: str) -> str: """ Adds two binary strings and returns the sum as a binary string. Args: a (str): The first binary string. b (str): The second binary string. Returns: ...
magic_instruct_75k
45,888
Write a Python function to process a list of files and perform specific operations on each file. The function should handle errors gracefully and provide detailed logging for each operation. The operations to be performed include reading the file, converting its content to uppercase, and writing the transformed content...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import logging def process_files(files: List[str]) -> None: """ Processes a list of files by reading their content, converting it to uppercase, and writing the transformed content back to the file. L...
magic_instruct_75k
45,901
Write a Python function to calculate the precision of a binary classification model based on the counts of true positives (tp), false positives (fp), and true negatives (tn). The precision is calculated using the formula: `p = tp / (tp + fp)`. If the denominator `(tp + fp)` is zero, the function should return 0.0 as th...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_precision(tp: int, fp: int, tn: int) -> float: """ Calculate the precision of a binary classification model based on the counts of true positives (tp), false positives (fp), and true negatives (tn). Precision ...
magic_instruct_75k
45,906
Write a Python function to process a list of gene segments represented as strings in the format "gs:gstart:gend:strand_inferred:chrom". Each segment contains information about the gene symbol (gs), start position (gstart), end position (gend), inferred strand (strand_inferred), and chromosome (chrom). The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def segment_genes(gene_segments: List[str]) -> Dict[str, List[str]]: """ Processes a list of gene segments and returns a dictionary where the keys are chromosomes and the values are lists of ge...
magic_instruct_75k
45,909
Write a Python function to find all occurrences of a specific word of length `n` within a given string `S` and wrap each occurrence with `<b>` tags. The function should return the modified string. The code should start with: ```python def wrap_word_with_b_tags(S: str, word: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def wrap_word_with_b_tags(S: str, word: str) -> str: """ Finds all occurrences of a specific word within a given string and wraps each occurrence with `<b>` tags. Args: S (str): The input string in which to find and...
magic_instruct_75k
45,914
Write a Python function to organize satellite image metadata by image type. The function should take in lists of file paths for Sentinel-2 and MODIS images, along with lists of timestamps and geohashes. It should return a dictionary where the keys are the image types ("Sentinel-2" and "MODIS") and the values are lists ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def organize_metadata(sentinel_paths: List[str], modis_paths: List[str], timestamps: List[str], geohashes: List[str]) -> Dict[str, List[Dict[str, str]]]: """ Organizes satellite image metadata by i...
magic_instruct_75k
45,918
Write a Python function to filter out sequences that contain the maximum representable floating-point number (1.7e+308) from a list of strings, where each string represents a comma-separated sequence of numeric values. The function should return a new list containing only the sequences that do not contain the maximum r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_max_float(datas: List[str]) -> List[List[float]]: """ Filters out sequences that contain the maximum representable floating-point number (1.7e+308) from a list of strings. Args: d...
magic_instruct_75k
45,956
Write a Python function to generate an unguessable reference. An unguessable reference is a unique identifier that is difficult for an outsider to predict or guess. The function should generate a string of a specific length, consisting of a combination of uppercase letters, lowercase letters, and digits. Each time the ...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_unguessable_reference(length: int = 10) -> str: """ Generates an unguessable reference of a specified length. The reference is a string consisting of a combination of uppercase lett...
magic_instruct_75k
45,969
Write a Python function to automate the deployment process of a software project using Docker. The function should build a Docker image, tag it, and push it to a container registry. The function should handle different versions of the software and push the images to a specific container registry. The function should t...
Here is the Python code to solve the given problem in the markdown block: ```python import subprocess def deploy_docker_image(image_version: str, workspace: str, registry_url: str) -> None: """ Automates the deployment process of a software project using Docker. Args: image_version (str): The vers...
magic_instruct_75k
45,978
Write a Python function to find the longest common subsequence (LCS) of two given strings. A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. For example, "abc", "abg", "bdf", "aeg", "acefg", etc., are all subsequences of "abcdefg". The LCS is the longest subsequence th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_subsequence(a: str, b: str) -> str: """ Finds the longest common subsequence (LCS) of two given strings. Args: a (str): The first string. b (str): The second strin...
magic_instruct_75k
45,990
Write a Python function to parse a file path and extract specific information from it. The file path follows a specific format, and your function should be able to parse this format and return the relevant details. The function `parse_file_path` should take a file path as input and return a dictionary containing the f...
Here is the Python code to solve the given problem in the markdown block: ```python def parse_file_path(file_path: str) -> dict: """ Parses a file path and extracts the directory, filename, and extension. Args: file_path (str): The file path to be parsed. Returns: dict: A dictionary co...
magic_instruct_75k
46,009
Write a Python function `process_time_data(time_count)` that takes a dictionary `time_count` as input and returns two lists `x` and `y` as output. The `time_count` dictionary contains time strings as keys and their corresponding counts as values. The function should iterate through the keys of the `time_count` dictiona...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def process_time_data(time_count: Dict[str, int]) -> Tuple[List[str], List[int]]: """ Processes time data and populates two lists `x` and `y` based on the presence of `time_str` in the `time...
magic_instruct_75k
46,026
Write a Python function to resolve module dependencies in a programming language's module system. The function should take a list of module names and their dependencies and return the order in which the modules should be resolved to satisfy all dependencies. The function should handle circular dependencies by raising a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def resolveModules(modules: List[Tuple[str, List[str]]]) -> List[str]: """ Resolves the dependencies of modules and returns the order in which they should be resolved. Args: modules (...
magic_instruct_75k
46,034
Write a Python function `apply_rule_decorator` that implements a decorator to enforce a rule on the input parameters of a function. The decorator should take a rule-checking function as an argument, which determines whether a given type matches the rule. The decorator should then apply this rule to the input parameters...
Here is the Python code to solve the given problem in the markdown block: ```python def apply_rule_decorator(rule_check): """ A decorator factory that creates a decorator to enforce a rule on the input parameters of a function. Args: rule_check (function): A function that takes a type and returns a...
magic_instruct_75k
46,069
Write a Python function to generate a Slurm job submission script based on the given requirements. The function should take the following inputs: - `error_log`: The name of the error log file. - `time_limit`: The time limit for the job in the format `HH:MM:SS`. - `num_gpus`: The number of GPUs required for the job. - `...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_slurm_script(error_log: str, time_limit: str, num_gpus: int, module: str, python_script: str) -> str: """ Generates a Slurm job submission script based on the given requirements. Args: error_log (str): ...
magic_instruct_75k
46,078
Write a Python function to generate emotion names based on the number of emotion classes. The function `get_fer_names(num_classes)` takes an integer `num_classes` as input and returns a list of emotion names based on the number of classes. The emotion names are predefined for 5, 6, and 7 classes as follows: - For 5 cla...
Here is the Python code to solve the given problem in the markdown block: ```python def get_fer_names(num_classes: int) -> list: """ Generate emotion names based on the number of emotion classes. Args: num_classes (int): The number of emotion classes. Returns: list: A list of emotion n...
magic_instruct_75k
46,084
Write a Python function to calculate the area of a rectangle given the coordinates of two opposite corners in a 2D coordinate system. The function should handle cases where the rectangle is not aligned with the coordinate axes, meaning the sides of the rectangle are not necessarily parallel to the x or y-axis. The func...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_rectangle_area(x1: int, y1: int, x2: int, y2: int) -> int: """ Calculate the area of a rectangle given the coordinates of two opposite corners. Args: x1 (int): The x-coordinate of the first corner. ...
magic_instruct_75k
46,090
Write a Python function to read a specific portion of a 2D grid of characters and return the word found in that portion based on the given parameters. The grid is represented as a list of lists, where each inner list represents a row of characters. The function should take the following parameters: - `grid`: A 2D list ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def read_word_from_grid(grid: List[List[str]], row: int, col: int, direction: str, length: int) -> str: """ Reads a specific portion of a 2D grid of characters and returns the word found in that portion....
magic_instruct_75k
46,128
Write a Python function to return the bottom-up level order traversal of a binary tree. The binary tree is represented by a pointer to its root node, where each node has a value and pointers to its left and right children. The function should return a 2D list, where each inner list represents a level of the tree, and t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def levelOrderBottom(root...
magic_instruct_75k
46,168
Write a Python function to filter and return a list of filenames for successfully uploaded files from a given list of file upload statuses. Each file upload status is represented by a dictionary with the keys "filename" (string) and "status" (string). The "status" can be either "success" or "failure". The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_successful_uploads(upload_statuses: List[Dict[str, str]]) -> List[str]: """ Filters and returns a list of filenames for successfully uploaded files from a given list of file upload statuses...
magic_instruct_75k
46,171
Write a Python function to initialize a 3-dimensional list with `None` values based on the given dimensions `a`, `b`, and `c`. The function should return the initialized 3-dimensional list. The code should start with: ```python from typing import List, Optional, Any def initialize_3d_list(a: int, b: int, c: int) -> L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Any def initialize_3d_list(a: int, b: int, c: int) -> List[List[List[Optional[Any]]]]: """ Initializes a 3-dimensional list with `None` values based on the given dimensions `a`, `b`, and `c`. ...
magic_instruct_75k
46,183
Write a Python function to find the maximum value in each sliding window of a given size `k` over a list of integers `nums`. The function should return a list containing the maximum value for each window as it slides from left to right through the input list. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import deque def max_sliding_window(nums: List[int], k: int) -> List[int]: """ Find the maximum value in each sliding window of size `k` over the list `nums`. Args: nums (Li...
magic_instruct_75k
46,184
Write a Python function `process_dependencies` that processes a list of package dependencies and returns a dictionary representing the dependencies in a structured format. The input list contains package names and their dependencies in a specific format. The function should parse this information and return a dictionar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def process_dependencies(install_requires: List[str]) -> Dict[str, List[str]]: """ Processes a list of package dependencies and returns a dictionary representing the dependencies in a structured fo...
magic_instruct_75k
46,195
Write a Python function to calculate the lengths of each word in a given list of words. The function should return a new list containing the lengths of each word in the original list. The function should handle an empty list by returning an empty list. The code should start with: ```python from typing import List def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def word_lengths(words: List[str]) -> List[int]: """ Calculate the lengths of each word in a given list of words. Args: words (List[str]): A list of words for which to calculate the lengths....
magic_instruct_75k
46,200
Write a Python function to count the occurrences of each unique file extension in a list of file paths. The function should return a dictionary where the keys are the file extensions (or an empty string for files with no extension) and the values are the counts of files with those extensions. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_file_extensions(file_paths: List[str]) -> Dict[str, int]: """ Counts the occurrences of each unique file extension in a list of file paths. Args: file_paths (List[str]): A li...