source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
69,779
Write a Python function to implement the Caesar Cipher encryption technique. The function should take a string and an integer shift value as inputs and return the encrypted string. The Caesar Cipher shifts each letter in the input string by the specified number of positions in the alphabet. Non-alphabetic characters sh...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(text: str, shift: int) -> str: """ Encrypts the given text using the Caesar Cipher technique with the specified shift value. Args: text (str): The input text to be encrypted. shift (int): T...
magic_evol_110k
69,780
Write a Python function to insert an additional element at the initial position of a given tuple. Since tuples in Python are immutable, the function should convert the tuple to a list, insert the element at the desired position, and then convert it back to a tuple. The function should handle tuples of any length and an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Any def insert_at_start(original_tuple: Tuple[Any, ...], additional_element: Any) -> Tuple[Any, ...]: """ Inserts an additional element at the initial position of a given tuple. Args: orig...
magic_evol_110k
69,795
Write a Python function to convert a list of integer numbers into a single string where each number is separated by a hyphen, except there is no leading or trailing hyphen for the first and last number respectively. The integers in the list can contain any number of digits. The function should handle both single and mu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def hyphenate_numbers(numbers: List[int]) -> str: """ Converts a list of integer numbers into a single string where each number is separated by a hyphen. Args: numbers (List[int]): A list of...
magic_evol_110k
69,805
Write a Python function to determine if a given number is divisible by 4 but not by 8 using bitwise operations. The function should return `True` if the number meets the criteria and `False` otherwise. The code should start with: ```python def is_divisible_by_4_not_8(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_4_not_8(n: int) -> bool: """ Determines if a given number is divisible by 4 but not by 8 using bitwise operations. Args: n (int): The number to be checked. Returns: bool: True if the...
magic_evol_110k
69,820
Write a Python function to compute the sum of elements in a given vector (list of integers) using a recursive approach. The function should start with: ```python from typing import List def recursive_sum(vector: 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(vector: List[int]) -> int: """ Compute the sum of elements in a given vector using a recursive approach. Args: vector (List[int]): The vector (list of integers) to compute ...
magic_evol_110k
69,848
Write a Python function to update a JSON configuration file with specific key-value pairs while preserving the data types of the values. The function should read the existing JSON configuration from a file, update the specified keys with new values, and then write the updated configuration back to the file. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python import json from typing import Any, Dict def update_nested_key(config: Dict[str, Any], keys: list, value: Any) -> None: """ Recursively update a nested key in a dictionary. Args: config (dict): The dictionary to up...
magic_evol_110k
69,850
Write a Python function to find and return the name and population of the country with the highest population from a given list of countries, where each country is represented as a dictionary with keys 'name' and 'population'. The function should start with: ```python from typing import List, Dict, Tuple def find_most...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def find_most_populous_country(countries: List[Dict[str, int]]) -> Tuple[str, int]: """ Finds and returns the name and population of the country with the highest population from a given list...
magic_evol_110k
69,853
Write a Python function to convert a list of data into a dictionary where each key is the first element of the corresponding item in the list, and the value is a list containing the remaining elements of that item. The function should use list comprehensions to create the dictionary and maintain time and space efficien...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def convert_list_to_dict(list_of_data: List[List[Any]]) -> Dict[Any, List[Any]]: """ Converts a list of data into a dictionary where each key is the first element of the corresponding item in ...
magic_evol_110k
69,859
Write a Python function to split a given string into words while maintaining punctuation within words (e.g., "I'm", "don't") as single entities and treating multiple continuous white spaces as a single separator. The function should return a list of words. 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 import re def split_text(text: str) -> List[str]: """ Splits a given string into words while maintaining punctuation within words (e.g., "I'm", "don't") as single entities and treating multiple conti...
magic_evol_110k
69,865
Write a Python function that prints a specified number a specified number of times. The function should take two parameters: `number` (an integer) and `times` (an integer). The function should print the `number` exactly `times` times. The function should be implemented using both a `for` loop and a `while` loop. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def print_number_times(number: int, times: int) -> None: """ Prints the specified number a specified number of times. Args: number (int): The integer to be printed. times (int): The number of times to print ...
magic_evol_110k
69,874
Write a Python function to simulate the transformation and aggregation of user activity events from a music streaming application. The function should take a list of user activity events, each represented as a dictionary, and return a dictionary that aggregates the total listening time for each user. The input events a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def aggregate_listening_time(events: List[Dict[str, any]]) -> Dict[str, int]: """ Aggregates the total listening time for each user from a list of user activity events. Args: events (L...
magic_evol_110k
69,875
Write a Python function to find the index of a given item in a list and the corresponding value from a dictionary where the key is the given item. The function should handle scenarios where the item is not present in either the list or the dictionary. The code should start with: ```python from typing import List, Dict,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple, Optional def find_item_and_value(my_list: List[str], my_dict: Dict[str, int], item: str) -> Tuple[Optional[int], Optional[int]]: """ Find the index of an item in a list and the correspondin...
magic_evol_110k
69,877
Write a Python function to generate a properly constructed SQL Inner Join statement using standard syntax. The function should take two table names and a condition as input and return the SQL query string. The condition should be formatted as a string in the form "column1 = column2". Additionally, the function should i...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_inner_join_query(table1: str, table2: str, condition: str) -> str: """ Generates a properly constructed SQL Inner Join statement using standard syntax. Args: table1 (str): The name of the first table. ...
magic_evol_110k
69,879
Write a Python function to determine whether a given integer is a prime number. The function should efficiently check for primality by considering only up to the square root of the number and handle edge cases such as negative numbers, 0, and 1. The code should start with: ```python def is_prime(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines whether a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. ...
magic_evol_110k
69,893
Write a Python function to predict which party will finally announce the victory in the Dota2 Senate voting procedure. The function should take a string representing each senator's party affiliation (`'R'` for Radiant and `'D'` for Dire) and return the winning party (`'Radiant'` or `'Dire'`). Each senator can ban one s...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque def predict_party_victory(senate: str) -> str: """ Predict which party will finally announce the victory in the Dota2 Senate voting procedure. Args: senate (str): A string representing...
magic_evol_110k
69,904
Write a Python function to find the indices of prime numbers in a given list and return them in a list format. The function should take a list of integers as input and return a list of indices where the corresponding elements are prime numbers. The code should start with: ```python from typing import List def find_pr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
magic_evol_110k
69,914
Write a Python function to calculate the power of a given base raised to a specified exponent using both the `pow` function and the exponentiation operator (`**`). The function should return a tuple containing the results from both methods. Additionally, ensure that the function handles edge cases such as negative expo...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_power(base: int, exponent: int) -> tuple: """ Calculate the power of a given base raised to a specified exponent using both the `pow` function and the exponentiation operator (`**`). Args: base (int): ...
magic_evol_110k
69,927
Write a Python function to transform a flat array into a two-dimensional array. The function should take two parameters: the array and a number 'n' that represents the number of elements per sub-array. If the number of elements in the array is not a multiple of 'n', the remaining elements should form a sub-array of the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transform_array(arr: List[int], n: int) -> List[List[int]]: """ Transforms a flat array into a two-dimensional array. Args: arr (List[int]): The flat array to be transformed. n (...
magic_evol_110k
69,929
Write a Python function to calculate the frequency of each unique alphabetic character in a given string, ignoring spaces. The function should return a dictionary where the keys are the characters and the values are their respective frequencies. The code should start with: ```python from collections import Counter fro...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import Counter from typing import Dict def character_frequency(input_string: str) -> Dict[str, int]: """ Calculate the frequency of each unique alphabetic character in the given string, ignoring spaces. Ar...
magic_evol_110k
69,943
Write a Python function to create a dictionary from a list of tuples, where each tuple contains a key-value pair. The function should also handle an optional parameter that allows the user to specify a default value for keys that are not present in the dictionary. If the default value is not provided, the function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Any from collections import defaultdict def create_dict_with_default(components: List[Tuple[str, int]], default: Any = None) -> dict: """ Create a dictionary from a list of tuples with an optiona...
magic_evol_110k
69,950
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
69,951
Write a Python function to evaluate the aggregation sum of a numerical matrix of real or complex numbers. The function should incrementally sum up the components of the matrix and return the final sum. The matrix can be a list of integers, floats, or complex numbers. 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, Union def aggregate_sum(matrix: List[Union[int, float, complex]]) -> Union[int, float, complex]: """ Evaluate the aggregation sum of a numerical matrix of real or complex numbers. Args: mat...
magic_evol_110k
69,963
Write a Python function to manipulate the coloration of displayed text within a console output environment, considering cross-platform functionality as well as the preservation of existing visual elements. The function should accept a text string and a color code (as an integer) and return the colored text string. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def color_text(text: str, color_code: int) -> str: """ Returns the given text string with the specified color applied using ANSI escape sequences. Args: text (str): The text string to be colored. color_code ...
magic_evol_110k
69,981
Write a Python function `bf` that takes three strings representing names of planets in our solar system and returns a tuple containing the names of planets that are closer to the Sun than the input planets, sorted in the order of their proximity to the Sun. If any of the input planet names are not valid, the function s...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid(planet: str) -> bool: """ Validate if the given planet name is a valid planet in our solar system. Args: planet (str): The name of the planet to validate. Returns: bool: True if the planet ...
magic_evol_110k
69,982
Write a Python function to determine if a specific key `k` is present within a nested tuple structure. The function should recursively search through all levels of the nested tuple to find the key. The code should start with: ```python def find_key_in_tuple(tuple_input: tuple, k: any) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_key_in_tuple(tuple_input: tuple, k: any) -> bool: """ Recursively searches for a specific key `k` within a nested tuple structure. Args: tuple_input (tuple): The nested tuple structure to search within. ...
magic_evol_110k
69,983
Write a Python function to calculate the cumulative differential outcome between multiple sets of quantitative entities, where each set consists of pairs of random integer values between 1 and 50. The differential outcome for each pair (x, y) is calculated as the absolute difference |x - y|. The function should return ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def cumulative_differential_outcome(num_sets: int, num_pairs: int) -> int: """ Calculate the cumulative differential outcome between multiple sets of quantitative entities. Each set co...
magic_evol_110k
69,987
Write a Python function to sort a list of numbers in ascending order using the bubble sort algorithm. The function should handle various edge cases, such as an empty list, a list with a single element, and a list with duplicate elements. The function should also ensure that all elements in the list are either integers ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def bubble_sort(x: List[Union[int, float]]) -> List[Union[int, float]]: """ Sorts a list of numbers in ascending order using the bubble sort algorithm. Args: x (List[Union[int, float]...
magic_evol_110k
69,989
Write a Python function to substitute each occurrence of the character '0' with the character 'x' in a given 2D matrix of character elements. The function should not use nested loops, recursion, or built-in functions like `replace()`. The code should start with: ```python from typing import List def replace_zero_in_ma...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_zero_in_matrix(matrix: List[List[str]]) -> List[List[str]]: """ Substitutes each occurrence of the character '0' with the character 'x' in a given 2D matrix of character elements. Args: ...
magic_evol_110k
69,997
Write a Python function to implement the Bubble Sort algorithm to sort a given list of integers in ascending order. 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...
magic_evol_110k
69,999
Write a Python function to search for and retrieve the values of a specified key, `target_key`, in a nested dictionary. The dictionary's structure is not constant, and it may contain varying levels of nesting. The function should return all found values as a list in the order of discovery. If no `target_key` is found, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def find_nested_keys(input_dict: Dict[str, Any], target_key: str) -> List[Any]: """ Search for and retrieve the values of a specified key in a nested dictionary. Args: input_dict ...
magic_evol_110k
70,001
Write a Python function to replace each letter in a given string with its immediate successor in the English alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters. The code should start with: ```python def replace_letter_entities(string: str) -> str...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_letter_entities(string: str) -> str: """ Replace each letter in the given string with its immediate successor in the English alphabet. Non-alphabetic characters remain unchanged. Args: string (str): ...
magic_evol_110k
70,013
Write a Python function to split a given string into words and return a list of these words. The function should handle multiple spaces between words and leading/trailing spaces. The code should start with: ```python from typing import List def split_string_into_words(s: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_string_into_words(s: str) -> List[str]: """ Splits a given string into words and returns a list of these words. Args: s (str): The input string to be split into words. Returns...
magic_evol_110k
70,014
Write a Python function to concatenate two given strings with a space in between them. The function should ensure that the two strings are non-identical and non-empty before performing the concatenation. If either string is empty or if the strings are identical, the function should return an empty string. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings_with_space(str1: str, str2: str) -> str: """ Concatenates two non-empty, non-identical strings with a space in between. Args: str1 (str): The first string to concatenate. str2 (str): ...
magic_evol_110k
70,015
Write a Python function to remove duplicate elements from a given list, sort the list in ascending order, find the 2nd largest element, and calculate the sum of the entire list after duplicate removal and sorting. The function should return a tuple containing the sorted list, the 2nd largest element, and the sum of the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def process_list(arr: List[int]) -> Tuple[List[int], int, int]: """ Processes the given list by removing duplicates, sorting it in ascending order, finding the 2nd largest element, and calcula...
magic_evol_110k
70,017
Write a Python function to concatenate two strings with a space in between and then append an exclamation mark at the end. The function should take two strings as input and return the resultant concatenated string. The code should start with: ```python def concatenate_with_exclamation(str1: str, str2: str) -> str: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_with_exclamation(str1: str, str2: str) -> str: """ Concatenates two strings with a space in between and appends an exclamation mark at the end. Args: str1 (str): The first string to be concatenated. ...
magic_evol_110k
70,025
Write a Python function to sort an array of fractional numbers in ascending order without using any in-built sorting functions. The function should implement the Bubble Sort algorithm. The code should start with: ```python from typing import List def sort_fractional_numbers(nums: List[float]) -> List[float]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_fractional_numbers(nums: List[float]) -> List[float]: """ Sorts an array of fractional numbers in ascending order using the Bubble Sort algorithm. Args: nums (List[float]): The arra...
magic_evol_110k
70,028
Write a Python function to return only positive numbers from the input list, multiply them by a given multiplier, and sort them in ascending order. Additionally, implement two helper functions: one to multiply the positive numbers by the given multiplier and another to swap elements for sorting purposes. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_positive_multiply_and_sort(l: List[int], n: int) -> List[int]: """Return only positive numbers in the list multiplied by n and sorted in ascending order. Args: l (List[int]): The input l...
magic_evol_110k
70,029
Write a Python function that accepts a list of strings as input. The function should return a dictionary where the keys are the words with the most unique characters and their frequencies. If multiple words have the same maximum count of unique characters, the function should return the last one in the list. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_max_unique_chars(words: List[str]) -> Dict[str, Dict[str, int]]: """ Finds the word with the most unique characters and returns a dictionary with the word and its character frequencies. ...
magic_evol_110k
70,036
Write a Python function to calculate the total count of unique employees for a specified company from a given list. The list is formatted as `[["Company", "Role", "First Name", "Surname"]]`. Consider cases where employees may have different roles at different companies, and note that the company name and employee names...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_employees(company_list: List[List[str]], company_name: str) -> int: """ Calculate the total count of unique employees for a specified company from the given list. Args: comp...
magic_evol_110k
70,044
Write a Python function to determine if two dictionaries are equivalent, meaning they have the same keys and corresponding values, regardless of the order of the keys. The function should return `True` if the dictionaries are equivalent and `False` otherwise. The code should start with: ```python from typing import Di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def are_dictionaries_equivalent(dict1: Dict[str, str], dict2: Dict[str, str]) -> bool: """ Determines if two dictionaries are equivalent, meaning they have the same keys and corresponding values, regardl...
magic_evol_110k
70,047
Write a Python function to extract a list of unique words from a given sentence, considering case insensitivity and handling punctuation. The function should return a list of unique words in lowercase. The code should start with: ```python from typing import List import re def extract_unique_words(sentence: str) -> L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_unique_words(sentence: str) -> List[str]: """ Extracts a list of unique words from a given sentence, considering case insensitivity and handling punctuation. Args: sent...
magic_evol_110k
70,054
Write a Python function to store a list of names in a nested dictionary structure. The outer dictionary should have keys representing the first letter of the names, and the inner dictionaries should store the names with their frequency count. The function should handle case sensitivity and ensure that names are stored ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def create_nested_dict(names: List[str]) -> Dict[str, Dict[str, int]]: """ Store a list of names in a nested dictionary structure. The outer dictionary has keys representing the first letter o...
magic_evol_110k
70,057
Write a Python function to sort an array of numbers from low to high using the **Insertion Sort** algorithm. The function should not use any built-in sort methods. The code should start with: ```python from typing import List def insertion_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 insertion_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the Insertion Sort algorithm. Args: arr (List[int]): The array of integers to be sort...
magic_evol_110k
70,062
Write a Python function to determine if a sub-vector `[x, y, z]` is present anywhere in a given 4D array `lst4d`. The function should return a list of quadruplets, each representing the coordinates `(depth1, depth2, row, index)` where the sub-vector `[x, y, z]` is found. The returned list of quadruplets should be sorte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_subvector_in_4d(lst4d: List[List[List[List[int]]]], x: int, y: int, z: int) -> List[Tuple[int, int, int, int]]: """ Find all occurrences of the sub-vector [x, y, z] in a 4D array lst4d an...
magic_evol_110k
70,071
Write a Python function to count the number of distinct words in a given sentence, considering case insensitivity. The function should split the sentence into words, convert them to lowercase, and then count the unique words. The code should start with: ```python def count_distinct_words(sentence: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_distinct_words(sentence: str) -> int: """ Counts the number of distinct words in a given sentence, considering case insensitivity. Args: sentence (str): The input sentence from which to count distinct word...
magic_evol_110k
70,072
Write a Python function to find the position of the first occurrence of a specified integer in an ordered array. If the integer is not present, return the index where it should be inserted to maintain the array's order. The function should handle edge cases such as an empty array or an array with a single element. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def search_insert_position(nums: List[int], target: int) -> int: """ Find the position of the first occurrence of a specified integer in an ordered array. If the integer is not present, return the in...
magic_evol_110k
70,074
Write a Python function to implement a `Book` class that includes private properties for `title`, `author`, `genre`, and `number_of_pages`. The class should include: 1. Default parameters to initialize properties if no value is passed during object creation. 2. Getters and setters for all properties with validation (i....
Here is the Python code to solve the given problem in the markdown block: ```python class Book: def __init__(self, title="Unknown", author="Unknown", genre="Unknown", number_of_pages=0): """ Initialize the Book object with title, author, genre, and number of pages. Args: title (...
magic_evol_110k
70,079
Write two Python functions, `str_to_int_list` and `validate_list`, that work together to process a string of space-separated integers and validate the resulting list. The `str_to_int_list` function should convert the input string into a list of integers, handling any non-integer values by raising a `TypeError`. The `va...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def str_to_int_list(input_str: str) -> List[int]: """ Converts a string of space-separated integers into a list of integers. Args: input_str (str): A string containing space-separated intege...
magic_evol_110k
70,091
Write a Python function to determine if the balance of a bank account ever drops below zero during a series of deposit and withdrawal operations. The operations can be either integers or strings that represent integers. Additionally, include an optional `case_insensitive` flag that, when set to `True`, makes the functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def below_zero(operations: List[Union[int, str]], case_insensitive: bool = False) -> bool: """ Determine if the balance of a bank account ever drops below zero during a series of deposit and withd...
magic_evol_110k
70,092
Write a Python function to reconstruct a balanced binary search tree (BST) from a sorted doubly-linked list. The function should ensure that the BST maintains the property of balanced binary search trees: for every node, the height difference between the left and right subtrees is no more than one. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, value=0, prev=None, next=None): self.value = value self.prev = prev self.next = next class TreeNode: def __init__(self, value=0, left=None, right=None): self.va...
magic_evol_110k
70,096
Write a Python function to identify the smallest alphanumeric string value from a given list of strings. The function should return the smallest string based on lexicographical order. The code should start with: ```python from typing import List def find_smallest_string(strings: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_string(strings: List[str]) -> str: """ Finds the smallest alphanumeric string from a given list of strings. Args: strings (List[str]): A list of strings from which to find ...
magic_evol_110k
70,102
Write a Python function to sort a list of mixed variable types (integers and strings) such that the integers remain in their original positions and only the strings are sorted alphabetically. The function should start with: ```python from typing import List, Union def sort_mixed_list(mix_list: 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_mixed_list(mix_list: List[Union[int, str]]) -> List[Union[int, str]]: """ Sorts a list of mixed variable types (integers and strings) such that the integers remain in their original posit...
magic_evol_110k
70,109
Write a Python function to find the nth Fibonacci number efficiently using an iterative approach. The function should accept a single integer `n` as its input parameter and return the nth Fibonacci number. The Fibonacci sequence is defined as: F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def find_nth_fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using an iterative approach. Args: n (int): The position in the Fibonacci sequence to find. Returns: int: The nth Fibonacci ...
magic_evol_110k
70,113
Write a Python function that simulates a 'while' loop running through a specified number of cycles, with the counter value incrementing by a given step for each cycle, starting from a specified initial value to a specified maximum value. The function should return a list of the counter values at the end of each cycle. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def simulate_loop(initial_value: int, max_value: int, step: int, cycles: int) -> List[int]: """ Simulates a 'while' loop running through a specified number of cycles, with the counter value incrementing ...
magic_evol_110k
70,120
Write a Python function to generate all possible permutations of a given list of numbers. The function should return a list of lists, where each inner list represents a unique permutation of the input list. The code should start with: ```python from typing import List def generate_permutations(numbers: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_permutations(numbers: List[int]) -> List[List[int]]: """ Generate all possible permutations of a given list of numbers. Args: numbers (List[int]): The list of numbers to permute...
magic_evol_110k
70,128
Write a Python function to transform a list of fruit names into a list of their corresponding capitalized versions. Each fruit name should be capitalized such that the first letter of each word in the name is in uppercase and the rest of the letters are in lowercase. The function should handle fruit names with multiple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def capitalize_fruit_names(fruits: List[str]) -> List[str]: """ Transforms a list of fruit names into a list of their corresponding capitalized versions. Each fruit name is capitalized such that the ...
magic_evol_110k
70,129
Write a Python function to construct a square matrix of dimension `n x n` filled with successive positive integers starting from 1 in a row-major order. The function should return the constructed matrix. The code should start with: ```python from typing import List def construct_square_matrix(n: int) -> List[List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def construct_square_matrix(n: int) -> List[List[int]]: """ Constructs a square matrix of dimension n x n filled with successive positive integers starting from 1 in a row-major order. Args: ...
magic_evol_110k
70,136
Write a Python function that formats a given number according to a specified format string. The function should support various formatting options such as decimal, floating-point, scientific notation, hexadecimal, octal, and binary representations. The format string should be flexible enough to allow for precision and ...
Here is the Python code to solve the given problem in the markdown block: ```python def format_number(number: float, format_spec: str) -> str: """ Formats a given number according to a specified format string. Args: number (float): The number to be formatted. format_spec (str): The format s...
magic_evol_110k
70,146
Write a Python function to calculate the number of combinations and permutations of selecting `r` items from a set of `n` items. The function should handle the calculation of factorial values using recursion and avoid variable name conflicts. The code should start with: ```python def factorial(n: int) -> int: """Ca...
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Calculate the factorial of a non-negative integer n. Args: n (int): The non-negative integer to calculate the factorial of. Returns: int: The factorial of n. """ ...
magic_evol_110k
70,159
Write a Python function to generate a random string of a specified length, consisting only of lowercase alphabetic characters. The function should ensure that the generated string meets the specified length and contains only valid characters. The code should start with: ```python import random import string def gener...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_random_string(length: int) -> str: """ Generates a random string of the specified length, consisting only of lowercase alphabetic characters. Args: length (int): The length ...
magic_evol_110k
70,187
Write a Python function to find the second largest value in a given list of integers. The function should handle lists with duplicate values and should be efficient in terms of both time and space complexity. The function should start with: ```python from typing import List def find_second_largest(numbers: List[int]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_largest(numbers: List[int]) -> int: """ Find the second largest value in a given list of integers. Args: numbers (List[int]): The list of integers from which to find the seco...
magic_evol_110k
70,198
Write a Python function to replace all instances of the number zero with the number one in a given list of integers. The function should return a new list with the replacements made. The code should start with: ```python from typing import List def replace_zeros_with_ones(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 replace_zeros_with_ones(input_list: List[int]) -> List[int]: """ Replaces all instances of the number zero with the number one in a given list of integers. Args: input_list (List[int]): ...
magic_evol_110k
70,205
Write a Python function that takes two lists of strings and a long text as input. The function should replace all instances of the strings in the first list found in the text with their corresponding strings in the second list, ensuring that the replacement strings themselves are not subjected to further replacements. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_replace(str_list1: List[str], str_list2: List[str], text: str) -> str: """ Replaces all instances of the strings in the first list found in the text with their corresponding strings in the sec...
magic_evol_110k
70,212
Write a Python function that processes a list of strings, removing any forbidden characters (e.g., special characters, whitespaces) from each string, sorts the cleaned strings alphabetically, and then determines and displays the frequency of each unique cleaned string. The function should handle edge cases such as empt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def process_and_analyze_strings(strings: List[str]) -> None: """ Processes a list of strings by removing forbidden characters, sorts the cleaned strings alphabetically, and then determines ...
magic_evol_110k
70,215
Write a Python program that generates and prints all Fibonacci numbers from 1 to 100. Additionally, the program should check and display whether each Fibonacci number is a prime number or not. For non-prime Fibonacci numbers, the program should provide their smallest prime factors. This should be implemented using a fo...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Check if a number is a prime number. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <= 1...
magic_evol_110k
70,219
Write a Python function to generate a random 6-digit number. The function should ensure that the generated number is always a 6-digit integer, i.e., it should be between 100000 and 999999 inclusive. The code should start with: ```python import random def generate_random_6_digit_number() -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_6_digit_number() -> int: """ Generates a random 6-digit number. Returns: int: A random 6-digit number between 100000 and 999999 inclusive. """ # Generate a random integer b...
magic_evol_110k
70,255
Write a Python function to calculate the minimum value in a 2D array, its corresponding positions (row, column), and its frequency in the array. The function should not use built-in Python functions like `min()`. The code should start with: ```python from typing import List, Tuple def find_min_info(arr: List[List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_min_info(arr: List[List[int]]) -> Tuple[int, List[Tuple[int, int]], int]: """ Calculate the minimum value in a 2D array, its corresponding positions (row, column), and its frequency. ...
magic_evol_110k
70,260
Write a Python function to divide each pair of numbers in a given list of tuples and return the results in a new list. If a division by zero occurs, append the string "Error: Division by Zero" to the result list instead. The function should handle the division operation for each pair and manage potential exceptions. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def divide_pairs(pair_list: List[Tuple[int, int]]) -> List[float or str]: """ Divides each pair of numbers in a given list of tuples and returns the results in a new list. If a division by zer...
magic_evol_110k
70,261
Write a Python function to join an array of string elements with a specified delimiter. The function should allow the user to choose between three different delimiters: a space (' '), no delimiter (''), and a hyphen ('-'). The function should return the concatenated string based on the chosen delimiter. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Literal def join_string_elements(arr: List[str], delimiter: Literal[' ', '', '-']) -> str: """ Joins an array of string elements with a specified delimiter. Args: arr (List[str]): The array...
magic_evol_110k
70,267
Write a Python function to generate an infinite sequence of natural numbers starting from a given number with a specified step. The function should yield each number in the sequence one at a time. The code should start with: ```python def generate_sequence(starting_number: int, step: int): ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_sequence(starting_number: int, step: int): """ Generates an infinite sequence of natural numbers starting from a given number with a specified step. Args: starting_number (int): The initial number of th...
magic_evol_110k
70,273
Write a Python function to generate the first `n` numbers of the Fibonacci sequence using the `sympy` library. The function should return a list of the first `n` Fibonacci numbers. The code should start with: ```python from typing import List import sympy 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 import sympy def generate_fibonacci(n: int) -> List[int]: """ Generate the first n numbers of the Fibonacci sequence using the sympy library. Args: n (int): The number of Fibonacci numbers t...
magic_evol_110k
70,282
Write a Python function to generate two lists: one containing the squared values of the first ten odd integers, and another containing the running sums of these squared values. The function should return both lists in ascending order. The code should start with: ```python from typing import List, Tuple def squared_an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def squared_and_running_sum() -> Tuple[List[int], List[int]]: """ Generate two lists: one containing the squared values of the first ten odd integers, and another containing the running sums o...
magic_evol_110k
70,308
Write a Python function to process a list of lists, where each sublist contains strings. The function should perform two operations: first, remove any duplicate strings within each sublist, and second, sort each sublist in ascending order. The function should return the processed list of lists. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_sublists(sublists: List[List[str]]) -> List[List[str]]: """ Processes a list of lists of strings by removing duplicates within each sublist and sorting each sublist. Args: sublis...
magic_evol_110k
70,322
Write a Python function to create a deep copy of a given multi-dimensional list (containing integers) without using the `copy.deepcopy()` function or any other built-in function that directly clones the object. The function should be able to handle lists of any feasible length and depth. 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 deep_copy_list(lst: List[int]) -> List[int]: """ Creates a deep copy of a given multi-dimensional list containing integers. Args: lst (List[int]): The original multi-dimensional list to ...
magic_evol_110k
70,330
Write a Python function to flatten a given 3D matrix that may contain nested lists. The function should handle any level of nesting and should not use any built-in functions specifically designed for flattening lists. The code should start with: ```python from typing import List, Any def flatten_3d_matrix(matrix: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_3d_matrix(matrix: List[List[List[Any]]]) -> List[Any]: """ Flattens a 3D matrix that may contain nested lists of any depth. Args: matrix (List[List[List[Any]]]): The 3D matr...
magic_evol_110k
70,333
Write a Python function to verify if a specific set of items is a subset of a larger set of items, ensuring there are no duplications. The function should take two lists as input and return a boolean indicating whether the first list is a subset of the second list. 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 is_subset_without_duplicates(set1: List[str], set2: List[str]) -> bool: """ Verifies if the first set of items is a subset of the second set of items, ensuring there are no duplications. Args: ...
magic_evol_110k
70,337
Write a Python function to create a histogram of characters in a given string, considering uppercase and lowercase letters as the same, and including numbers and punctuation marks. The function should return a dictionary containing the character(s) with the highest frequency (in lowercase for letters) and the correspon...
Here is the Python code to solve the given problem in the markdown block: ```python def advanced_histogram(test: str) -> dict: """ Given a string containing space separated characters (including uppercase and lowercase letters, numbers, and punctuation marks), return a dictionary of the character(s) with th...
magic_evol_110k
70,340
Write a Python function to find the maximum value in a list of integers and return it. The function should handle lists of any length, 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: Lis...
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 and return the maximum value in a list of integers. Args: numbers (List[int]): A list of integers from which to fi...
magic_evol_110k
70,353
Write a Python function to convert all the lowercase letters in a given string to their corresponding uppercase letters without using the built-in `upper()` method. The function should handle strings with mixed characters (both uppercase and lowercase) and non-alphabetic characters (such as numbers and punctuation). T...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(s: str) -> str: """ Converts all lowercase letters in the given string to their corresponding uppercase letters. Args: s (str): The input string to be converted. Returns: str: T...
magic_evol_110k
70,357
Write a Python function to find the smallest non-negative number from each of two given lists of floating-point numbers. If a list does not contain any non-negative numbers, the function should return `None` for that list. The function should handle any given lists, including those with all negative numbers or empty li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_smallest_non_negative(list1: List[float], list2: List[float]) -> Tuple[Optional[float], Optional[float]]: """ Find the smallest non-negative number from each of two given lists ...
magic_evol_110k
70,366
Write a Python function to obscure designated phrases or keywords in a given body of text. The function should replace each occurrence of the specified keywords with a sequence of asterisks (`*`) of the same length as the keyword. The function should handle case sensitivity and should not modify the original text. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def obscure_keywords(text: str, keywords: List[str]) -> str: """ Obscures designated phrases or keywords in a given body of text by replacing each occurrence of the specified keywords with a sequenc...
magic_evol_110k
70,367
Write a Python function to extract and return only the numeric characters from a given string. The function should handle any string input and return a string containing only the digits found in the input string. The code should start with: ```python def extract_numeric_characters(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def extract_numeric_characters(s: str) -> str: """ Extracts and returns only the numeric characters from the given string. Args: s (str): The input string from which to extract numeric characters. Returns: ...
magic_evol_110k
70,369
Write a Python function to merge two sorted lists of integers into one sorted list without using the in-built sort function. The function should efficiently combine the two lists by comparing elements from each list and appending the smaller element to the result 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 def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merge two sorted lists of integers into one sorted list without using the in-built sort function. Args: list1 (Li...
magic_evol_110k
70,372
Write a Python function to validate and classify an IPv6 address into one of the following categories: Unicast, Multicast, or Anycast. The function should return a string indicating the type of IPv6 address or "Invalid" if the address does not match any valid IPv6 format. The code should start with: ```python import r...
Here is the Python code to solve the given problem in the markdown block: ```python import re def classify_ipv6(ip: str) -> str: """ Classify an IPv6 address into Unicast, Multicast, Anycast, or Invalid. Args: ip (str): The IPv6 address to classify. Returns: str: The classification of...
magic_evol_110k
70,373
Write a Python function to verify if two given verbal expressions incorporate the same array of words with an equal incidence rate. The function should return `True` if the word frequencies in both expressions are identical, and `False` otherwise. The function should handle case sensitivity by converting all words to l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def verify_word_set_frequency(expression1: str, expression2: str) -> bool: """ Verify if the two specified verbal expressions incorporate the same array of words with an e...
magic_evol_110k
70,374
Write a Python function to calculate and return the square root of a given non-negative number. If the input number is negative, the function should return `None`. The function should use the `math.sqrt` function from the `math` module to compute the square root. The code should start with: ```python import math def ...
Here is the Python code to solve the given problem in the markdown block: ```python import math def square_root(num: float) -> float: """ Calculate the square root of a given non-negative number. Args: num (float): The number for which to calculate the square root. Returns: float: The...
magic_evol_110k
70,385
Write a Python function to analyze a given list of elements and categorize them into three types: decimal numeric values, distinct typographical characters, and other types. The function should return a dictionary containing the count of each category. The code should start with: ```python from typing import List, Dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union def analyze_elements(data: List[Union[float, str, int]]) -> Dict[str, int]: """ Analyzes a list of elements and categorizes them into decimal numeric values, distinct typographical character...
magic_evol_110k
70,391
Write a Python function to multiply two given 2D matrices. The function should handle matrices of any size, provided they are compatible for multiplication (i.e., the number of columns in the first matrix should be equal to the number of rows in the second matrix). The function should return the resulting matrix after ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_multiplication(matrixA: List[List[int]], matrixB: List[List[int]]) -> List[List[int]]: """ Multiplies two given 2D matrices and returns the resulting matrix. Args: matrixA (List[L...
magic_evol_110k
70,400
Write a Python function to generate the Collatz sequence starting from a given positive integer `n` up to 1. The function should also calculate the total number of steps to reach 1 and find the highest number encountered in the sequence. The function should be efficient and optimized for large values of `n` (particular...
Here is the Python code to solve the given problem in the markdown block: ```python def collatz_sequence(n: int) -> tuple: """ Generates the Collatz sequence starting from a given positive integer n up to 1. Also calculates the total number of steps to reach 1 and finds the highest number encountered in the...
magic_evol_110k
70,401
Write a Python function to sort an array of mixed data types (integers and strings) in ascending order using the Selection Sort algorithm. The function should handle the comparison between integers and strings, considering that 'a' < 'b' and 1 < 2, 'a' < 1, etc. The function should not use any built-in sort functions o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def mixed_data_selection_sort(arr: List[Union[int, str]]) -> List[Union[int, str]]: """ Sorts an array of mixed data types (integers and strings) in ascending order using the Selection Sort algori...
magic_evol_110k
70,411
Write a Python function to group and count dates per month and year in a specific format. Given a DataFrame with a 'Date' column and a 'Val' column, the function should add three new columns: 'Count_d' (count of occurrences per day), 'Count_m' (count of occurrences per month), and 'Count_y' (count of occurrences per ye...
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd def count_dates_per_period(df: pd.DataFrame) -> pd.DataFrame: """ Groups and counts dates per day, month, and year in a DataFrame. Args: df (pd.DataFrame): The input DataFrame with 'Date' and 'V...
magic_evol_110k
70,427
Write a Python function to identify all prime numbers within a given array and calculate their sum. The function should handle arrays of arbitrary size and include edge cases such as empty arrays and arrays containing negative numbers. Avoid using in-built functions for identifying primes and ensure the program can eff...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False other...
magic_evol_110k
70,442
Write a Python function to determine if there exists a pair of indices (i, j) such that the elements at these indices in two given arrays A and B are equal. If such a pair exists, return the pair of indices; otherwise, return `False`. The code should start with: ```python from typing import List, Tuple, Union def fin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_matching_indices(A: List[int], B: List[int]) -> Union[Tuple[int, int], bool]: """ Determine if there exists a pair of indices (i, j) such that A[i] == B[j]. Args: A (L...
magic_evol_110k
70,448
Write a Python function to retain the first occurrence of each integer in a given array of integers, discarding any repeated occurrences, and return the array in its original order. The function should not use any built-in functions or additional libraries. 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 retain_first_occurrences(objects: List[int]) -> List[int]: """ Retains the first occurrence of each integer in the given array and discards any repeated occurrences, returning the array in its or...
magic_evol_110k
70,463
Write a Python function to generate a list of even integers within a specified range `[start, end)`. The function should handle cases where `start` is greater than or equal to `end` by returning an empty list. The function should also ensure that the `start` and `end` values are integers. 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 generate_even_numbers(start: int, end: int) -> List[int]: """ Generate a list of even integers within the specified range [start, end). Args: start (int): The starting integer of the ran...
magic_evol_110k
70,469
Write a Python function to generate and store combinations of numbers from two nested loops. The outer loop should iterate over the numbers 1 to 10, and the inner loop should iterate over the numbers from the current number of the outer loop to 10. Each combination should be stored in a dictionary with the format "i-j"...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_combinations(): """ Generates and stores combinations of numbers from two nested loops. The outer loop iterates over the numbers 1 to 10, and the inner loop iterates over the numbers from the current number ...
magic_evol_110k
70,470
Write a Python function to find the maximum element and its index in a given array without using any in-built functions or methods. The function should handle arrays with both positive and negative numbers. The code should start with: ```python from typing import List, Tuple def find_max_element_and_index(arr: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_element_and_index(arr: List[int]) -> Tuple[int, int]: """ Finds the maximum element and its index in a given array without using in-built functions or methods. Args: arr ...
magic_evol_110k
70,492
Write a Python function to filter out all the odd numbers from a given list of integers. The function should raise a `ValueError` if the input is not a list or if any element in the list is not an integer. The function should start with: ```python from typing import List def odd_numbers(num_list: List[int]) -> List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def odd_numbers(num_list: List[int]) -> List[int]: """ Filters out all the odd numbers from a given list of integers. Args: num_list (List[int]): A list of integers from which to filter out ...
magic_evol_110k
70,501
Write a Python function to determine if two given string inputs are anagrams of each other, considering case sensitivity. The function should return `True` if the strings are anagrams and `False` otherwise. Additionally, optimize the function to run with a time complexity better than O(n log n). The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import Counter def are_anagrams(str1: str, str2: str) -> bool: """ Determines if two given strings are anagrams of each other, considering case sensitivity. Args: str1 (str): The first string to co...
magic_evol_110k
70,515
Write a Python function to sort a multidimensional array using the cocktail shaker sort method. The function should organize elements in the array from smallest to largest and from left to right, then top to bottom. Additionally, the function should handle elements of equal value by maintaining their relative order. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cocktail_shaker_sort(arr: List[int]) -> List[int]: """ Sorts a list using the cocktail shaker sort method. Args: arr (List[int]): The list to be sorted. Returns: List[int]: ...