source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 110,757 | Write a Python function to determine if two strings are isomorphic. Two strings are isomorphic if there is a one-to-one mapping possible for every character of the first string to every character of the second string. The function should handle edge cases such as strings of different lengths and should not use any buil... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(string1: str, string2: str) -> bool:
"""
Determine if two strings are isomorphic.
Two strings are isomorphic if there is a one-to-one mapping possible for every character
of the first string to every ... |
magic_evol_110k | 110,763 | Write a Python function that takes a single alphanumeric character sequence as input and returns a new string where each character from the input sequence is repeated twice consecutively. The function should handle any alphanumeric string, including those with spaces.
The code should start with:
```python
def double_c... | Here is the Python code to solve the given problem in the markdown block:
```python
def double_characters(s: str) -> str:
"""
Returns a new string where each character from the input string is repeated twice consecutively.
Args:
s (str): The input alphanumeric string.
Returns:
str: A n... |
magic_evol_110k | 110,777 | Write a Python function to remove an element from a given list at a specified index, ensuring the index is valid before performing the removal. If the index is invalid, the function should return the original list without any changes. The function should start with:
```python
from typing import List
def remove_element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_element_at_index(lst: List[int], index: int) -> List[int]:
"""
Removes an element from the list at the specified index if the index is valid.
Args:
lst (List[int]): The list from ... |
magic_evol_110k | 110,793 | Write a Python function to find the common elements between two lists of strings. The function should return a list of common elements in the order they appear in the first list. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[str], list2: List[str]) -> List[str]:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(list1: List[str], list2: List[str]) -> List[str]:
"""
Finds the common elements between two lists of strings and returns them in the order they appear in the first list.
Arg... |
magic_evol_110k | 110,796 | Write a Python function that iterates over a sequence of numbers, identifies prime numbers, and for each prime number, calculates the sum of its digits. Additionally, for each prime number, iterate over a nested sequence and perform specific tasks based on the sum of its digits. The function should use all types of loo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
magic_evol_110k | 110,804 | Write a Python function to index a list of tuples based on the first element of each tuple, up to a specified maximum index. The function should return a list of lists where each sublist contains all the values corresponding to a specific index key. The code should start with:
```python
from typing import List, Tuple
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def index_data(data: List[Tuple[int, int]], maxidx: int) -> List[List[int]]:
"""
Indexes a list of tuples based on the first element of each tuple, up to a specified maximum index.
Args:
... |
magic_evol_110k | 110,833 | Design a Python function to create a graph representation of locations and their respective neighbors using an adjacency list. The function should take a list of tuples, where each tuple contains a location and its neighbors, and return a dictionary representing the adjacency list. 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, Dict
def create_adjacency_list(locations: List[Tuple[str, List[str]]]) -> Dict[str, List[str]]:
"""
Creates an adjacency list representation of locations and their neighbors.
Args:
l... |
magic_evol_110k | 110,840 | Write a Python function to transpose a given matrix, where the rows of the original matrix become the columns of the transposed matrix and vice versa. The function should handle matrices of any dimensions. The code should start with:
```python
from typing import List
def transpose_matrix(matrix: List[List[int]]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Transposes the given matrix, converting its rows to columns and columns to rows.
Args:
matrix (List[List[int]]): The ori... |
magic_evol_110k | 110,846 | Write a Python function to find the indexes of all occurrences of a specified number in a given list. The function should return a list of indices where the specified number appears. The code should start with:
```python
from typing import List
def find_all_occurrences(lst: List[int], number: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_all_occurrences(lst: List[int], number: int) -> List[int]:
"""
Find the indexes of all occurrences of a specified number in a given list.
Args:
lst (List[int]): The list of intege... |
magic_evol_110k | 110,855 | Write a Python function to flatten a given two-dimensional array (which can have unknown depths) into a one-dimensional array. Additionally, implement a functionality that allows the user to specify a depth, and only flatten arrays up to that depth, keeping all deeper arrays nested. The function should handle various d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_array(lst: List[Any], depth: int = -1) -> List[Any]:
"""
Flattens a nested list up to a specified depth.
Args:
lst (List[Any]): The nested list to be flattened.
dept... |
magic_evol_110k | 110,877 | Write a Python function to generate the first `n` prime numbers using a do-while loop construct. The function should return a list of the first `n` prime numbers. The code should start with:
```python
def generate_first_n_primes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
magic_evol_110k | 110,892 | Write a Python function to perform an optimized linear search on a given list of integers. The function should return the index of the first occurrence of the target element if it exists in the list, otherwise return -1. The optimization should minimize the time complexity by reducing the number of comparisons.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def optimized_linear_search(arr: List[int], x: int) -> int:
"""
Perform an optimized linear search to find the index of the first occurrence of the target element.
Args:
arr (List[int]): The... |
magic_evol_110k | 110,894 | Write a Python function to generate a string of a specified length `n`, filled with a specified character `char`. The function should handle cases where `n` is zero or negative, and ensure that the character `char` is a single character. If `char` is not a single character, the function should return an empty string.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_string(n: int, char: str) -> str:
"""
Generates a string of length `n` filled with the character `char`.
Args:
n (int): The length of the string to be generated.
char (str): The character to fil... |
magic_evol_110k | 110,904 | Write a Python function to find a triple of indices (i, j, k) such that the elements at these indices in three given arrays A, B, and C are equal. The function should return the indices if such a triple exists, otherwise return `None`. Ensure that the function raises a `ValueError` if the input arrays do not have the s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_equal_elements_indices(A: List[int], B: List[int], C: List[int]) -> Optional[Tuple[int, int, int]]:
"""
Find a triple of indices (i, j, k) such that A[i] == B[j] == C[k].
A... |
magic_evol_110k | 110,905 | Write a Python function to calculate the sum of the three largest numbers from an unordered list of whole numbers. The function should efficiently find and sum the three largest numbers without sorting the entire list.
The code should start with:
```python
from typing import List
def sum_of_three_largest(numbers: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def sum_of_three_largest(numbers: List[int]) -> int:
"""
Calculate the sum of the three largest numbers from an unordered list of whole numbers.
Args:
numbers (List[int]): The l... |
magic_evol_110k | 110,914 | Write a Python function to compute the highest common factor (HCF) of two integers using the Euclidean algorithm. The function should be able to handle both positive and negative integers. The code should start with:
```python
def compute_hcf(n1: int, n2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_hcf(n1: int, n2: int) -> int:
"""
Computes the highest common factor (HCF) of two integers using the Euclidean algorithm.
Args:
n1 (int): The first integer.
n2 (int): The second integer.
Ret... |
magic_evol_110k | 110,916 | Write a Python function to sort a given list of strings in descending order based on their alphabetical sequence. The function should handle lists of varying lengths and ensure that the sorting is done in-place. The code should start with:
```python
from typing import List
def sort_list_descending(strings: List[str]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list_descending(strings: List[str]) -> None:
"""
Sorts a list of strings in descending alphabetical order in-place.
Args:
strings (List[str]): The list of strings to be sorted.
... |
magic_evol_110k | 110,917 | Write a Python function that takes two integers as input and returns a formatted string showing the sign of their sum. If the sum is zero, the function should return an empty string. The function should use formatted string literals to achieve this.
The code should start with:
```python
def format_sum_with_sign(a: int... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_sum_with_sign(a: int, b: int) -> str:
"""
Returns a formatted string showing the sign of the sum of two integers.
If the sum is zero, returns an empty string.
Args:
a (int): The first integer.
... |
magic_evol_110k | 110,946 | Write a Python function to calculate the maximum, minimum, and average values from a given list of numerical scores. The function should return these values as a tuple in the order of maximum, minimum, and average. The code should start with:
```python
from typing import List, Tuple
def calculate_stats(scores: List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_stats(scores: List[int]) -> Tuple[int, int, float]:
"""
Calculate the maximum, minimum, and average values from a list of numerical scores.
Args:
scores (List[int]): A l... |
magic_evol_110k | 110,964 | Write a Python function to calculate the sum of elements in a given list. The function should be efficient and handle various edge cases, such as an empty list or a list with negative numbers. The code should start with:
```python
from typing import List
def sum_of_elements(lst: 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_elements(lst: List[int]) -> int:
"""
Calculate the sum of elements in a given list.
Args:
lst (List[int]): The list of integers whose sum needs to be calculated.
Returns:
... |
magic_evol_110k | 110,972 | Write a Python function to sort a list of student records based on their GPA (Grade Point Average) in descending order. Each student record is represented as a dictionary with keys 'name', 'gpa', and 'graduation_year'. The function should return a list of student records sorted by GPA.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_students_by_gpa(students: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Sorts a list of student records by their GPA in descending order.
Args:
students (List[Dict[str, a... |
magic_evol_110k | 110,991 | Write a Python function to identify whether each number in a given list of integers is a prime number or not. The function should return a dictionary where the keys are the numbers from the list and the values are boolean values indicating whether the corresponding number is prime.
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, Dict
from math import sqrt
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the numb... |
magic_evol_110k | 110,992 | Write a Python function to validate that a list of date strings are in strictly increasing order. The function should handle erroneous input by returning `False` if any date string is invalid or if the dates are not in increasing order. The function should also print appropriate error messages for invalid dates and non... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from datetime import datetime
def validate_dates(date_list: List[str]) -> bool:
"""
Validates that a list of date strings are in strictly increasing order.
Args:
date_list (List[str]): A lis... |
magic_evol_110k | 110,999 | Write a Python function to validate a list of integers based on a set of predefined validation rules. The function should return a list of validation results, where each result is a dictionary indicating whether the integer passed the validation and the reason for failure if it did not. The validation rules are:
1. The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def validate_integers(integers: List[int]) -> List[Dict[str, bool or str]]:
"""
Validates a list of integers based on predefined rules and returns a list of validation results.
The validation ... |
magic_evol_110k | 111,006 | Write a Python function to implement the QuickSort algorithm for sorting a list of integers. The function should be optimized for efficiency, speed, and computing resources. The code should start with:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the QuickSort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List[i... |
magic_evol_110k | 111,010 | Write a Python function to safely access an element at a specified index in a given string. If the index is out of bounds, return a default value instead of raising an error. The function should handle both positive and negative indices.
The code should start with:
```python
def safe_access(s: str, index: int, default... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_access(s: str, index: int, default: str = 'Index out of bounds') -> str:
"""
Safely access an element at a specified index in a given string.
If the index is out of bounds, return a default value.
Args:
... |
magic_evol_110k | 111,015 | Write a Python function to create a dictionary where the keys are the unique lexical items (words) from a given sentence, and the values are the counts of vowel phonemes in each corresponding lexical item. The sentence is provided as a string, and the function should handle case insensitivity by converting all characte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_vowel_phonemes(sentence: str) -> Dict[str, int]:
"""
Creates a dictionary where the keys are the unique lexical items from the given sentence,
and the values are the counts of vowel phoneme... |
magic_evol_110k | 111,048 | Write a Python function to extract the recurring elements from a given numerical series. A recurring element is defined as an element that appears more than once in the series. The function should return a list of these recurring elements in ascending order.
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
def find_recurring_elements(sequence: List[int]) -> List[int]:
"""
Extracts the recurring elements from a given numerical series and returns them in ascending order.
Args:
sequence (List[int... |
magic_evol_110k | 111,054 | Write a Python function to find all perfect numbers within a given range. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). The function should take an integer `n` as input and return a list of all perfect numbers up to `n`.
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_perfect_numbers(n: int) -> List[int]:
"""
Find all perfect numbers within the range up to `n`.
Args:
n (int): The upper limit of the range to search for perfect numbers.
Return... |
magic_evol_110k | 111,061 | Write a Python function to convert a list of 7-segment display codes into their corresponding binary and hexadecimal representations. The function should handle both valid and invalid 7-segment codes, returning `None` for invalid codes and printing an error message. The function should also handle potential punctuation... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def convert_seven_segment(seven_segment_codes: List[str]) -> Optional[List[Tuple[str, str]]]:
"""
Convert a list of 7-segment display codes into their corresponding binary and hexadecima... |
magic_evol_110k | 111,068 | Write a Python function to generate the Fibonacci sequence up to a specified iteration index `n`. The function should return a list of Fibonacci numbers up to the `n`-th iteration. The Fibonacci sequence is defined such that each number is the sum of the two preceding ones, starting from 0 and 1.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the n-th iteration.
Args:
n (int): The iteration index up to which the Fibonacci sequence should be gen... |
magic_evol_110k | 111,103 | Write a Python function to generate an output array where each element is the cumulative sum of the preceding elements from the input array. The function should start with:
```python
from typing import List
def cumulative_sum(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(arr: List[int]) -> List[int]:
"""
Generate an output array where each element is the cumulative sum of the preceding elements from the input array.
Args:
arr (List[int]): ... |
magic_evol_110k | 111,113 | Write a Python function to convert a list of tuples into a dictionary where each tuple's second element serves as the key and the first element serves as the value. The function should avoid using explicit loops and should utilize Python built-in functions to achieve this efficiently.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def convert_tuple_list_to_dict(tuple_list: List[Tuple[str, str]]) -> Dict[str, str]:
"""
Converts a list of tuples into a dictionary where each tuple's second element serves as the key and t... |
magic_evol_110k | 111,118 | Write a Python function to compute the aggregate sum of the individual numerical digits within a specified integer value. The function should handle both positive and negative integers. The code should start with:
```python
def sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(number: int) -> int:
"""
Compute the aggregate sum of the individual numerical digits within a specified integer value.
Args:
number (int): The integer value whose digits are to be summed.
Ret... |
magic_evol_110k | 111,135 | Write a Python function to compare two phrases and determine if they contain the same words, regardless of their order. The function should return `True` if the phrases contain the same words, and `False` otherwise. The function should handle phrases with multiple spaces between words and ignore case differences.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets(phrase1: str, phrase2: str) -> bool:
"""
Compare two phrases to determine if they contain the same words, regardless of their order and case.
Args:
phrase1 (str): The first phrase to compare.
... |
magic_evol_110k | 111,144 | Write a Python function to find the kth largest integer and its frequency in a given list of integers. The function should handle negative integers and zeros. The code should start with:
```python
from typing import List, Tuple
def find_kth_largest_and_frequency(arr: List[int], k: int) -> Tuple[int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import heapq
from collections import Counter
def find_kth_largest_and_frequency(arr: List[int], k: int) -> Tuple[int, int]:
"""
Find the kth largest integer and its frequency in the given list of ... |
magic_evol_110k | 111,147 | Write a Python function to identify the greatest unconventional digit from a set of nine handpicked, distinct numerals. The function should take a list of nine integers as input and return the greatest integer. The code should start with:
```python
from typing import List
def find_greatest_unconventional_digit(numbers... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_greatest_unconventional_digit(numbers: List[int]) -> int:
"""
Identifies the greatest unconventional digit from a set of nine handpicked, distinct numerals.
Args:
numbers (List[int]... |
magic_evol_110k | 111,149 | Write a Python function to determine the relationship between three given numerical values using an if-else ladder. The function should compare the three numbers and return a string describing their relationship. The possible relationships are:
1. The first number is greater than both the second and third numbers.
2. T... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_three_numbers(num1: int, num2: int, num3: int) -> str:
"""
Compares three numerical values and returns a string describing their relationship.
Args:
num1 (int): The first number to compare.
num2 ... |
magic_evol_110k | 111,150 | Write a Python function to perform a ternary search on a sorted list. The function should return the index of the key if it is present in the list, otherwise, it should return -1. The function should be recursive and should use the ternary search algorithm, which divides the list into three parts instead of two as in b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search(l: int, r: int, key: int, ar: List[int]) -> int:
"""
Perform a ternary search on a sorted list to find the index of a key.
Args:
l (int): The left index of the current sea... |
magic_evol_110k | 111,159 | Write a Python function to partition a given 2D numpy array into non-overlapping sub-arrays of 2x2 dimensions. The output should maintain the original order of elements and can be a three-dimensional numpy array or list. The function should handle arrays of any size where the dimensions are multiples of 2.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List, Union
def partition_2x2(array: np.ndarray) -> Union[np.ndarray, List[List[List[int]]]]:
"""
Partitions a given 2D numpy array into non-overlapping sub-arrays of 2x2 dimensions.
A... |
magic_evol_110k | 111,165 | Write a Python function to extract the first `n` elements from a given list. The function should handle cases where `n` is greater than the length of the list by returning the entire list. The function should also handle cases where `n` is less than or equal to zero by returning an empty list.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_first_n_elements(lst: List[int], n: int) -> List[int]:
"""
Extracts the first n elements from the given list.
Args:
lst (List[int]): The list from which to extract the elements.
... |
magic_evol_110k | 111,167 | Write a Python function to determine if one string is a substring of another string. The function should return `True` if the second string is a substring of the first string, and `False` otherwise. The function should handle edge cases such as empty strings and case sensitivity.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring(str1: str, str2: str) -> bool:
"""
Determines if one string is a substring of another string.
Args:
str1 (str): The main string to be checked.
str2 (str): The substring to check for in the m... |
magic_instruct_75k | 1 | Write a Python function to filter out palindromic strings from a given list of strings. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). The function should return a new list containing only the palindrom... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_palindromes(words: List[str]) -> List[str]:
"""
Filters out palindromic strings from a given list of strings.
Args:
words (List[str]): A list of strings to be checked for ... |
magic_instruct_75k | 3 | Write a Python function to parse a list of tokens from a simple programming language. The language has four types of tokens: "daddress", "dcommand", "doaddress", and "dosymbol". Each token is represented as a tuple where the first element is the token type and the second element is the token value. The parser should us... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def daddress(token: Tuple[str, str]) -> Tuple[str, str]:
"""Process a 'daddress' token."""
return token
def dcommand(token: Tuple[str, str]) -> Tuple[str, str]:
"""Process a 'dcommand' token.... |
magic_instruct_75k | 25 | Write a Python function `generate_tmux_commands` that generates a list of tmux commands for managing a distributed machine learning job. The function should take the following parameters:
- `session`: The name of the tmux session to be created.
- `base_cmd`: The base command to be executed by each worker.
- `num_worker... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_tmux_commands(session: str, base_cmd: List[str], num_workers: int, remotes: List[str], logdir: str) -> List[Tuple[str, str, List[str]]]:
"""
Generates a list of tmux commands for mana... |
magic_instruct_75k | 33 | Write a Python function to find two distinct elements in a given array that sum up to a specified target. If such a pair exists, return their indices as a list. If no such pair exists, return an empty list.
The code should start with:
```python
from typing import List
def find_two_sum(nums: List[int], target: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_two_sum(nums: List[int], target: int) -> List[int]:
"""
Find two distinct elements in the array that sum up to the target and return their indices.
Args:
nums (List[int]): The array... |
magic_instruct_75k | 42 | 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 repre... |
magic_instruct_75k | 45 | Write a Python function to group products by their category from a list of tuples. Each tuple in the input list contains the product name as the first element and the category as the second element. The function should return a dictionary where the keys are the unique categories and the values are lists of product name... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def group_products_by_category(products: List[Tuple[str, str]]) -> Dict[str, List[str]]:
"""
Groups products by their category from a list of tuples.
Args:
products (List[Tuple[... |
magic_instruct_75k | 47 | Write a Python function to correct the names of software applications in a given list. The function should handle misspellings, incorrect capitalization, and missing characters. The corrected names should match the most common and widely accepted spellings and capitalization for each application. The function should ma... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def fix_application_names(apps: List[str]) -> List[str]:
"""
Corrects the names of software applications in a given list.
Args:
apps (List[str]): A list of application names with potential e... |
magic_instruct_75k | 51 | Write a Python function to generate a configuration file for a blog engine. The configuration file should contain settings for both local and remote URLs, site title, site description, a boolean flag for copying RST files, and a Disqus shortname. The function should take these variables as input and return a string rep... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_config_file(local_url: str, remote_url: str, site_title: str, site_description: str, copy_rst: bool, disqus_shortname: str) -> str:
"""
Generates a configuration file for a blog engine based on the provided settings... |
magic_instruct_75k | 56 | Write a Python function to simulate an agent-based model using the FLAMEGPU framework. The function should perform a specific computation on the agents' data and update the output message with the result. The function should be named `pred_output_location` and should take two parameters: `message_in` and `message_out`,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any
class MessageBruteForce:
def setVariableInt(self, key: str, value: int) -> None:
"""
Mock method to set an integer variable in the message.
Args:
key (str): The key for th... |
magic_instruct_75k | 61 | Write a Python function to generate SQL statements based on a list of database migration operations. Each operation is represented as a tuple containing the operation type and a version number. The function should handle two types of migration operations: "migrate" and "rollback". For "migrate" operations, the function... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_sql_statements(operations: List[Tuple[str, str]]) -> List[str]:
"""
Generates SQL statements based on a list of database migration operations.
Args:
operations (List[Tupl... |
magic_instruct_75k | 64 | Write a Python function to simulate a callback mechanism that allows registering callback functions and invoking them in a thread-safe manner. The function should handle multiple threads invoking the callbacks without causing data races or other synchronization issues.
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, Callable
import threading
# Global lock for thread safety
callback_lock = threading.Lock()
def register_callback(callbacks: List[Callable[[], None]], callback: Callable[[], None]) -> None:
"""
Register... |
magic_instruct_75k | 86 | Implement the `CivilianTimeImp` class in Python to represent time in a 12-hour format with an additional indicator for AM or PM. The class should include the following member functions:
1. `setTime(self, hr: int, min: int, pm: int)`: A function to set the time in the civilian format. The parameters `hr` and `min` repre... | Here is the Python code to solve the given problem in the markdown block:
```python
class TimeImp:
def __init__(self, hr: int, min: int):
self.hr = hr
self.min = min
class CivilianTimeImp(TimeImp):
def __init__(self, hr: int, min: int, pm: int):
super().__init__(hr, min)
self.pm... |
magic_instruct_75k | 116 | Write a Python function to determine the most effective treatment for a specific subclone based on a given matrix of treatment effects. The function should take a 2D array `matrix` and an integer `subclone_index` as input and return the index of the treatment that has the greatest impact on the specified subclone. If t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def most_effective_treatment(matrix: List[List[float]], subclone_index: int) -> int:
"""
Determine the most effective treatment for a specific subclone based on the given matrix of treatment effects.
... |
magic_instruct_75k | 128 | Write a Python function to calculate the Euclidean distance between two points in a 2D plane. The points are represented by their Cartesian coordinates `(x, y)`. The function should be named `calculate_distance` and should take two tuples as input, where each tuple contains the `(x, y)` coordinates of a point. The func... | 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 | 141 | Write a Python function to automate the process of entering a Docker container's namespace using the `nsenter` command. The function should take a container ID as input and then use the `docker inspect` command to retrieve the container's process ID (PID). Finally, the function should use the obtained PID to enter the ... | Here is the Python code to solve the given problem in the markdown block:
```python
import subprocess
def enter_container_namespace(container_id: str) -> None:
"""
Automates the process of entering a Docker container's namespace using the `nsenter` command.
Args:
container_id (str): The ID of the ... |
magic_instruct_75k | 157 | Write a Python function to calculate the power of a given base number `x` raised to the power `n`. The function should handle both positive and negative values of `n`. The code should start with:
```python
def myPow(x: float, n: int) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def myPow(x: float, n: int) -> float:
"""
Calculate the power of a given base number `x` raised to the power `n`.
Args:
x (float): The base number.
n (int): The power number.
Returns:
float: The... |
magic_instruct_75k | 189 | Write a Python script that organizes and analyzes data from a set of packages. The packages are represented as a list of dictionaries, where each dictionary contains information about a specific package. The information includes the package name, version, dependencies, and size.
Your task is to write two functions:
1.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def organize_packages(packages: List[Dict[str, any]]) -> Dict[str, List[str]]:
"""
Organizes the list of package dictionaries into a dictionary where the keys are package names
and the values a... |
magic_instruct_75k | 199 | Write a Python function to determine if a given stack (represented as a list) is empty. The function should return `True` if the stack is empty and `False` otherwise. The function should not use any built-in stack methods or functions.
The code should start with:
```python
from typing import List
def is_stack_empty(s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_stack_empty(stk: List[int]) -> bool:
"""
Determines if the given stack (represented as a list) is empty.
Args:
stk (List[int]): The stack represented as a list of integers.
Retur... |
magic_instruct_75k | 205 | Write a Python function `normalize_flux(flux, cont, window)` that normalizes the `flux` data based on the median of each row within the specified `window`. The normalization should be performed by dividing each element of a row in `flux` by the corresponding median value calculated within the window. The function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def normalize_flux(flux: np.ndarray, cont: np.ndarray, window: int) -> np.ndarray:
"""
Normalizes the flux data based on the median of each row within the specified window.
Args:
flux (np.ndarray... |
magic_instruct_75k | 207 | Write a Python function to find and return the largest of two given numbers. The function should handle any two integers and return the larger one. The code should start with:
```python
def find_largest_number(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_largest_number(num1: int, num2: int) -> int:
"""
Finds and returns the largest of two given numbers.
Args:
num1 (int): The first number to compare.
num2 (int): The second number to compare.
Ret... |
magic_instruct_75k | 236 | Write a Python function to extract the version number of a specific programming language from a list of strings representing programming language classifiers. Each string in the list follows the format:
```
'Programming Language :: <language_name> :: <version>'
```
The function should take in the list of classifiers an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_version(classifiers: List[str], language: str) -> str:
"""
Extracts the version number of a specific programming language from a list of classifiers.
Args:
classifiers (List[str]... |
magic_instruct_75k | 240 | Write a Python function to determine if a given string is a valid palindrome, considering only alphanumeric characters and ignoring cases. The function should return `True` if the string is a palindrome and `False` otherwise. The function should start with:
```python
def is_valid_palindrome(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_palindrome(s: str) -> bool:
"""
Determines if a given string is a valid palindrome, considering only alphanumeric characters and ignoring cases.
Args:
s (str): The input string to be checked.
Retur... |
magic_instruct_75k | 243 | Write a Python function to extract specific configuration details from a given CloudFormation template string related to an Amazon EMR (Elastic MapReduce) Studio. The function should parse the template and extract the following details:
1. Authentication mode used for the EMR Studio.
2. Default S3 location for the EMR ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def extract_emr_studio_config(template: str) -> dict:
"""
Extracts specific configuration details from a given CloudFormation template string related to an Amazon EMR Studio.
Args:
template (str): The Clo... |
magic_instruct_75k | 260 | Write a Python function to automate the build process for a specific ROS 2 package. The function should navigate to a specified directory and execute a build command using a makefile located in that directory. The makefile's name includes a variable `$CONFIGURATION` which can take any value. The function should be able... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import subprocess
def build_ros2_package(configuration: str) -> None:
"""
Automates the build process for a specific ROS 2 package by navigating to the build directory
and executing the build command using a makef... |
magic_instruct_75k | 290 | Write a Python function to find the pair of points with the maximum Euclidean distance between them from a given list of 2D points. The function should return the pair of points with the maximum distance.
The code should start with:
```python
from typing import List, Tuple
def max_distance_points(points: List[Tuple[f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def max_distance_points(points: List[Tuple[float, float]]) -> Tuple[Tuple[float, float], Tuple[float, float]]:
"""
Calculate the pair of points with the maximum Euclidean distance from... |
magic_instruct_75k | 295 | Create a Python function to simulate a command execution framework with custom exception handling. The function should execute a command and handle any exceptions that occur during the execution. The custom exception class, named `CommandExecutionException`, should inherit from the built-in `Exception` class and provid... | Here is the Python code to solve the given problem in the markdown block:
```python
class CommandExecutionException(Exception):
"""
Custom exception class for handling errors specific to command execution.
Attributes:
message (str): The error message associated with the exception.
"""
def _... |
magic_instruct_75k | 314 | Write a Python function to calculate the final total amount for a financial transaction after applying a discount and a surcharge. The transaction details are provided in a dictionary with specific keys: 'importe' (float), 'descuento' (float), 'recargo' (float), and 'total' (float). The function should take this dictio... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_transaction_total(transaction_details: dict) -> float:
"""
Calculate the final total amount for a financial transaction after applying a discount and a surcharge.
Args:
transaction_details (dict): A di... |
magic_instruct_75k | 320 | Write a Python function `generate_install_commands(packages)` that takes a list of package names as input and returns a string containing the `apt-get install` commands for installing the specified packages. The function should also include the `-y` flag to automatically answer "yes" to all prompts. The function should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_install_commands(packages: List[str]) -> str:
"""
Generates an `apt-get install` command string for the given list of package names.
Args:
packages (List[str]): A list of packag... |
magic_instruct_75k | 342 | 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 contains no even numbers, the function should return `0`.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(arr: List[int]) -> int:
"""
Calculate the sum of all even numbers in a given list.
Args:
arr (List[int]): A list of integers.
Returns:
int: The sum of al... |
magic_instruct_75k | 359 | 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 maxProfit(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 repres... |
magic_instruct_75k | 360 | 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 of a company. If it is not possible to make any profit, the function should return 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 max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be obtained by buying and selling a stock at most once.
Args:
prices (List[int]): A list of integers repre... |
magic_instruct_75k | 361 | Write a Python function to count the frequency of each unique element in a given list of integers. The function should return a dictionary where the keys are the unique elements from the input list and the values are the frequency of occurrence of each element in the input list.
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, Dict
def count_frequency(input_list: List[int]) -> Dict[int, int]:
"""
Counts the frequency of each unique element in the given list of integers.
Args:
input_list (List[int]): The list of i... |
magic_instruct_75k | 362 | Write a Python function to convert a dictionary of technology acronyms and their full names into a sorted list of strings. Each string in the list should represent the full name of the technology followed by its acronym in parentheses. The list should be sorted alphabetically based on the full names of the technologies... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def convert_tech_dict_to_list(tech_dict: Dict[str, str]) -> List[str]:
"""
Converts a dictionary of technology acronyms and their full names into a sorted list of strings.
Each string in the l... |
magic_instruct_75k | 368 | Write a Python function to remove specified key-value pairs from a given dictionary. The function should take a dictionary and a list of keys as input and return the modified dictionary with the specified key-value pairs removed. If a key in the list does not exist in the dictionary, it should be ignored.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def remove_key_values(dictionary: Dict[str, int], keys: List[str]) -> Dict[str, int]:
"""
Removes specified key-value pairs from a dictionary.
Args:
dictionary (Dict[str, int]): The in... |
magic_instruct_75k | 376 | Write a Python function to reverse the order of words in a given string while preserving the order of characters within each word. The input string will contain multiple words separated by spaces, and there will be no leading or trailing spaces. The function should return the string with the words reversed.
The code s... | 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 while preserving the order of characters within each word.
Args:
s (str): The input string containing multiple words separated by s... |
magic_instruct_75k | 389 | Write a Python function `filter_and_process_access_points` that takes a list of access points and a radius `area_radius_b` as input and performs the following tasks:
1. Filter the access points based on their type and distance from the center of the area.
2. Calculate the total number of access points within a certain ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def filter_and_process_access_points(access_points: List[Tuple[int, Tuple[float, float], float]], area_radius_b: float) -> Tuple[int, float]:
"""
Filters and processes access points ba... |
magic_instruct_75k | 401 | Write a Python function `extract_url_mapping(urlpatterns)` that takes a list of URL patterns and returns a dictionary mapping each URL to its corresponding view class and any additional parameters. Each URL pattern is defined using the `path` function, which takes at least three arguments: the URL pattern as a string, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Dict, Tuple
def extract_url_mapping(urlpatterns: List[Any]) -> Dict[str, Tuple[Any, ...]]:
"""
Extracts URL mappings from a list of URL patterns.
Args:
urlpatterns (List[Any]): A list ... |
magic_instruct_75k | 410 | Write a Python function to filter a list of messages based on specific criteria. Each message is represented as a dictionary with a nested structure. The function should return a new list containing only the messages that meet the following conditions:
1. The message must be from a user with the username 'devbot'.
2. T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_messages(messages: List[Dict[str, Dict[str, str]]]) -> List[Dict[str, Dict[str, str]]]:
"""
Filters a list of messages based on specific criteria.
Args:
messages (List[Dict[... |
magic_instruct_75k | 417 | Write a Python function to parse a list of configuration keys in the format "section_key" and return a dictionary where each section is a key and its value is another dictionary containing the configuration keys and their initial values as empty strings. The function should handle the grouping of keys under their respe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def parse_config_keys(config_keys: List[str]) -> Dict[str, Dict[str, str]]:
"""
Parses a list of configuration keys in the format "section_key" and returns a dictionary
where each section is a ... |
magic_instruct_75k | 428 | Create a Python class `Registrar` that manages the registration process for a university. The class should allow students to register for courses and provide functionality for adding, dropping, and viewing courses. The class should have the following methods:
1. `add_course(course_name: str)`: Adds a new course to the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
class Registrar:
def __init__(self):
"""
Initialize the registrar's records.
"""
self.courses = {} # Dictionary to map course names to sets of students
self.students ... |
magic_instruct_75k | 459 | Write a Python function to return a new list containing the unique elements of a given list `L` in the order they first appeared. The function should maintain the stability of the original order of elements, meaning that if an element appears multiple times in `L`, only the first occurrence should be included in the ou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def stable_uniq(L: List[int]) -> List[int]:
"""
Returns a new list containing the unique elements of the input list `L` in the order they first appeared.
Args:
L (List[int]): The input list ... |
magic_instruct_75k | 464 | Write a Python function to calculate the total cost of a customer's purchase, factoring in any applicable discounts. The function should take in a list of items purchased, their individual prices, and any available discount codes. The discount codes can be applied to specific items or the entire purchase. If a discount... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_total_cost(items: List[str], prices: List[float], discount_codes: List[str]) -> float:
"""
Calculate the total cost of a purchase after applying any applicable discounts.
Args:
... |
magic_instruct_75k | 473 | Write a Python function to process a dictionary and return a hyphen-separated string of values based on specific conditions. The function should iterate through the keys of the dictionary and append the corresponding values to a list `toKey` based on the following rules:
1. If the key exists in the dictionary and its c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def process_dict(obj: Dict) -> str:
"""
Processes a dictionary and returns a hyphen-separated string of values based on specific conditions.
Args:
obj (Dict): The input dictionary to process... |
magic_instruct_75k | 494 | Write a Python function to read pairs of integers from a file into a list, initialize a 2D array of size `n x n`, populate the 2D array with the values from the list, and calculate the sum of all elements on the main diagonal of the 2D array.
The code should start with:
```python
from typing import List, Tuple
def re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def read_pairs_from_file(filename: str) -> List[Tuple[int, int]]:
"""
Read pairs of integers from a file into a list.
Args:
filename (str): The name of the file to read from.
Ret... |
magic_instruct_75k | 496 | Write a Python function to extract the value of the red channel from a given 32-bit color integer. The color is stored in the format 0xAARRGGBB, where AA represents the alpha channel, RR represents the red channel, GG represents the green channel, and BB represents the blue channel. The function should return the value... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_red_channel(color: int) -> int:
"""
Extracts the value of the red channel from a given 32-bit color integer.
The color is stored in the format 0xAARRGGBB, where AA represents the alpha channel,
RR represents... |
magic_instruct_75k | 497 | Write a Python function to calculate the sum of all even numbers in a given array. The function should take an array of integers as input and return the sum of all the even numbers in the array. The code should start with:
```python
from typing import List
def sum_of_even_numbers(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(arr: List[int]) -> int:
"""
Calculate the sum of all even numbers in a given array.
Args:
arr (List[int]): The array of integers from which to calculate the sum of ev... |
magic_instruct_75k | 540 | Create a Python class `SecretNumber` that generates a random secret number within a specified range and allows users to guess the number. The class should provide methods to check if a guess is correct, to retrieve the range of the secret number, and to keep track of the number of guesses made by the user.
The class s... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
class SecretNumber:
def __init__(self, min: int, max: int):
"""
Initializes the SecretNumber class with a random secret number within the specified range.
Args:
min (int): The mini... |
magic_instruct_75k | 580 | Write a Python function to calculate the average score of a game from a given list of integer scores. The function should return the average score rounded to the nearest integer. The function should handle cases where the list is empty by returning 0.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average_score(scores: List[int]) -> int:
"""
Calculate the average score of a game from a list of integer scores.
Args:
scores (List[int]): A list of integer scores.
Retur... |
magic_instruct_75k | 585 | Write a Python function to update a dictionary with a new key-value pair. The function should handle both updating an existing key's value and adding a new key-value pair if the key does not exist. The function should start with:
```python
def update_dictionary(original_dict: dict, key: str, value) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def update_dictionary(original_dict: dict, key: str, value) -> dict:
"""
Updates the given dictionary with a new key-value pair. If the key already exists, its value is updated.
If the key does not exist, a new key-value pai... |
magic_instruct_75k | 600 | Write a Python function to update a list of high scores for a video game by inserting a new score while maintaining the list in descending order. The function should take the current list of high scores and the new score as inputs and return the updated list of high scores. The function should ensure that the list rema... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def update_high_scores(high_scores: List[int], new_score: int) -> List[int]:
"""
Updates the list of high scores by inserting a new score while maintaining the list in descending order.
Args:
... |
magic_instruct_75k | 691 | Write a Python function to calculate the cumulative count of changes at each time interval from a given list of integers representing the number of changes made to a system at different time intervals. The function should take the list of changes as input and return a new list containing the cumulative count of changes... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_changes(changes: List[int]) -> List[int]:
"""
Calculate the cumulative count of changes at each time interval from a given list of integers.
Args:
changes (List[int]): A list ... |
magic_instruct_75k | 699 | Write a Python function to count the number of strings in a list that contain a specific substring, considering the search to be case-insensitive. The substring can be part of a larger word within the candidate string.
The code should start with:
```python
from typing import List
def count_substring_matches(candidate... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_substring_matches(candidates: List[str], substring: str) -> int:
"""
Counts the number of strings in a list that contain a specific substring, considering the search to be case-insensitive.
... |
magic_instruct_75k | 701 | Write a Python function to automate the process of updating DNS servers for a network interface on a Linux-based server. The function should:
1. Modify the `/etc/dhcp/dhclient.conf` file to replace the line `#prepend domain-name-servers 127.0.0.1;` with `prepend domain-name-servers 8.8.8.8, 8.8.4.4;`.
2. Restart the ne... | Here is the Python code to solve the given problem in the markdown block:
```python
import subprocess
def update_dns_servers():
"""
Automates the process of updating DNS servers for the network interface on a Linux-based server.
This function performs the following tasks:
1. Modifies the `/etc/dhcp/dh... |
magic_instruct_75k | 702 | Write a Python function to calculate the cumulative sum of a list of integers. The cumulative sum at each index `i` in the output list should be the sum of all elements from index 0 to index `i` in the input list. The function should start with:
```python
from typing import List
def cumulative_sum(nums: List[int]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(nums: List[int]) -> List[int]:
"""
Calculate the cumulative sum of a list of integers.
Args:
nums (List[int]): The input list of integers.
Returns:
List[int]:... |
magic_instruct_75k | 723 | Write a Python function to manage a simple task management system. The system should allow adding tasks, marking tasks as completed, and displaying the list of tasks. You need to implement the `TaskManager` class with the following requirements:
1. The `TaskManager` class should have a property `tasks` which is a list... | Here is the Python code to solve the given problem in the markdown block:
```python
class TaskManager:
def __init__(self):
"""
Initialize the TaskManager with an empty list of tasks.
"""
self.tasks = []
def add_task(self, description: str) -> None:
"""
Add a new ... |
magic_instruct_75k | 741 | Write a Python function to generate CSS code based on a given dictionary of style attributes. The function should accept a dictionary where the keys represent CSS property names and the values represent the corresponding property values. The function should then construct and return a string representing the CSS code f... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_css(style_attributes: dict) -> str:
"""
Generates CSS code based on the given dictionary of style attributes.
Args:
style_attributes (dict): A dictionary where keys are CSS property names and values are the ... |
magic_instruct_75k | 745 | Write a Python function to parse command-line arguments and extract key-value pairs from them. The command-line arguments are provided in the form of a list of strings, where each key is preceded by double dashes (`--`) and is followed by a space and then the corresponding value. The function should return a dictionary... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def parse_command_line_arguments(arguments: List[str]) -> Dict[str, str]:
"""
Parses command-line arguments and extracts key-value pairs.
Args:
arguments (List[str]): A list of strings... |
magic_instruct_75k | 758 | Write a Python function `parse_attribute_map` that takes an attribute map as input and returns a list of tuples containing the attribute, sub-attribute, and URI. The attribute map is represented as a dictionary where the keys are tuples of attribute, sub-attribute, and URI, and the values are the corresponding paths. I... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Optional
def parse_attribute_map(attr_map: Dict[Tuple[str, Optional[str], Optional[str]], str]) -> List[Tuple[str, Optional[str], Optional[str]]]:
"""
Parses an attribute map and returns a ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.