source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 106,780 | Write a Python function to format and return a message string that includes a predefined prefix and a user-provided message. The function should concatenate the prefix and the message, ensuring that the message is properly formatted and returned as a single string. The code should start with:
```python
def format_messa... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_message(prefix: str, message: str) -> str:
"""
Formats and returns a message string by concatenating a predefined prefix and a user-provided message.
Args:
prefix (str): The predefined prefix to be includ... |
magic_evol_110k | 106,787 | Write a Python function to calculate the number of distinct paths to traverse a given n x m matrix from the bottom-left corner to the top-right corner, moving only upwards or to the right. The function should start with:
```python
def count_distinct_paths(n: int, m: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_distinct_paths(n: int, m: int) -> int:
"""
Calculate the number of distinct paths to traverse an n x m matrix from the bottom-left corner to the top-right corner,
moving only upwards or to the right.
Args:
... |
magic_evol_110k | 106,792 | Write a Python function to calculate the sum of the squares of all even numbers in a given list of integers. The function should iterate through the list, identify the even numbers, square each of them, and then return the sum of these squared values.
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 sum_of_squared_evens(lst: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
lst (List[int]): A list of integers.
Returns:
... |
magic_evol_110k | 106,812 | Write a Python function to find the missing numbers in a given string of space-separated integers. The function should return a string of space-separated integers that are missing between the minimum and maximum values found in the input string. If the input string is empty, the function should return "0...n". If no nu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def missing_numbers(s: str) -> str:
"""
Find the missing numbers in a given string of space-separated integers.
Args:
s (str): A string containing space-separated integers.
Returns:
... |
magic_evol_110k | 106,833 | Write a Python function to find the intersection of two given arrays and return it as a new array sorted in ascending order. The original arrays can be of any length and can contain numbers in any order. The numbers can range from -10,000 to 10,000. The function should handle cases where the two arrays have some or no ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection(list_one: List[int], list_two: List[int]) -> List[int]:
"""
Finds the intersection of two given arrays and returns it as a new array sorted in ascending order.
Args:
li... |
magic_evol_110k | 106,842 | Write a Python function to find the Kth smallest element in a given array of distinct integers. The function should handle dynamic values of K and N (length of the array). If K is out of bounds (i.e., K is less than 1 or greater than N), the function should return `None`.
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, Optional
import heapq
def find_kth_smallest(arr: List[int], k: int) -> Optional[int]:
"""
Find the Kth smallest element in a given array of distinct integers.
Args:
arr (List[int]): The arr... |
magic_evol_110k | 106,851 | Write a Python function to convert a given numerical value into its equivalent string representation in English words. The function should handle numbers in the range from 0 to 999,999. For example, the number 1234 should be converted to "One Thousand Two Hundred Thirty Four".
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def number_to_words(num: int) -> str:
"""
Converts a given numerical value into its equivalent string representation in English words.
Args:
num (int): The numerical value to convert. Must be in the range 0 to 999,9... |
magic_evol_110k | 106,855 | Write a Python function to find the name with the minimum frequency in a given dictionary of names and their respective frequencies. If multiple names have the same minimum frequency, return the name that is alphabetically first. The function should start with:
```python
from typing import Dict
def find_min_frequency_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_min_frequency_name(name_frequency: Dict[str, int]) -> str:
"""
Find the name with the minimum frequency in a given dictionary of names and their respective frequencies.
If multiple names hav... |
magic_evol_110k | 106,858 | Write a Python function to generate a random number within a specified range, allowing the user to specify whether the endpoints of the range are included or excluded. The function should ensure that the distribution of the generated numbers is uniform.
The code should start with:
```python
import random
def generate... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_number(start: int, end: int, include_start: bool = True, include_end: bool = True) -> int:
"""
Generates a random integer within a specified range, with customizable inclusion of the range endp... |
magic_evol_110k | 106,872 | Write a Python function to detect and remove duplicates from a given list of integers. The function should return a new list with all duplicate elements removed, while maintaining the order of the first occurrence of each element.
The code should start with:
```python
from typing import List
def remove_duplicates(arr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(arr: List[int]) -> List[int]:
"""
Removes duplicates from the given list of integers while preserving the order of the first occurrence of each element.
Args:
arr (List... |
magic_evol_110k | 106,882 | Write a Python function to flatten a given two-dimensional matrix into a one-dimensional list. The function should correct any errors in the provided pseudocode and ensure that the matrix is transformed correctly regardless of its dimensions. The function should start with:
```python
from typing import List
def flatte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a given two-dimensional matrix into a one-dimensional list.
Args:
matrix (List[List[int]]): The two-dimensional matrix ... |
magic_evol_110k | 106,899 | Write a Python function that takes a list of items and prints each item with a custom message. The function should be able to handle lists of any data type, including strings, numbers, and other objects. The message should be formatted to include the index of the item and the item itself.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def print_items_with_message(items: List[Any]) -> None:
"""
Prints each item in the given list with a custom message that includes the item's index.
Args:
items (List[Any]): The list of... |
magic_evol_110k | 106,907 | Write a Python function to swap two integers using bitwise XOR operations instead of a temporary variable. The function should take two integers as input and return a tuple containing the swapped integers.
The code should start with:
```python
def swap_using_xor(a: int, b: int) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def swap_using_xor(a: int, b: int) -> tuple:
"""
Swaps two integers using bitwise XOR operations without using a temporary variable.
Args:
a (int): The first integer.
b (int): The second integer.
Return... |
magic_evol_110k | 106,914 | Write a Python function to display the elements of a given two-dimensional matrix in a diagonal zig-zag order. The function should handle null or irregularly shaped matrices gracefully without raising exceptions. If an irregularly shaped or empty matrix is encountered, the function should return `"Invalid matrix"`.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def diagonal_zig_zag(input_matrix: List[List[int]]) -> Union[str, List[int]]:
"""
Display the elements of a given two-dimensional matrix in a diagonal zig-zag order.
Args:
input_matri... |
magic_evol_110k | 106,945 | Write a Python function to reverse a given string using a custom iterative approach. The function should not use Python's built-in slicing (`[::-1]`) or the `reversed()` function. Instead, it should use a loop to manually reverse the string.
The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses a given string using a custom iterative approach.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Initial... |
magic_evol_110k | 106,968 | Write a Python function to determine if two given strings are anagrams of each other, ignoring spaces and case sensitivity. The function should return a boolean value indicating whether the two strings are anagrams.
The code should start with:
```python
def are_anagrams(s1: str, s2: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(s1: str, s2: str) -> bool:
"""
Determines if two strings are anagrams of each other, ignoring spaces and case sensitivity.
Args:
s1 (str): The first string to compare.
s2 (str): The second s... |
magic_evol_110k | 106,969 | Write a Python function to calculate the sum of the coordinates of a point on the graph of \( y = h(x) \) given the coordinates of a point on the graph of \( y = g(x) \). The function should take the x-coordinate and the y-coordinate of the point on the graph of \( y = g(x) \) as inputs and return the sum of the coordi... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_coordinates(x: int, y: int) -> int:
"""
Calculate the sum of the coordinates of a point on the graph of y = h(x)
given the coordinates of a point on the graph of y = g(x).
Args:
x (int): The x-coordin... |
magic_evol_110k | 106,971 | Write a Python function to extract the second numerical element from each sublist within a given list of lists. The function should handle lists of varying lengths and ensure that only valid sublists (those containing at least two elements) are processed. If a sublist does not contain at least two elements, it should b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_second_elements(nested_list: List[List[int]]) -> List[int]:
"""
Extracts the second numerical element from each sublist within a given list of lists.
Only sublists containing at least two... |
magic_evol_110k | 106,984 | Write a Python function to sort only the string elements in a mixed list of integers and strings, while keeping the integers in their original positions. The function should start with:
```python
from typing import List, Union
def sort_strings_in_mixed_list(mixed_list: List[Union[int, str]]) -> List[Union[int, str]]:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sort_strings_in_mixed_list(mixed_list: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Sorts only the string elements in a mixed list of integers and strings, while keeping the integers i... |
magic_evol_110k | 106,991 | Write a Python function to calculate the number of days between two given dates. The dates will be provided as strings in the format "DD Month, YYYY" (e.g., "27 April, 2020"). The function should handle the conversion of the date strings to datetime objects and compute the difference in days.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def days_between_dates(date1: str, date2: str) -> int:
"""
Calculate the number of days between two given dates.
Args:
date1 (str): The first date in the format "DD Month, YYYY".
... |
magic_evol_110k | 107,003 | Write a Python function to calculate the total number of chairs set up for a meeting after adding a specified number of chairs to each row. The function should take the number of rows, the initial number of chairs per row, and the number of additional chairs per row as inputs. The function should return the new total n... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_chairs(num_rows: int, initial_chairs_per_row: int, additional_chairs_per_row: int) -> int:
"""
Calculate the total number of chairs set up for a meeting after adding additional chairs to each row.
Args:
... |
magic_evol_110k | 107,014 | Write a Python function to extract elements from a given numeric sequence where the rank (1-based index) of each element in the sequence is greater than or equal to a specified integer limit. The function should return a new list containing only those elements that meet the condition.
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
def extract_elements_by_rank(sequence: List[int], limit: int) -> List[int]:
"""
Extracts elements from the given numeric sequence where the rank (1-based index) of each element
is greater than or equ... |
magic_evol_110k | 107,028 | Write a Python function to print numbers from 0 to n (inclusive) using a while loop, and implement exception handling to catch and handle any potential `ArithmeticError`. The function should start with:
```python
def print_numbers_up_to(n: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_numbers_up_to(n: int) -> None:
"""
Prints numbers from 0 to n (inclusive) using a while loop.
Implements exception handling to catch and handle any potential ArithmeticError.
Args:
n (int): The upper l... |
magic_evol_110k | 107,076 | Write a Python function to perform an insertion sort on a given list of numbers. The function should sort the list in ascending order. The code should start with:
```python
from typing import List
def insertion_sort(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the insertion sort algorithm.
Args:
numbers (List[int]): The list of integers to be... |
magic_evol_110k | 107,079 | Write a Python function to compute the factorial of a non-negative integer `n`, with the capability to handle an optional parameter `power`. If `power` is provided, the function should return the factorial of `n` raised to the power of `power`. Additionally, the function should handle a third optional parameter `modulo... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def factorial(n: int, power: int = 1, modulo: int = None) -> int:
"""
Compute the factorial of a non-negative integer `n`, optionally raised to the power of `power` and modulo `modulo`.
Args:
n (int): T... |
magic_evol_110k | 107,095 | Write a Python function to determine if a given integer is a palindromic number. A number is considered palindromic if its numerical representation remains identical when read in reverse. The function should not convert the integer to a string for the check.
The code should start with:
```python
def is_palindromic_num... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindromic_number(x: int) -> bool:
"""
Determine if a given integer is a palindromic number without converting it to a string.
Args:
x (int): The integer to check for palindromic property.
Returns:
... |
magic_evol_110k | 107,103 | Write a Python function to sort a list of numbers that includes negative numbers, decimals, and duplicates, and find the index of a given target number after sorting. The function should return both the sorted list and the index of the target number in the sorted list.
The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_and_find_index(num_list: List[float], target: float) -> Tuple[List[float], int]:
"""
Sorts a list of numbers and finds the index of a given target number after sorting.
Args:
... |
magic_evol_110k | 107,111 | Write a Python function to rotate an array to the right by `k` steps, where `k` is a non-negative integer. Additionally, return the sum of the first and last elements of the rotated array. The function should be efficient, using `O(1)` extra space and `O(n)` time complexity.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_array_and_sum(nums: List[int], k: int) -> int:
"""
Rotates the given array to the right by `k` steps and returns the sum of the first and last elements of the rotated array.
Args:
... |
magic_evol_110k | 107,114 | Write a Python function to remove duplicates from a given list while maintaining the order of elements. The function should be optimized for both time and space complexity. The provided erroneous code should not be used, and a more optimized solution should be implemented.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_optimized(arr: List[int]) -> List[int]:
"""
Removes duplicates from the given list while maintaining the order of elements.
Args:
arr (List[int]): The list from which d... |
magic_evol_110k | 107,117 | Write a Python function to store and retrieve multiple addresses efficiently. Each address should be stored as a tuple containing a street name and a house number. The function should allow for adding new addresses and retrieving existing ones. The code should start with:
```python
def store_and_retrieve_addresses() ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def store_and_retrieve_addresses() -> dict:
"""
Stores and retrieves multiple addresses efficiently.
Returns:
dict: A dictionary containing addresses where the key is the street name and the value is a tuple (street... |
magic_evol_110k | 107,120 | Write a Python function to sort a list of integers using the bubble sort algorithm. The function should handle both positive and negative numbers and sort them from least to greatest. The code should start with:
```python
from typing import List
def bubble_sort(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def bubble_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers using the bubble sort algorithm.
Args:
numbers (List[int]): The list of integers to be sorted.
Returns:
... |
magic_evol_110k | 107,126 | Write a Python function to arrange a given array of integers in descending order and calculate the sum of all prime numbers in the array. The function should return a tuple containing the sorted array and the sum of the prime numbers.
The code should start with:
```python
from typing import List, Tuple
def arrange_an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwis... |
magic_evol_110k | 107,134 | Write a Python function to count the number of consonants in a given string. A consonant is defined as any alphabetic character that is not a vowel (i.e., 'a', 'e', 'i', 'o', 'u'). The function should be case-insensitive.
The code should start with:
```python
def consonant_count(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def consonant_count(s: str) -> int:
"""
Count the number of consonants in the given string.
Args:
s (str): The input string to count consonants from.
Returns:
int: The total number of consonants in the ... |
magic_evol_110k | 107,137 | Write a Python function to create a dictionary from a list of tuples. Each tuple contains two integer values. The key of the dictionary should be the first element of each tuple, and the value should be a list of the product of the first element and the second element of each tuple. If the key is already present in the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_product_dict(list_of_tuples: List[Tuple[int, int]]) -> Dict[int, List[int]]:
"""
Create a dictionary from a list of tuples. Each tuple contains two integer values.
The key of ... |
magic_evol_110k | 107,140 | Write a Python function to generate a three-dimensional stochastic matrix with specified dimensions. The matrix should have four strata, each containing seven ranks, and be organized along two columnar lines. Each rank in a column should sum up to 1.0, making the matrix stochastic.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_stochastic_matrix(strata: int, rank: int, column: int) -> np.ndarray:
"""
Generates a three-dimensional stochastic matrix with the specified dimensions.
Args:
strata (int): The numbe... |
magic_evol_110k | 107,144 | Write a Python function that generates a dictionary where the keys are characters of a given string and the corresponding values are their respective ASCII values. The function should filter out any non-alphanumeric characters (including spaces) from the input string before processing. Additionally, the function must b... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_ascii_dict(input_string: str) -> dict:
"""
Generates a dictionary where the keys are alphanumeric characters from the input string and the values are their respective ASCII values.
Args:
input_string (s... |
magic_evol_110k | 107,149 | Write a Python function to extract even numbers from three given lists, merge them, and sort them in increasing order. Additionally, implement a helper function to handle the extraction and sorting logic. The main function should then use this helper function to achieve the desired result. The code should be corrected ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_even_and_merge(l1: List[int], l2: List[int], l3: List[int]) -> List[int]:
"""
Obtains only the even numbers from three lists, merges and sorts them in increasing order.
Args:
l1 (Lis... |
magic_evol_110k | 107,161 | Write a Python function to find the indices of all occurrences of a specified number in a given two-dimensional matrix. The function should return a list of tuples, where each tuple represents the row and column indices of an occurrence of the specified number.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_all_occurrences(matrix: List[List[int]], target: int) -> List[Tuple[int, int]]:
"""
Find the indices of all occurrences of a specified number in a two-dimensional matrix.
Args:
... |
magic_evol_110k | 107,179 | Write a Python function to determine which characters from a given selection are found in a word string, and quantify the frequency of occurrence for each character found. The function should be optimized to minimize the number of iterations over the word string.
The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_characters(word: str, characters: str) -> Dict[str, int]:
"""
Determines which characters from a given selection are found in a word string,
and quantifies the frequency of occurrence for ea... |
magic_evol_110k | 107,191 | Write a Python function to merge two dictionaries without losing any key-value pairs. If there are overlapping keys, the value from the second dictionary should overwrite the value from the first dictionary. The function should be able to handle any number of dictionaries, not just two. The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_multiple_dictionaries(*dicts: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge multiple dictionaries into a single dictionary. If there are overlapping keys,
the value from the last dictio... |
magic_evol_110k | 107,205 | Write a Python function to generate a list of numbers within a specified range using a while loop. The function should append each number in the range to the list and return the list. The range should be inclusive of both the start and end values.
The code should start with:
```python
from typing import List
def gene... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_numbers_in_range(start: int, end: int) -> List[int]:
"""
Generate a list of numbers within the specified range [start, end] (inclusive) using a while loop.
Args:
start (int): Th... |
magic_evol_110k | 107,215 | Write a Python function to parse and isolate the first and last names from a given full name string. The function should handle names with multiple middle names or initials. The code should start with:
```python
def parse_name(full_name: str) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def parse_name(full_name: str) -> tuple:
"""
Parses and isolates the first and last names from a given full name string.
Args:
full_name (str): The full name string to be parsed.
Returns:
tuple: A tuple... |
magic_evol_110k | 107,219 | Write a Python function to extend a given string by repeatedly adding a specified character at the beginning of the string until the string reaches a specified minimum length. The function should handle cases where the minimum length is less than or equal to the original string length by returning the original string u... | Here is the Python code to solve the given problem in the markdown block:
```python
def extend_string_to_min_length(s: str, min_len: int, char: str) -> str:
"""
Extends the given string by adding a specified character at the beginning until the string reaches a specified minimum length.
Args:
s (st... |
magic_evol_110k | 107,220 | Write a Python function to calculate the number of pies Carl baked for each school fund-raiser, given the total number of pies baked, the number of pies baked for his own family, and the number of school fund-raisers. The function should return the number of pies baked for each school event.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_pies_per_event(total_pies: int, family_pies: int, school_events: int) -> float:
"""
Calculate the number of pies Carl baked for each school fund-raiser.
Args:
total_pies (int): The total number of pies... |
magic_evol_110k | 107,244 | Write a Python function to calculate the greatest common divisor (GCD) of two non-negative integers `a` and `b`. The function should handle edge cases such as when one or both of the integers are zero. The code should start with:
```python
def greatest_common_divisor(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def greatest_common_divisor(a: int, b: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two non-negative integers a and b.
Args:
a (int): The first non-negative integer.
b (int): The second no... |
magic_evol_110k | 107,250 | Write a Python function to recursively merge two pre-sorted subarrays into a single sorted array. The function should take two lists as input and return a new list that contains all elements from both input lists in sorted order. The function should be implemented using recursion and should not modify the original inpu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(ar1: List[int], ar2: List[int]) -> List[int]:
"""
Recursively merges two pre-sorted subarrays into a single sorted array.
Args:
ar1 (List[int]): The first pre-sorted ... |
magic_evol_110k | 107,264 | Write a Python function to validate email addresses using a regular expression. The function should determine if a given email address is in a valid format according to common email standards. The function should return `True` if the email is valid and `False` otherwise.
The code should start with:
```python
import re... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validate an email address using a regular expression.
Args:
email (str): The email address to validate.
Returns:
bool: True if the email is valid, ... |
magic_evol_110k | 107,267 | Write a Python function to check if a given element exists in a list. The function should return `True` if the element is found in the list, and `False` otherwise. The function should handle lists of any type of elements, including integers, strings, and other objects. 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, Any
def contains_element(my_list: List[Any], elem: Any) -> bool:
"""
Check if a given element exists in the provided list.
Args:
my_list (List[Any]): The list in which to search for the ele... |
magic_evol_110k | 107,272 | Write a Python function to count the occurrences of zeros and 'False-like' values in a given matrix. The function should accept an optional boolean argument `strict_zero` that determines whether to count only explicit zeros or also 'False-like' values such as `0`, `0.0`, `False`, `''`, and `None`. The function should h... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def count_zeros(matrix: List[List[Union[int, float, str, bool]]], strict_zero: bool = False) -> int:
"""
Counts the occurrences of zeros and 'False-like' values in a given matrix.
Args:
... |
magic_evol_110k | 107,273 | Write a Python function to count and categorize the command-line arguments provided when the script is executed. The function should validate each argument and categorize it as either a number (integer or float) or a string. The function should return a dictionary with the count of numbers and strings.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
import sys
from typing import Dict
def categorize_arguments() -> Dict[str, int]:
"""
Count and categorize the command-line arguments as numbers or strings.
Returns:
Dict[str, int]: A dictionary with keys 'numbers' ... |
magic_evol_110k | 107,283 | Write a Python function to sort a given matrix of integers in ascending order. The matrix is represented as a list of lists, where each sublist represents a row in the matrix. The function should return a new matrix with the same dimensions, where all elements are sorted in ascending order.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Sorts a given matrix of integers in ascending order.
Args:
matrix (List[List[int]]): A 2D list of integers representing the m... |
magic_evol_110k | 107,287 | Write a Python function to generate a dictionary from two tuples that have the same number of elements. Ensure that no tuple contains any repeated elements and verify that all elements are non-empty strings. The function should return the generated dictionary if the conditions are met, otherwise, it should return an ap... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict, Union
def generate_dictionary(tuple1: Tuple[str], tuple2: Tuple[str]) -> Union[Dict[str, str], str]:
"""
Generate a dictionary from two tuples that have the same number of elements.
Ensure th... |
magic_evol_110k | 107,292 | Write a Python function to generate a sequence of numbers from 1 to `x-1` using a `while` loop. Additionally, compare the performance of this function with a similar function that uses a `for` loop. Finally, identify and correct any errors in an erroneous version of the `while` loop function, and compare its performanc... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sequence_while(x: int) -> list:
"""
Generate a sequence of numbers from 1 to x-1 using a while loop.
Args:
x (int): The upper limit of the sequence (exclusive).
Returns:
list: A list contai... |
magic_evol_110k | 107,304 | Write a Python function to verify that each element within a given bi-dimensional matrix strictly follows an incrementing sequence both horizontally across individual rows and vertically through all intersecting columns. The function should return `True` if the matrix satisfies the condition, and `False` otherwise.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_incrementing_matrix(matrix: List[List[int]]) -> bool:
"""
Verify that each element within a given bi-dimensional matrix strictly follows an incrementing sequence
both horizontally across indiv... |
magic_evol_110k | 107,327 | Write a Python function to calculate the number of non-negative even integers less than a given integer `N`. The function should handle edge cases where `N` is less than 0 or not an integer. The function should be optimized to avoid iterating through every integer up to `N` to identify even numbers.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_even_numbers(N: int) -> int:
"""
Calculate the number of non-negative even integers less than a given integer N.
Args:
N (int): The integer input provided by the user.
Returns:
int: The number... |
magic_evol_110k | 107,337 | Write a Python function to reverse the characters in a given input string using a stack data structure. The function should start with:
```python
def reverse_string_with_stack(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_with_stack(input_string: str) -> str:
"""
Reverses the characters in the given input string using a stack data structure.
Args:
input_string (str): The input string to be reversed.
Returns:
... |
magic_evol_110k | 107,340 | Write a Python function to calculate the shortest distance from the vertical y-axis to a given point on a Cartesian plane. The point is represented by its coordinates (x, y). The function should return the absolute value of the x-coordinate of the point, as this represents the shortest distance to the y-axis.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def distance_to_y_axis(point: tuple) -> float:
"""
Calculate the shortest distance from the vertical y-axis to a given point on a Cartesian plane.
Args:
point (tuple): A tuple representing the coordinates (x, y) of ... |
magic_evol_110k | 107,343 | Write a Python function to convert a given sequence of words into title case, where the first letter of each word is capitalized, and the rest of the letters are in lowercase. The function should handle various edge cases, such as words with mixed cases, punctuation, and numbers.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_title_case(text: str) -> str:
"""
Converts a given sequence of words into title case, where the first letter of each word is capitalized,
and the rest of the letters are in lowercase. Punctuation and numbers r... |
magic_evol_110k | 107,345 | Write a Python function to filter a dictionary based on a given limit, returning a new dictionary containing only the key-value pairs where the value is above the specified limit. The function should use dictionary comprehension for this purpose.
The code should start with:
```python
from typing import Dict
def filte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_dict_above_limit(d: Dict[str, int], limit: int) -> Dict[str, int]:
"""
Filters a dictionary to include only the key-value pairs where the value is above a specified limit.
Args:
d... |
magic_evol_110k | 107,350 | Write a Python function to find and return all prime numbers that are less than or exactly equal to a given integer `n`. The function should handle invalid input gracefully by returning an empty list if `n` is less than 2. The code should start with:
```python
def find_primes_up_to(n: int) -> list:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_primes_up_to(n: int) -> list:
"""
Find all prime numbers that are less than or exactly equal to a given integer `n`.
Args:
n (int): The upper limit to find prime numbers.
Returns:
list: A list ... |
magic_evol_110k | 107,364 | Write a Python function to determine if a given number is a prime number. The function should use an efficient algorithm to check for factors up to the square root of the number. The function should also handle edge cases such as numbers less than 2, which are not prime.
The code should start with:
```python
def is_pr... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Determines if a given number is a prime number.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"""
... |
magic_evol_110k | 107,367 | Write a Python function to create a composite data structure, specifically a dictionary, using two tuples that share a congruent number of constituent elements. The function should take two tuples as input and return a dictionary where the elements of the first tuple are the keys and the elements of the second tuple ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def create_composite_dict(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]:
"""
Creates a dictionary from two tuples that share a congruent number of elements.
Args:
tuple1 (... |
magic_evol_110k | 107,383 | Write a Python function to calculate the occurrence rate of each alphabet letter within a given string, considering case sensitivity, and store the result in a dictionary. Exclude digits and special characters from the count.
The code should start with:
```python
from typing import Dict
def letter_occurrence_rate(tex... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def letter_occurrence_rate(text: str) -> Dict[str, int]:
"""
Calculate the occurrence rate of each alphabet letter in the given text, considering case sensitivity.
Args:
text (str): The inpu... |
magic_evol_110k | 107,394 | Write a Python function to remove all whitespace characters and punctuation symbols from a given string. The function should return the cleaned string with only the alphanumeric characters.
The code should start with:
```python
import string
def clean_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import string
def clean_string(s: str) -> str:
"""
Removes all whitespace characters and punctuation symbols from the given string.
Args:
s (str): The input string from which to remove whitespace and punctuation.
... |
magic_evol_110k | 107,421 | Write a Python function to implement the Bubble Sort algorithm to sort a given list of integers in ascending order. The function should systematically iterate over the list elements and employ comparative operations to achieve the sorting. The code should start with:
```python
from typing import List
def bubble_sort(n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(number_list: List[int]) -> List[int]:
"""
Sorts a given list of integers in ascending order using the Bubble Sort algorithm.
Args:
number_list (List[int]): The list of intege... |
magic_evol_110k | 107,423 | Write a Python function to format a phone number in the specified format `(XXX) XXX-XXXX` where `X` represents a digit. The function should validate the input to ensure it is a 10-digit string consisting only of digits. If the input is invalid, the function should return the string "Invalid phone number".
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_phone_number(phone_number: str) -> str:
"""
Formats a 10-digit phone number into the format (XXX) XXX-XXXX.
Args:
phone_number (str): A string representing a 10-digit phone number.
Returns:
s... |
magic_evol_110k | 107,431 | Write a Python function to safely access an element in a string by providing an index. If the index is out of range, the function should 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... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_access(s: str, index: int, default: str = None) -> str:
"""
Safely access an element in a string by providing an index. If the index is out of range, return a default value.
Args:
s (str): The input string.... |
magic_evol_110k | 107,451 | Write a Python function to compute the cumulative sum of each number's square within a provided list. The function should return a list where each element at index `i` is the cumulative sum of the squares of the elements from the start of the list up to index `i`.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_square_sum(numbers: List[int]) -> List[int]:
"""
Computes the cumulative sum of each number's square within the provided list.
Args:
numbers (List[int]): A list of integers fo... |
magic_evol_110k | 107,468 | Write a Python function to find the first and last occurrence of a designated target value within a descending order numerical array. The function should return the indices of the first and last occurrence of the target value. If the target value is not found in the array, the function should return `-1` for both indic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_first_and_last_occurrence(lst: List[int], target: int) -> Tuple[int, int]:
"""
Find the first and last occurrence of a target value in a descending order numerical array.
Args:
... |
magic_evol_110k | 107,476 | Write a Python function to compute the factorial of a given non-negative integer. The function should handle edge cases such as negative numbers and non-integer inputs, returning appropriate error messages in such scenarios. The function should not use external libraries or modules like `math.factorial()` to perform th... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int or str:
"""
Compute the factorial of a given non-negative integer.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
int or str: The facto... |
magic_evol_110k | 107,495 | Write a Python function to retrieve the User_ID from a database using a username, ensuring that the username comparison is case-insensitive. The function should accept a username as input and return the corresponding User_ID. If no matching User_ID is found, the function should return `None`.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
import sqlite3
def get_user_id(username: str) -> Optional[int]:
"""
Retrieve the User_ID from the database using a case-insensitive username comparison.
Args:
username (str): The usernam... |
magic_evol_110k | 107,496 | Write a Python function to find the numerical positions of all singleton elements in a given list of integers. A singleton element is an element that appears exactly once in the list. The function should return a list of indices where these singleton elements are located.
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
from collections import Counter
def find_singleton_positions(arr: List[int]) -> List[int]:
"""
Find the positions of all singleton elements in a given list of integers.
Args:
arr (List[int])... |
magic_evol_110k | 107,506 | Write a Python function to create a multidimensional, hierarchical dictionary from two given lists: one containing unique keys and the other containing corresponding values. The function should handle cases where the keys and values lists are not of the same length by either truncating the longer list or filling in def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def create_hierarchical_dict(keys: List[str], values: List[Any], default_value: Any = None) -> dict:
"""
Creates a hierarchical dictionary from two lists: one containing unique keys and the other co... |
magic_evol_110k | 107,511 | Write a Python function to extract all email addresses associated with the domain "gmail.com" from a given text using regular expressions. The function should be able to handle various formats of email addresses and ensure that only valid "gmail.com" addresses are extracted. The code should start with:
```python
import... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_gmail_addresses(text: str) -> List[str]:
"""
Extracts all email addresses associated with the domain "gmail.com" from the given text.
Args:
text (str): The input text f... |
magic_evol_110k | 107,546 | Write a Python function to incorporate a specified element into an existing data structure, specifically an array. The function should append the specified element to the end of the array and return the modified array. The code should start with:
```python
from typing import List
def incorporate_element(arr: List[str]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def incorporate_element(arr: List[str], element: str) -> List[str]:
"""
Incorporates a specified element into an existing array by appending it to the end.
Args:
arr (List[str]): The existin... |
magic_evol_110k | 107,563 | Write a Python function to perform a bijective multiplication operation on two distinct rational integers. The function should accept two integers as input and return their product. The function should also ensure that the inputs are distinct and rational integers. If the inputs are not distinct or not rational integer... | Here is the Python code to solve the given problem in the markdown block:
```python
def bijective_multiplication(num_1: int, num_2: int) -> int:
"""
Perform a bijective multiplication operation on two distinct rational integers.
Args:
num_1 (int): The first rational integer.
num_2 (int): Th... |
magic_evol_110k | 107,570 | Write a Python function to filter out and return a new list containing only the odd numbers from a given list of integers. The function should handle lists of any size, including empty lists. The code should start with:
```python
from typing import List
def get_odd_numbers(num_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_odd_numbers(num_list: List[int]) -> List[int]:
"""
Returns a new list containing only the odd numbers from the given list of integers.
Args:
num_list (List[int]): The list of integer... |
magic_evol_110k | 107,596 | Write a Python function to rotate an array such that the last element becomes the first element, and the rest of the elements are shifted to the right by one position. The function should handle arrays of varying lengths and ensure that the original array is modified in place. The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_array(nums: List[int]) -> List[int]:
"""
Rotate the array such that the last element becomes the first element,
and the rest of the elements are shifted to the right by one position.
... |
magic_evol_110k | 107,609 | Write a Python function to determine if a given integer is an even number. The function should return `True` if the number is even and `False` otherwise. The function should be named `is_num_even` and should accept a single integer as input.
The code should start with:
```python
def is_num_even(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_num_even(num: int) -> bool:
"""
Determines if a given integer is an even number.
Args:
num (int): The integer to check for evenness.
Returns:
bool: True if the number is even, False otherwise.
... |
magic_evol_110k | 107,613 | Write a Python function to encode a string by shifting each character two places to the right in the alphabet, and another function to decode the encoded string by shifting each character two places to the left. Ensure that the decoding function correctly handles overflow conditions (characters beyond 'z' or 'Z'). Addi... | Here is the Python code to solve the given problem in the markdown block:
```python
def encode_string(text: str) -> str:
"""
Encodes the given string by shifting each character two places to the right in the alphabet.
Args:
text (str): The string to be encoded.
Returns:
str: The encode... |
magic_evol_110k | 107,619 | Write a Python function to calculate the least common multiple (LCM) of two non-negative integers, ensuring that it handles zero values correctly and efficiently. The function should use the greatest common divisor (GCD) to compute the LCM. The code should start with:
```python
import math
def least_common_multiple(x:... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def least_common_multiple(x: int, y: int) -> int:
"""
Calculate the least common multiple (LCM) of two non-negative integers x and y.
Args:
x (int): The first non-negative integer.
y (int): The ... |
magic_evol_110k | 107,622 | Write a Python function to filter out all odd numbers from a given list of integers. The function should return a new list containing only the even numbers from the input list. The code should start with:
```python
from typing import List
def filter_even_numbers(input_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_even_numbers(input_list: List[int]) -> List[int]:
"""
Filters out all odd numbers from the given list of integers and returns a new list containing only the even numbers.
Args:
in... |
magic_evol_110k | 107,632 | Write a Python function to determine if two given strings are permutations of each other. A permutation is a rearrangement of characters. The function should return `True` if the two strings are permutations of each other, and `False` otherwise. The function should handle strings of different lengths by returning `Fals... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
def are_permutations(str1: str, str2: str) -> bool:
"""
Determine if two given strings are permutations of each other.
Args:
str1 (str): The first string to compare.
str2 (st... |
magic_evol_110k | 107,634 | Write a Python function to insert an element into a sorted list at a specified index while maintaining the order of the list. If the specified index is out of bounds, the element should be inserted at the nearest valid position to maintain the order. The function should return the modified list.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insert_into_sorted_list(sorted_list: List[int], element: int, index: int) -> List[int]:
"""
Inserts an element into a sorted list at a specified index while maintaining the order of the list.
If ... |
magic_evol_110k | 107,643 | Write a Python function to calculate the frequency of a specific word in a given sentence, considering case insensitivity. The function should handle punctuation and multiple spaces gracefully.
The code should start with:
```python
from typing import List
def word_frequency(sentence: str, word: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def word_frequency(sentence: str, word: str) -> int:
"""
Calculate the frequency of a specific word in a given sentence, considering case insensitivity.
Args:
sentence (str): The s... |
magic_evol_110k | 107,645 | Write a Python function to count the occurrences of each unique integer in a given two-dimensional array and return the results sorted by the frequency of occurrence in descending order. The function should handle arrays with varying row sizes and include negative integers.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def count_unique_occurrences(two_d_array: List[List[int]]) -> List[Tuple[int, int]]:
"""
Counts the occurrences of each unique integer in a given two-dimensional array and returns the result... |
magic_evol_110k | 107,651 | Write a Python function to invert the placement of each item within a given list and convert each character within these elements from uppercase to lowercase. The function should take a list of strings as input and return a new list with the transformed elements.
The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def invert_and_lowercase(arr: List[str]) -> List[str]:
"""
Inverts the placement of each item within the given list and converts each character within these elements from uppercase to lowercase.
Arg... |
magic_evol_110k | 107,661 | Write a Python function to perform a linear search on a given list of integers to find the index of a specified target element. If the target element is not found, the function should return -1. The function should handle various edge cases, such as an empty list, a list with duplicate elements, and a list where the ta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], target: int) -> int:
"""
Perform a linear search on a list of integers to find the index of a specified target element.
Args:
arr (List[int]): The list of i... |
magic_evol_110k | 107,666 | Write a Python function to calculate the Least Common Multiple (LCM) of two integers, `a` and `b`, ensuring the function is optimized and error-free. The function should handle the constraints where `1 <= a, b <= 10^6`. The code should start with:
```python
import math
def lcm(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lcm(a: int, b: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of two integers a and b.
Args:
a (int): The first integer, must be in the range [1, 10^6].
b (int): The second integ... |
magic_evol_110k | 107,676 | Write a Python function to merge two sorted arrays into a single sorted array. The function should take two lists of integers as input, each of which is already sorted in ascending order, and return a new list that contains all elements from both input lists, also sorted in ascending order.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two sorted arrays into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
arr2 ... |
magic_evol_110k | 107,686 | Write a Python function to compute the median of a variable set of numerical inputs ranging from five to twenty. The function should handle edge cases such as all identical numbers and numbers in descending order. The function should also validate the input to ensure it falls within the specified range.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_median(numbers: List[int]) -> float:
"""
Compute the median of a list of numbers ranging from 5 to 20.
Args:
numbers (List[int]): The list of numbers to compute the median from.
... |
magic_evol_110k | 107,687 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The LCS is the longest sequence of characters that appear in the same order in both strings, but not necessarily consecutively. The function should return the length of the LCS.
The code should start with:
```python
def lon... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second s... |
magic_evol_110k | 107,708 | Write a Python function to find and print the indices of the maximum and second maximum values in a given list of unique integers. The function should modify the list to ensure that the second maximum value can be correctly identified. The code should start with:
```python
from typing import List
def find_max_indices(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_indices(nums: List[int]) -> None:
"""
Finds and prints the indices of the maximum and second maximum values in a list of unique integers.
Args:
nums (List[int]): A list of uniqu... |
magic_evol_110k | 107,709 | Write a Python function to efficiently generate and print the elements of a list using a generator expression. The function should take a list of integers as input and print each element in the list. The code should start with:
```python
from typing import List
def print_list_elements(my_list: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_list_elements(my_list: List[int]) -> None:
"""
Efficiently prints each element of the given list using a generator expression.
Args:
my_list (List[int]): The list of integers to be... |
magic_evol_110k | 107,724 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an `m x n` grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
magic_evol_110k | 107,733 | Write a Python function to download a CSV file from a given remote URL, save it locally, and then calculate the size of the downloaded file in both bytes and human-readable format (KB, MB). The function should handle possible HTTP errors that may occur during the file download. The code should start with:
```python
imp... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import requests
def download_and_calculate_file_size(url: str, file_name: str) -> None:
"""
Downloads a CSV file from a given URL, saves it locally, and calculates its size in bytes, kilobytes, and megabytes.
Arg... |
magic_evol_110k | 107,734 | Write a Python function that checks if a given number is divisible by a specified divisor and returns a corresponding message. If the number is divisible by the divisor, the function should return "Good Day". Otherwise, it should return "Bad Day". The function should handle both positive and negative integers.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_divisibility(number: int, divisor: int) -> str:
"""
Checks if a given number is divisible by a specified divisor and returns a corresponding message.
Args:
number (int): The number to check for divisibilit... |
magic_evol_110k | 107,745 | Write a Python function to create a shallow copy of a given object using Python's built-in `copy` module. Additionally, explain the difference between a shallow copy and a deep copy, and provide a brief example to illustrate the trade-offs between the two.
The code should start with:
```python
import copy
def create_... | Here is the Python code to solve the given problem in the markdown block:
```python
import copy
def create_shallow_copy(obj):
"""
Creates a shallow copy of the given object.
Args:
obj: The object to be copied.
Returns:
A shallow copy of the object.
"""
return copy.copy(obj)
#... |
magic_evol_110k | 107,747 | Write a Python function to create a dictionary with 15 unique hexadecimal color codes as keys and their corresponding randomly generated decimal figures (ranging from 0.1 to 1.0) as values. The function should ensure that each color code is unique and that the decimal figures are rounded to one decimal place.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import random
def generate_color_code_dict() -> Dict[str, float]:
"""
Generates a dictionary with 15 unique hexadecimal color codes as keys and their corresponding
randomly generated decimal figures ... |
magic_evol_110k | 107,751 | Write a Python function to apply a custom mathematical operation to each element in a given array of integers. The custom operation involves multiplying each element by a coefficient and then adding an offset. The function should return a new array with the transformed elements.
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 custom_transform(array: List[int], coefficient: int, offset: int) -> List[int]:
"""
Applies a custom mathematical operation to each element in the given array.
The operation involves multiplying ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.