source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
33,701
Write a Python function to find the mode (the most frequently occurring element) in a given list of integers. If there are multiple elements with the same highest frequency, return any one of them. The function should handle lists with a single mode and lists with multiple modes. 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, Optional from collections import defaultdict def find_mode(data_set: List[int]) -> Optional[int]: """ Find the mode (the most frequently occurring element) in a given list of integers. Args: ...
evol_instruct_66k
33,706
Write a Python function to find the intersection of two lists, considering multiple occurrences of the same number in both lists. The intersection should include each number as many times as it appears in both lists, based on the minimum occurrence in each list. The function should handle lists of variable lengths and ...
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_intersection(arr1: List[int], arr2: List[int]) -> List[int]: """ Finds the intersection of two lists, considering multiple occurrences of the same number. Ar...
evol_instruct_66k
33,707
Write a Python function to extract specified columns from a given nested list (table). The function should take two inputs: the nested list `data` and a list of column indices `columns`. The function should return a new nested list containing only the columns specified by the indices in `columns`. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_columns(data: List[List[str]], columns: List[int]) -> List[List[str]]: """ Extracts specified columns from a given nested list (table). Args: data (List[List[str]]): The nested l...
evol_instruct_66k
33,721
Write a Python function to sort a list of randomly generated numbers from 1 to 50 and count the occurrences of a specific number in the list. The function should return the sorted list and the count of the specified number. The code should start with: ```python from typing import List, Tuple def sort_and_count(num_li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_and_count(num_list: List[int], num_to_count: int) -> Tuple[List[int], int]: """ Sorts the given list of numbers and counts the occurrences of a specified number. Args: num_li...
evol_instruct_66k
33,726
Write a Python function to evaluate a complex conditional expression based on given variables `x`, `y`, and `z`. The function should return `True` if the complex conditional expression is satisfied, otherwise `False`. The complex conditional expression should be formed by combining the following conditions: 1. `x` is g...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_complex_conditional(x: int, y: int, z: int) -> bool: """ Evaluates a complex conditional expression based on the given variables x, y, and z. The complex conditional expression is formed by combining the follow...
evol_instruct_66k
33,730
Write a Python function to find the minimum absolute value among a list of negative integers. The function should take a list of integers as input and return the smallest absolute value. The code should start with: ```python from typing import List def find_min_absolute_value(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_min_absolute_value(nums: List[int]) -> int: """ Find the minimum absolute value among a list of negative integers. Args: nums (List[int]): A list of negative integers. Returns:...
evol_instruct_66k
33,733
Write a Python function to calculate the sum of the elements in a given array using a recursive approach. The function should handle arrays of integers and return the sum of all elements. The code should start with: ```python from typing import List def recursive_sum(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def recursive_sum(arr: List[int]) -> int: """ Calculate the sum of the elements in a given array using a recursive approach. Args: arr (List[int]): The array of integers to sum. Retur...
evol_instruct_66k
33,741
Write a Python function to sort a dictionary based on the ascending order of its values. The function should take a dictionary as input and return a new dictionary with the same keys but sorted by their corresponding values in ascending order. The code should start with: ```python from typing import Dict def sort_dict...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_value(input_dict: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary by its values in ascending order. Args: input_dict (Dict[str, int]): The dictionary to be sorted....
evol_instruct_66k
33,753
Write a Python function to identify and return a quartet of primitive types that are fundamental to the Python programming language. Each type should be represented by a sample value and a brief description of its characteristics. The function should return a list of dictionaries, where each dictionary contains the typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def identify_primitive_types() -> List[Dict[str, str]]: """ Identify and return a quartet of primitive types that are fundamental to the Python programming language. Returns: List[Dict...
evol_instruct_66k
33,766
Write a Python function to calculate the cumulative product of elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def cumulative_product(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def cumulative_product(arr: List[int]) -> int: """ Calculate the cumulative product of elements in a given list of integers. Args: arr (List[int]): The list of integers for which the cumul...
evol_instruct_66k
33,790
Write a Python function to extract a subset of columns from a given multilayered list (a list of lists) based on specified column indices. The function should return a new list of lists that includes only the columns specified by the indices. The code should start with: ```python from typing import List def subset_co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def subset_columns(data: List[List[str]], columns: List[int]) -> List[List[str]]: """ Extracts a subset of columns from a given multilayered list based on specified column indices. Args: dat...
evol_instruct_66k
33,802
Write a Python function to apply a given mathematical operation to each element of a 2D matrix and return the resulting matrix. The mathematical operation will be provided as a lambda function. The function should handle matrices of any size. The code should start with: ```python from typing import List, Callable def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def apply_operation_to_matrix(matrix: List[List[int]], operation: Callable[[int], int]) -> List[List[int]]: """ Applies a given mathematical operation to each element of a 2D matrix and returns...
evol_instruct_66k
33,804
Write a Python function to calculate the value of `y` given an integer `x` using the formula `y = 3 * x + 2`. The function should return the calculated value of `y`. The code should start with: ```python def calculate_y(x: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_y(x: int) -> int: """ Calculate the value of y using the formula y = 3 * x + 2. Args: x (int): The input integer value. Returns: int: The calculated value of y. """ # Apply the for...
evol_instruct_66k
33,819
Write a Python function to return a list of tuples representing the contents of a dictionary sorted by its keys in ascending order. Ensure that the given dictionary only contains unique keys. The function should start with: ```python from typing import Dict, List, Tuple def sorted_dict_contents(input_dict: Dict[str, s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sorted_dict_contents(input_dict: Dict[str, str]) -> List[Tuple[str, str]]: """ Returns a list of tuples representing the contents of a dictionary sorted by its keys in ascending order. ...
evol_instruct_66k
33,820
Write a Python function to implement the Bubble Sort algorithm. The function should take a list of integers as input and return the sorted list. Additionally, provide a detailed analysis illustrating how the same goal would be accomplished without the use of functions. Provide commentary on readability, code reuse, and...
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: ...
evol_instruct_66k
33,824
Write a Python function to reverse a given string without using any built-in functions or slicing operations. The function should use a loop to manually reverse the string. The code should start with: ```python def reverse_string_manual(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_manual(s: str) -> str: """ Reverses a given string without using built-in functions or slicing. Args: s (str): The input string to be reversed. Returns: str: The reversed string. ...
evol_instruct_66k
33,825
Write a Python function to sort an array of negative integers in descending order. The function should take a list of negative integers as input and return the sorted list. The code should start with: ```python from typing import List def sort_negative_integers_descending(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 sort_negative_integers_descending(arr: List[int]) -> List[int]: """ Sorts an array of negative integers in descending order. Args: arr (List[int]): A list of negative integers. Re...
evol_instruct_66k
33,829
Write a Python function that processes a given input sentence to generate a list of individual words, removes any predefined list of stop words, and calculates the frequency of the remaining words. The function should be case-insensitive, meaning "Word" and "word" should be considered the same. Additionally, the functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict from collections import Counter def word_frequency(sentence: str, stop_words: List[str]) -> Dict[str, int]: """ Processes a given sentence to generate a list of individual words, removes any predef...
evol_instruct_66k
33,841
Write a Python function to convert a dictionary containing personal information (full name, age, and profession) into a JSON string. The function should ensure that the JSON string is properly formatted and adheres to the correct syntax. The code should start with: ```python import json def dict_to_json(personal_info:...
Here is the Python code to solve the given problem in the markdown block: ```python import json def dict_to_json(personal_info: dict) -> str: """ Converts a dictionary containing personal information into a properly formatted JSON string. Args: personal_info (dict): A dictionary containing persona...
evol_instruct_66k
33,843
Write a Python function to access and modify the last element of a dynamically changing list. The function should take a list and a new value as input, update the last element of the list with the new value, and return the updated list. The code should start with: ```python from typing import List def update_last_elem...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def update_last_element(arr: List[int], new_value: int) -> List[int]: """ Updates the last element of a given list with a new value and returns the updated list. Args: arr (List[int]): The...
evol_instruct_66k
33,848
Write a Python function to find the maximum number in a list of integers. The function should be efficient and handle edge cases such as an empty list or a list with a single element. The code should start with: ```python from typing import List def find_max_number(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_number(numbers: List[int]) -> int: """ Find the maximum number in a list of integers. Args: numbers (List[int]): A list of integers from which to find the maximum number. R...
evol_instruct_66k
33,867
Write a Python function to transform a given list of string type entities into an equivalent list of elements of the integral numeric type. The function should handle lists of varying lengths and ensure that each string element is converted to its corresponding integer value. 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 convert_string_list_to_int_list(string_list: List[str]) -> List[int]: """ Converts a list of string type entities into a list of integral numeric type. Args: string_list (List[str]): A l...
evol_instruct_66k
33,873
Write a Python function to reverse a given string and print each character along with its index in the reversed string. The function should start with: ```python def reverse_and_enumerate(input_string: str) -> None: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_and_enumerate(input_string: str) -> None: """ Reverses the input string and prints each character along with its index in the reversed string. Args: input_string (str): The string to be reversed and en...
evol_instruct_66k
33,893
Write a Python function to calculate the absolute difference between two given numbers. The function should take two parameters, `x` and `y`, and return the absolute difference between them. The code should start with: ```python def absolute_difference(x: int, y: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def absolute_difference(x: int, y: int) -> int: """ Calculate the absolute difference between two given numbers. Args: x (int): The first number. y (int): The second number. Returns: int: The ab...
evol_instruct_66k
33,896
Write a Python function to convert time from 24-hour format to 12-hour format with AM/PM indicators. The input will be a string in the format "HH:MM" where HH is the hour (00 to 23) and MM is the minute (00 to 59). The output should be a string in the format "HH:MM AM/PM". The code should start with: ```python def con...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_24_hour_to_12_hour(time_str: str) -> str: """ Converts a time string from 24-hour format to 12-hour format with AM/PM indicators. Args: time_str (str): A string representing the time in 24-hour format "H...
evol_instruct_66k
33,901
Write a Python function to transform a list of strings, where each string represents a person's name and age in the format 'name,age', into a list of dictionaries. Each dictionary should have keys 'name' and 'age' corresponding to the respective values from the input strings. The function should handle any number of in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def transform_data(arr: List[str]) -> List[Dict[str, str]]: """ Transforms a list of strings, where each string represents a person's name and age in the format 'name,age', into a list of dictionar...
evol_instruct_66k
33,907
Write a Python function to find the unique shared elements between two lists and return them in ascending order. The function should ensure that both lists contain only identical data types (either integers or strings) and handle cases where the lists are empty. The function should not use Python's built-in list functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def shared_elements(list1: List[Union[int, str]], list2: List[Union[int, str]]) -> List[Union[int, str]]: """ Find the unique shared elements between two lists and return them in ascending order. ...
evol_instruct_66k
33,913
Write a Python function to generate a random integer within a specified range defined by a pair of distinct numeric boundaries. The function should handle cases where the boundaries are provided in reverse order (i.e., the lower bound is greater than the upper bound) by swapping them. The function should also ensure th...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_int(a: int, b: int) -> int: """ Generates a random integer within the specified range [a, b]. Args: a (int): The lower bound of the range. b (int): The upper bound of the r...
evol_instruct_66k
33,939
Write a Python function to generate a cipher text where each distinctive character in a given input phrase is substituted by a uniquely different alphabetical letter. The function should handle both uppercase and lowercase letters, and non-alphabetical characters should remain unchanged. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import random import string def generate_cipher_text(input_string: str) -> str: """ Generates a cipher text where each distinctive character in the input string is substituted by a uniquely different...
evol_instruct_66k
33,967
Write a Python function to determine the number of related articles for each entry in an encyclopedia. The encyclopedia is represented as a dictionary where each key is an entry and the corresponding value is a list of related articles. The function should return a dictionary where each key is an entry and the correspo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def count_related_articles(encyclopedia: Dict[str, List[str]]) -> Dict[str, int]: """ Counts the number of related articles for each entry in the encyclopedia. Args: encyclopedia (Dict...
evol_instruct_66k
33,979
Write a Python function to process a given string by removing all punctuation, converting the words to lowercase, and returning a list of unique words that appear exactly once in the string. The function should start with: ```python from typing import List def unique_words_from_string(s: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import re from collections import Counter def unique_words_from_string(s: str) -> List[str]: """ Processes a given string to remove punctuation, convert words to lowercase, and return a list of uni...
evol_instruct_66k
33,986
Write a Python function to randomly select an integer from a given two-dimensional array of numerical elements ranging from one to five. The function should also return the index positions (row and column) of the chosen integer in the array. The code should start with: ```python from typing import Tuple, List import ra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, List import random def choose_random_element(array: List[List[int]]) -> Tuple[int, Tuple[int, int]]: """ Randomly selects an integer from a given two-dimensional array and returns the integer along wit...
evol_instruct_66k
34,011
Write a Python function to concatenate two strings and return the reversed result. The function should handle empty strings and ensure that the concatenated string is reversed correctly. The code should start with: ```python def reverse_concatenate(string1: str, string2: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_concatenate(string1: str, string2: str) -> str: """ Concatenates two strings and returns the reversed result. Args: string1 (str): The first string to concatenate. string2 (str): The second strin...
evol_instruct_66k
34,012
Write a Python function to calculate the sum of two n-dimensional matrices, `A` and `B`, where each matrix can have up to \(10^3 \times 10^3\) integer elements. Both matrices are filled with integer values ranging from 1 to 100. The function should return the resulting matrix after the summation. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_sum(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: """ Calculate the sum of two n-dimensional matrices A and B. Args: A (List[List[int]]): The first matrix. B...
evol_instruct_66k
34,016
Write a Python function to calculate the area of a circle given its radius. The function should handle both positive and zero radius values. For negative radius values, the function should return `None`. The code should start with: ```python from math import pi def calculate_circle_area(radius: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from math import pi def calculate_circle_area(radius: float) -> float: """ Calculate the area of a circle given its radius. Args: radius (float): The radius of the circle. Returns: float: The area of t...
evol_instruct_66k
34,023
Write a Python function to encrypt a given text using a rotation cipher (also known as Caesar cipher). The function should shift each alphabetic character in the text by a specified number of positions in the alphabet. Non-alphabetic characters should remain unchanged. The code should start with: ```python def encrypt_...
Here is the Python code to solve the given problem in the markdown block: ```python def encrypt_text(text: str, shift: int) -> str: """ Encrypts the given text using a rotation cipher (Caesar cipher). Args: text (str): The text to be encrypted. shift (int): The number of positions to shift ...
evol_instruct_66k
34,033
Write a Python function to construct a comprehensive HTTPS internet network location, including a precise subdomain and a domain, up to and including a detailed web path. The function should take four parameters: the protocol (e.g., "https://"), the subdomain (e.g., "mypage."), the domain (e.g., "google.com/"), and the...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_url(protocol: str, subdomain: str, domain: str, path: str) -> str: """ Constructs a comprehensive HTTPS internet network location. Args: protocol (str): The protocol to use, e.g., "https://". s...
evol_instruct_66k
34,035
Write a Python function to generate a 5x5 NumPy array filled with random floating-point values within a specified range, rounded to a maximum of 2 decimal places. The function should accept two parameters: the lower boundary and the upper boundary of the range. The array should maintain uniform randomness across all el...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_random_array(lower_bound: float, upper_bound: float) -> np.ndarray: """ Generate a 5x5 NumPy array filled with random floating-point values within a specified range, rounded to a maximum of 2...
evol_instruct_66k
34,037
Write a Python function to determine if a given numerical sequence is symmetrical, meaning it reads the same forwards and backwards. The function should accept an integer as input and return a boolean indicating whether the number is symmetrical. The code should start with: ```python def is_symmetrical_number(num: int...
Here is the Python code to solve the given problem in the markdown block: ```python def is_symmetrical_number(num: int) -> bool: """ Determines if a given numerical sequence is symmetrical. Args: num (int): The numerical sequence to be checked for symmetry. Returns: bool: True if the n...
evol_instruct_66k
34,039
Write a Python function to determine if all the strings in a given array are unique. The function should return `True` if all strings are unique and `False` otherwise. The code should start with: ```python from typing import List def are_all_strings_unique(strings: List[str]) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def are_all_strings_unique(strings: List[str]) -> bool: """ Determines if all strings in the given list are unique. Args: strings (List[str]): A list of strings to check for uniqueness. ...
evol_instruct_66k
34,058
Write a Python function to calculate the area of a rhombus given its two diagonals, and another function to calculate the ratio of the colored area to the total area if one quarter of the rhombus is colored. The code should start with: ```python def calculate_area(diagonal1: float, diagonal2: float) -> float: def color...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_area(diagonal1: float, diagonal2: float) -> float: """ Calculate the area of a rhombus given its two diagonals. Args: diagonal1 (float): The length of the first diagonal. diagonal2 (float): The...
evol_instruct_66k
34,072
Write a Python function to determine the unique elements in the intersection of three given sets. The function should take three sets as input and return a set containing the elements that are present in all three sets. The code should start with: ```python from typing import Set def find_intersection_of_three_sets(s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def find_intersection_of_three_sets(setA: Set[int], setB: Set[int], setC: Set[int]) -> Set[int]: """ Determine the unique elements in the intersection of three sets. Args: setA (Set[int]): Th...
evol_instruct_66k
34,076
Write a Python function to iterate over a given list and return a new list containing the elements of the original list in reverse order. The function should handle lists of any length and type of elements. The code should start with: ```python from typing import List, Any def reverse_list(input_list: List[Any]) -> Li...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Any def reverse_list(input_list: List[Any]) -> List[Any]: """ Returns a new list containing the elements of the input list in reverse order. Args: input_list (List[Any]): The list to be r...
evol_instruct_66k
34,101
Write a Python function to perform a binary search on a sorted array of integers to determine if a specified integer is included in the array. If the integer exists in the array, return the index of its first occurrence. If the integer does not exist, return -1. 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 def binary_search_first_occurrence(arr: List[int], num: int) -> int: """ Perform a binary search on a sorted array to find the first occurrence of a specified integer. Args: arr (List[int]):...
evol_instruct_66k
34,102
Write a Python function to merge two dictionaries such that if there are overlapping keys between the two dictionaries, the values corresponding to the shared keys are summed. The input dictionaries will have at most 100 unique keys, all keys are single lower case letters, and the values are integers in the range [1, 1...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Merge two dictionaries such that if there are overlapping keys, the values corresponding to the shared keys are summed...
evol_instruct_66k
34,111
Write a Python function to square only the numeric elements in a given list, ignoring any non-numeric data types. The function should handle lists containing integers, floats, and other data types. The code should start with: ```python from typing import List, Union def square_numeric_elements(lst: List[Union[int, flo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def square_numeric_elements(lst: List[Union[int, float, str]]) -> List[Union[int, float]]: """ Squares only the numeric elements in the given list, ignoring any non-numeric data types. Args: ...
evol_instruct_66k
34,114
Write a Python function to combine two dictionaries into a single dictionary. If there are duplicate keys, merge their values by applying a mathematical function, such as addition. The function should handle any number of dictionaries and return the combined dictionary. The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def combine_dictionaries(dicts: List[Dict[str, int]]) -> Dict[str, int]: """ Combines a list of dictionaries into a single dictionary. If there are duplicate keys, their values are merged by ad...
evol_instruct_66k
34,119
Write a Python function to transpose a given MxN matrix without using any built-in matrix transposition methods or libraries. The function should handle both square and non-square matrices. For square matrices, the transposition should be done in-place to minimize memory usage. For non-square matrices, a new matrix sho...
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 a given MxN matrix. For square matrices, the transposition is done in-place. For non-square matrices, a new matrix is ...
evol_instruct_66k
34,126
Write a Python function to convert a given integer into its Roman numeral representation. The function should handle integers in the range from 1 to 3999, which is the range for which Roman numerals are typically defined. The code should start with: ```python def int_to_roman(num: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_roman(num: int) -> str: """ Convert an integer into its Roman numeral representation. Args: num (int): The integer to be converted, must be in the range 1 to 3999. Returns: str: The Roman num...
evol_instruct_66k
34,135
Write a Python function to encrypt a given string using a custom Caesar cipher with a provided key. The encryption should consider case sensitivity and non-alphabetic characters, which should remain unchanged. The code should start with: ```python def custom_caesar_cipher(text: str, key: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def custom_caesar_cipher(text: str, key: int) -> str: """ Encrypts a given string using a custom Caesar cipher with a provided key. The encryption maintains case sensitivity and leaves non-alphabetic characters unchanged. ...
evol_instruct_66k
34,137
Write a Python function to create a dictionary where the keys are composite tuples formed by pairing each element of a list of tuples with every other element, and the values are the products of the elements in the paired tuples. The function should start with: ```python from typing import List, Tuple, Dict def create...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def create_composite_product_dict(tuples_list: List[Tuple[int, int]]) -> Dict[Tuple[int, int], int]: """ Creates a dictionary where the keys are composite tuples formed by pairing each eleme...
evol_instruct_66k
34,155
Write a Python function that demonstrates the use of nested `try-except-else-finally` blocks to handle different types of errors. The function should take two arguments, `x` and `y`, and perform a division operation. The function should handle `ZeroDivisionError` and `TypeError` appropriately, and demonstrate the prope...
Here is the Python code to solve the given problem in the markdown block: ```python def nested_error_handling(x, y): """ Demonstrates the use of nested try-except-else-finally blocks to handle different types of errors. Args: x (int or float): The numerator. y (int or float): The denominato...
evol_instruct_66k
34,157
Write a Python function to merge two sorted lists into a single sorted list. The function should efficiently merge the two lists in O(n + m) time complexity, where n and m are the lengths of the two lists. The function should handle lists of different lengths and should not use any built-in sorting functions. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two sorted lists into a single sorted list. Args: list1 (List[int]): The first sorted list. list2 ...
evol_instruct_66k
34,165
Write a Python function to replace all occurrences of a specified character in a given string with another specified character. The function should take three parameters: the input string, the character to be replaced, and the character to replace with. The function should return the modified string. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_character(input_string: str, old_char: str, new_char: str) -> str: """ Replaces all occurrences of a specified character in the input string with another specified character. Args: input_string (str): Th...
evol_instruct_66k
34,167
Write a Python function to compute the factorial of a given integer. The function should handle and provide a friendly error message for negative input numbers and non-integer values. The code should start with: ```python def factorial(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Compute the factorial of a given non-negative integer. Args: n (int): The non-negative integer for which to compute the factorial. Returns: int: The factorial of the gi...
evol_instruct_66k
34,170
Write a Python function to sort a list of dictionaries by a specified key. The function should take two arguments: a list of dictionaries and a string representing the key by which to sort the dictionaries. The function should return the sorted list of dictionaries. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_list_of_dicts(data: List[Dict[str, any]], key: str) -> List[Dict[str, any]]: """ Sorts a list of dictionaries by a specified key. Args: data (List[Dict[str, any]]): A list of ...
evol_instruct_66k
34,174
Write a Python function to manipulate a given string by replacing all exclamation marks (`!`) with periods (`.`). The function should handle potential exceptions and ensure that the modified string is printed correctly. The code should start with: ```python def replace_exclamation_with_period(input_str: str) -> str: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_exclamation_with_period(input_str: str) -> str: """ Replaces all exclamation marks in the input string with periods. Args: input_str (str): The input string to be modified. Returns: str: The...
evol_instruct_66k
34,177
Write a Python function that takes a list of tuples as input and returns a list of results obtained by applying a lambda function to each tuple. Each tuple contains two items, and the lambda function should subtract the second item from the first item. The function should use list comprehension to achieve this. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def process_tuples(lst: List[Tuple[int, int]]) -> List[int]: """ Processes a list of tuples by applying a lambda function to each tuple. The lambda function subtracts the second item from the ...
evol_instruct_66k
34,194
Write a Python function to sort a binary matrix represented as a list of integers in ascending order. The function should efficiently count the number of 0s and 1s and then construct the sorted list. The code should start with: ```python from typing import List def sort_binary_matrix(B: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sort_binary_matrix(B: List[int]) -> List[int]: """ Sorts a binary matrix (a list of integers containing only 0s and 1s) in ascending order. Args: B (List[int]): The binary matrix to be...
evol_instruct_66k
34,196
Write a Python function to validate if each number in a given list falls within the corresponding range defined by a pair of lower and upper bounds. The function should return a list of boolean values indicating whether each number is within its respective range. 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 validate_ranges(numbers: List[int], lower_bounds: List[int], upper_bounds: List[int]) -> List[bool]: """ Validate if each number in the `numbers` list falls within the corresponding range defined by ...
evol_instruct_66k
34,198
Write a Python function to generate an array where each element is the maximum value of the corresponding row in a given input matrix. The input matrix is a 2D list of integers. The function should start with: ```python from typing import List def max_values_in_rows(matrix: 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 max_values_in_rows(matrix: List[List[int]]) -> List[int]: """ Generates an array where each element is the maximum value of the corresponding row in the input matrix. Args: matrix (List[...
evol_instruct_66k
34,200
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 code 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...
evol_instruct_66k
34,205
Write a Python function to compute an array where each element is the sum of all other elements in the input array, excluding the element at the current index. The function should start with: ```python from typing import List def sum_of_others(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 sum_of_others(arr: List[int]) -> List[int]: """ Computes an array where each element is the sum of all other elements in the input array, excluding the element at the current index. Args: ...
evol_instruct_66k
34,209
Write a Python function to iterate over a given list and print each element. The function should handle the following cases: 1. If the list is empty, print "The array is empty". 2. If an index error occurs during iteration, print "Index error occurred". The code should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def iterate_and_print(array: List[int]) -> None: """ Iterates over the given list and prints each element. Handles empty list and index errors. Args: array (List[int]): The list of integers ...
evol_instruct_66k
34,213
Write a Python function to generate a two-dimensional matrix of dimensions `n` by `m` based on the following rules: 1. All border elements should be `0`. 2. All non-border elements should be `1`. 3. If either `n` or `m` equals `1`, the matrix should be filled with `0`s. The function should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_matrix(n: int, m: int) -> List[List[int]]: """ Generates a two-dimensional matrix of dimensions n by m based on the following rules: 1. All border elements are 0. 2. All non-border e...
evol_instruct_66k
34,216
Write a Python function that implements a decorator to cache the results of a function call. The decorator should store the results of previous function calls in a dictionary, and if the function is called again with the same arguments, it should return the cached result instead of recomputing it. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Callable, Any def memoize(func: Callable) -> Callable: """ A decorator that caches the results of function calls. Args: func (Callable): The function to be decorated. Returns: Callab...
evol_instruct_66k
34,231
Write a Python function to sort a given list of numerical elements in descending order. The function should return the sorted list. The code should start with: ```python from typing import List def sort_descending(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 sort_descending(numbers: List[int]) -> List[int]: """ Sorts a given list of numerical elements in descending order. Args: numbers (List[int]): The list of numerical elements to be sort...
evol_instruct_66k
34,242
Write a Python function to transform a given textual string into an array form by dissecting it into individual words. The function should handle various edge cases, such as strings with leading or trailing spaces, multiple spaces between words, and empty strings. 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 text_to_array(text: str) -> List[str]: """ Transforms a given textual string into an array form by dissecting it into individual words. Args: text (str): The input textual string to be t...
evol_instruct_66k
34,245
Write a Python function to convert an IP address from dot-decimal notation to binary notation. The function should validate the input to ensure it is a valid IP address and return an error message if the input is invalid. The function should handle edge cases such as invalid IP addresses (e.g., values greater than 255,...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_ip_to_binary(ip_address: str) -> str: """ Converts an IP address from dot-decimal notation to binary notation. Args: ip_address (str): The IP address in dot-decimal notation. Returns: str: T...
evol_instruct_66k
34,247
Write a Python function to stop a loop after a specified number of iterations. The function should take an integer `n` as input, which represents the number of iterations after which the loop should stop. The function should print the iteration number for each iteration and stop after `n` iterations. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def stop_loop_after_n_iterations(n: int) -> None: """ Stops a loop after a specified number of iterations and prints the iteration number for each iteration. Args: n (int): The number of iterations after which the l...
evol_instruct_66k
34,258
Write a Python function that generates and prints numerical values from 1 to 11, checking if each number is odd or even. For every odd number, it should print "[number] is odd", and for every even number, it should print "[number] is even". The function should handle any potential errors using exception handling. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def print_odd_even_numbers(): """ Generates and prints numerical values from 1 to 11, checking if each number is odd or even. Prints "[number] is odd" for odd numbers and "[number] is even" for even numbers. Handles any ...
evol_instruct_66k
34,267
Write a Python function to compute the absolute difference between two given 3D vectors. Each vector is represented as a list of three integers representing the x, y, and z coordinates in a 3D space. The function should return a new list containing the absolute differences for each corresponding pair of coordinates. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_absolute_difference(vector1: List[int], vector2: List[int]) -> List[int]: """ Compute the absolute difference between two 3D vectors. Args: vector1 (List[int]): The first 3D vect...
evol_instruct_66k
34,269
Write a Python function to generate a string output based on an array of food items. The function should iterate through the array and append specific messages to the output string based on the type of food item. The food items can be "hamburger", "hot dog", "cheese", or any other item. If the item is "hamburger", appe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_food_string(food_items: List[str]) -> str: """ Generates a string output based on an array of food items. Args: food_items (List[str]): A list of food items. Returns: ...
evol_instruct_66k
34,273
Write a Python function to calculate the square of a number and return the result. The function should handle both positive and negative integers, as well as zero. The code should start with: ```python def square_number(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def square_number(number: int) -> int: """ Calculate the square of a given integer. Args: number (int): The integer to be squared. Returns: int: The square of the input number. """ # Calculate t...
evol_instruct_66k
34,275
Write a Python function to sort a given list of numerical values in ascending order. The function should return the sorted list. The code should start with: ```python from typing import List def sort_numbers(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 sort_numbers(numbers: List[int]) -> List[int]: """ Sorts a given list of numerical values in ascending order. Args: numbers (List[int]): The list of numerical values to be sorted. ...
evol_instruct_66k
34,278
Write a Python function to process a given corpus of text by removing all characters that are not alphanumeric. The function should return the processed text as a string. The code should start with: ```python import re def remove_non_alphanumeric(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import re def remove_non_alphanumeric(text: str) -> str: """ Removes all non-alphanumeric characters from the given text. Args: text (str): The input text from which non-alphanumeric characters will be removed. ...
evol_instruct_66k
34,289
Write a Python function to calculate the sum of an arbitrary set of numerical inputs, incorporating a multi-step process for solving the task. The function should handle mixed data types in the input list and only sum the numerical values, ignoring non-numeric entries. 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 def sum_calculation(numeric_vector: List) -> float: """ Calculate the sum of an arbitrary set of numerical inputs, ignoring non-numeric entries. Args: numeric_vector (List): A list containin...
evol_instruct_66k
34,295
Write a Python function to find the top three highest selling products in each category for every month of the year, along with the percent change in sales compared to the same month in the previous year. The function should take a list of dictionaries as input, where each dictionary represents a sale record with keys ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict from datetime import datetime from collections import defaultdict def top_selling_products(sales_data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Find the top three highest selling products...
evol_instruct_66k
34,297
Write a Python function to count the occurrences of each unique character in a given string and return the result as a list of tuples, where each tuple contains a character and its count. The list should be sorted in ascending order based on the characters. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def count_unique_characters(s: str) -> List[Tuple[str, int]]: """ Counts the occurrences of each unique character in the given string and returns the result as a sorted list of tuples. Args: ...
evol_instruct_66k
34,303
Write a Python function to generate the nth term of the Fibonacci series using an iterative approach for computational efficiency. The function should handle edge cases such as n being 0 or 1 directly, and efficiently compute the nth term for larger values of n. The code should start with: ```python def fibonacci_iter...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_iterative(n: int) -> int: """ Generate the nth term of the Fibonacci series using an iterative approach. Args: n (int): The position in the Fibonacci series to generate. Returns: int: The ...
evol_instruct_66k
34,309
Write a Python function to construct an alternative array derived from the provided input array, which retains only the elements with values less than a specified threshold. The function should handle both positive and negative integers in the input array. The code should start with: ```python from typing import List ...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def filter_elements_below_threshold(input_array: List[int], threshold: int) -> List[int]: """ Constructs an alternative array derived from the provided input array, which retains only the elements with...
evol_instruct_66k
34,323
Write a Python function to filter and print elements from a given list that are greater than a specified threshold using list comprehension. The function should take a list of integers and an integer threshold as input and print each element that meets the condition. 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 filter_and_print_elements(elements: List[int], threshold: int) -> None: """ Filters and prints elements from the given list that are greater than the specified threshold. Args: elements ...
evol_instruct_66k
34,337
Write a Python function to sort an input array of integers in ascending order while maintaining a count of the number of times each number appeared in the initial unsorted list. The function should return both the sorted list and a dictionary containing the counts of each number. 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, Dict def sort_and_count_occurrences(nums: List[int]) -> (List[int], Dict[int, int]): """ Sorts an input array of integers in ascending order and counts the occurrences of each number. Args: ...
evol_instruct_66k
34,338
Debug and correct the given Python code to ensure it functions as intended. The code consists of two functions, `f1` and `f2`. The function `f1` takes an integer `x` and returns `x + 1`. The function `f2` takes an integer `x` and returns the square of the result of `f1(x)`. The task is to fix any issues in the code and...
Here is the Python code to solve the given problem in the markdown block: ```python def f1(x: int) -> int: """ Returns the value of x incremented by 1. Args: x (int): The input integer. Returns: int: The value of x incremented by 1. """ y = x + 1 return y def f2(x: int) ->...
evol_instruct_66k
34,343
Write a Python function to generate the Fibonacci sequence up to the nth term, ensuring it correctly handles edge cases and generates the sequence accurately. Then, use this function to identify and fill in the missing value in a given JSON array representation of a Fibonacci sequence. 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 def generate_fibonacci(n: int) -> List[int]: """ Generate the Fibonacci sequence up to the nth term. Args: n (int): The number of terms in the Fibonacci sequence to generate. Returns: ...
evol_instruct_66k
34,355
Write a Python function to convert a given time in Central European Time (CET) to UTC+5. The function should handle any given time and return the corresponding time in UTC+5. The function should also handle the conversion for the same day when the time in CET is 12pm. The code should start with: ```python def convert_...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_CET_to_UTC_plus_5(hours_CET: int) -> int: """ Convert a given time in Central European Time (CET) to UTC+5. Args: hours_CET (int): The time in Central European Time (CET) to be converted. Returns: ...
evol_instruct_66k
34,358
Write a Python function to find the maximum value in a given list of integers. The function should handle lists of any size, including empty lists. If the list is empty, the function should return `None`. The code should start with: ```python from typing import List, Optional def find_max_value(numbers: List[int]) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_max_value(numbers: List[int]) -> Optional[int]: """ Find the maximum value in a given list of integers. Args: numbers (List[int]): The list of integers to search for the m...
evol_instruct_66k
34,369
Write a Python function to generate a 3D array using NumPy that contains the numbers from 1 to `n^3`, where `n` is a positive integer, and then reshape it into an `n x n x n` matrix. The function should return the reshaped matrix. The code should start with: ```python import numpy as np def generate_3d_matrix(n: int)...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_3d_matrix(n: int) -> np.ndarray: """ Generate a 3D array using NumPy that contains the numbers from 1 to n^3, and then reshape it into an n x n x n matrix. Args: n (int): The dim...
evol_instruct_66k
34,384
Write a Python function to generate a random sequence of `n` distinct alphanumeric characters. The function should ensure that the characters are unique and should return the sequence as a string. The code should start with: ```python from typing import List import random import string def generate_random_sequence(n: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random import string def generate_random_sequence(n: int) -> str: """ Generates a random sequence of `n` distinct alphanumeric characters. Args: n (int): The number of distinct alphan...
evol_instruct_66k
34,387
Write a Python function to compute the sum of two numbers. The function should be named `sum_of_two_numbers` and should take two parameters, `num1` and `num2`, both of which are integers. The function should return the sum of these two numbers. The code should start with: ```python def sum_of_two_numbers(num1: int, nu...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_two_numbers(num1: int, num2: int) -> int: """ Computes the sum of two given integers. Args: num1 (int): The first integer to be summed. num2 (int): The second integer to be summed. Returns: ...
evol_instruct_66k
34,392
Write a Python function to generate and print the Fibonacci sequence up to a specified number of terms, excluding numbers divisible by 3. Additionally, append an "E" for even numbers and an "O" for odd numbers next to the respective Fibonacci number. The code should start with: ```python def print_fibonacci_sequence(n...
Here is the Python code to solve the given problem in the markdown block: ```python def print_fibonacci_sequence(n: int): """ Generates and prints the Fibonacci sequence up to n terms, excluding numbers divisible by 3. Appends "E" for even numbers and "O" for odd numbers next to the respective Fibonacci num...
evol_instruct_66k
34,401
Write a Python function to classify a list of entities based on their types and sub-attributes. Each entity is represented as a dictionary with keys `name`, `type`, and `subAttributes`. The `subAttributes` is itself a dictionary containing various attributes, one of which is `color`. The function should return a nested...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def classify_entities(entities: List[Dict[str, Any]]) -> Dict[str, Dict[str, List[Dict[str, Any]]]]: """ Classify a list of entities based on their types and sub-attributes. Args: ...
evol_instruct_66k
34,409
Write a Python function to extend a list with another list and return the modified list itself. The function should handle the case where the list to be extended is `None` by returning an empty list. The code should start with: ```python from typing import List, Optional def extend_and_return(lst: Optional[List], exte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def extend_and_return(lst: Optional[List], extension: List) -> List: """ Extends the given list with another list and returns the modified list itself. If the list to be extended is None, r...
evol_instruct_66k
34,435
Write a Python function to sum the digits of a given number, handling negative numbers and floating point numbers by rounding down to the nearest integer before summing the digits. The function should return the sum of the digits as an integer. The code should start with: ```python def sum_digits(n: float) -> int: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_digits(n: float) -> int: """ Sum the digits of a given number, handling negative numbers and floating point numbers by rounding down to the nearest integer before summing the digits. Args: n (float): The num...
evol_instruct_66k
34,444
Write a Python function to find the maximum value in a given list of numerical data. The function should efficiently handle the task using Python's built-in functions. The code should start with: ```python from typing import List def find_max_value(data: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(data: List[int]) -> int: """ Find the maximum value in a given list of numerical data. Args: data (List[int]): The list of integers from which to find the maximum value. ...
evol_instruct_66k
34,448
Write a Python function to validate URLs that match the pattern "www.somedomain.com/posts/[post_id]", considering alphanumeric post_ids, optional query strings, and a length constraint of 5 to 10 characters for the domain name. The function should return `True` if the URL matches the pattern, and `False` otherwise. Th...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_url(url: str) -> bool: """ Validates if the given URL matches the pattern "www.somedomain.com/posts/[post_id]" with optional query strings and a length constraint of 5 to 10 characters for the domain ...
evol_instruct_66k
34,487
Write a Python function to search a large collection of documents for relevant results based on a given search query. The function should return a list of documents that contain the search query as a substring. The documents are represented as a list of strings. 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 def search_documents(documents: List[str], search_query: str) -> List[str]: """ Searches a large collection of documents for relevant results based on a given search query. Args: documents (...
evol_instruct_66k
34,490
Write a Python function to generate the first `n` Fibonacci numbers. The function should return a list of the first `n` Fibonacci numbers. The code should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
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 first n Fibonacci numbers. Args: n (int): The number of Fibonacci numbers to generate. Returns: List[int]: A list...
evol_instruct_66k
34,496
Write a Python function to extract the first n lexical items (words) from a given text string. The function should handle cases where n is greater than the number of words in the text, and it should return an empty list if n is less than or equal to 0. The function should also handle text strings that may contain multi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_first_n_words(text: str, n: int) -> List[str]: """ Extracts the first n words from a given text string. Args: text (str): The text string from which to extract the words. n (...
evol_instruct_66k
34,501
Write a Python function to sort a given list of integers using the bubble sort algorithm. The function should return the sorted list. The code should start with: ```python from typing import List def bubble_sort(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 bubble_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the bubble sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: Li...