Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.

Examples
is_sorted([5]) ➞ True
is_sorted([1, 2, 3, 4, 5]) ➞ True
is_sorted([1, 3, 2, 4, 5]) ➞ False
is_sorted([1, 2, 3, 4, 5, 6]) ➞ True
is_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True
is_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False
is_sorted([1, 2, 2, 3, 3, 4]) ➞ True
is_sorted([1, 2, 2, 2, 3, 4]) ➞ False
Response:
```python
def is_sorted(lst):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to determine whether the length of intersection of these two
intervals is a prime number.
Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
which its length is 1, which not a prime number.
If the length of the intersection is a prime number, return "YES",
otherwise, return "NO".
If the two intervals don't intersect, return "NO".

[input/output] samples:
intersection((1, 2), (2, 3)) ==> "NO"
intersection((-1, 1), (0, 4)) ==> "NO"
intersection((-3, -1), (-5, 5)) ==> "YES"
Response:
```python
def intersection(interval1, interval2):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr.

Example:
>>> prod_signs([1, 2, 2, -4]) == -9
>>> prod_signs([0, 1]) == 0
>>> prod_signs([]) == None
Response:
```python
def prod_signs(arr):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.

You have to find the minimum path of length k in the grid. You can start
from any cell, and in each step you can move to any of the neighbor cells,
in other words, you can go to cells which share an edge with you current
cell.
Please note that a path of length k means visiting exactly k cells (not
necessarily distinct).
You CANNOT go off the grid.
A path A (of length k) is considered less than a path B (of length k) if
after making the ordered lists of the values on the cells that A and B go
through (let's call them lst_A and lst_B), lst_A is lexicographically less
than lst_B, in other words, there exist an integer index i (1 <= i <= k)
such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
lst_A[j] = lst_B[j].
It is guaranteed that the answer is unique.
Return an ordered list of the values on the cells that the minimum path go through.

Examples:

    Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3
    Output: [1, 2, 1]

    Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1
    Output: [1]
Response:
```python
def minPath(grid, k):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
For example:
tri(2) = 1 + (2 / 2) = 2
tri(4) = 3
tri(3) = tri(2) + tri(1) + tri(4)
       = 2 + 3 + 3 = 8
You are given a non-negative integer number n, you have to a return a list of the
first n + 1 numbers of the Tribonacci sequence.
Examples:
tri(3) = [1, 3, 2, 8]
Response:
```python
def tri(n):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
For example:
digits(1)  == 1
digits(4)  == 0
digits(235) == 15
Response:
```python
def digits(n):


Prompt:
Instruction:Write a function that takes in a list of strings words and an integer n. The function should return the concatenation of the first n strings from the list words where each string contains at most three characters.

Example:
Input: words = ['abc', 'defg', 'hij', 'klmno', 'pqrstu'], n = 3
Output: 'abchijklmno'

Constraints:

1 <= len(words) <= 50
1 <= n <= len(words)
Response:
```python
def concatenate_words(words, n):
    # Initialize an empty string for the concatenated result
    result = ""

    # Iterate through the first n elements of words
    for word in words[:n]:
        # Check if the length of the word is at most three characters
        if len(word) <= 3:
            # Concatenate the word to the result
            result += word

    return result
```

Instruction: Write a Python function called 'is_square_number' that takes an integer 'num' as input and returns True if 'num' is a perfect square, and False otherwise.
Response:
```python
def is_square_number(num: int) -> bool:
    """
    Checks if an integer is a perfect square.

    Args:
        num (int): The integer to check.

    Returns:
        bool: True if the integer is a perfect square, False otherwise.
    """
    if num < 0:
        return False

    square_root = int(num ** 0.5)
    return square_root * square_root == num

# Test cases
print(is_square_number(1))   # Output should be True
print(is_square_number(2))   # Output should be False
print(is_square_number(-1))  # Output should be False
print(is_square_number(64))  # Output should be True
print(is_square_number(0))   # Output should be True
print(is_square_number(180)) # Output should be False
```

Instruction: Create a function that returns True if the first character
of a given string is a digit and is not followed by another digit,
and False otherwise.
Note: A "digit" refers to a character from '0' to '9'.

Examples:
check_if_first_char_is_digit("123 apple") ➞ False
check_if_first_char_is_digit("123 456 apple") ➞ False
check_if_first_char_is_digit("1234 apple") ➞ True
check_if_first_char_is_digit("4 apple") ➞ True
check_if_first_char_is_digit("") ➞ False
Response:
```python
def check_if_first_char_is_digit(txt):
    if txt == "":
        return False
    first_char = txt[0]
    if first_char.isdigit():
        if len(txt) == 1:
            return True
        elif not txt[1].isdigit():
            return True
    return False
```

Instruction: Write a function sort_array that sorts an array of tuples based on the sum of their elements in ascending order. For tuples with the same sum of elements, sort based on the maximum element in the tuple.
Response:
```python
def sort_array(arr):
    return sorted(arr, key=lambda x: (sum(x), max(x)))

# Test cases
print(sort_array([(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
print(sort_array([(3, 2), (1, 4), (5, 6), (7, 8), (9, 10)]))  # Output: [(1, 4), (3, 2), (5, 6), (7, 8), (9, 10)]
```

Instruction: Write a Python function called 'custom_list' that takes a positive integer 'n' as input and returns a list of size 'n'. The value of the element at index 'i' is the factorial of 'i' if 'i' is even, or the sum of numbers from 1 to 'i' otherwise. Indexing starts from 1.
Response:
```python
def custom_list(n: int) -> List[int]:
    """
    Constructs a list of size n, where the value of the element at index i is the factorial of i if i is even,
    or the sum of numbers from 1 to i otherwise.

    Args:
        n (int): The size of the list.

    Returns:
        List[int]: The constructed list.
    """
    def factorial(num):
        if num == 0 or num == 1:
            return 1
        else:
            return num * factorial(num - 1)

    custom = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            custom.append(factorial(i))
        else:
            custom.append(sum(range(1, i + 1)))
    return custom

# Test case
print(custom_list(5))   # Output should be [1, 2, 6, 24, 15]
```

Instruction: Write a Python function called 'alternate_sort_list' that takes a list of integers as input and returns the list sorted in a strange order. In this strange order, you start with the minimum value, then the maximum of the remaining integers, then the minimum, and so on.
Response:
```python
def alternate_sort_list(lst):
    """
    Sorts a list of integers in a strange order.

    Args:
        lst (list): The list of integers to be sorted.

    Returns:
        list: The list sorted in a strange order.
    """
    sorted_lst = []
    lst.sort()
    while lst:
        sorted_lst.append(lst.pop(0))
        if lst:
            sorted_lst.append(lst.pop(-1))
    return sorted_lst

# Test cases
print(alternate_sort_list([1, 2, 3, 4]))   # Output should be [1, 4, 2, 3]
print(alternate_sort_list([5, 5, 5, 5]))   # Output should be [5, 5, 5, 5]
print(alternate_sort_list([]))             # Output should be []
```

Instruction: You are given a string representing a password.
If a character in the password is a letter, reverse its case (convert uppercase to lowercase and vice versa).
If a character in the password is a digit, replace it with its complement (9 - digit).
If a character in the password is a special character (not a letter or a digit), keep it as it is.
The function should return the modified password string.

Examples:
modify_password("AbCd1234") ➞ "aBcD8765" (A -> a, b -> B, C -> c, d -> D, 1 -> 8, 2 -> 7, 3 -> 6, 4 -> 5)
modify_password("P@𝑤0𝑟𝑑")➞"p@W9RD" (P -> p, @ -> @, $ -> $, $ -> $, w -> W, 0 -> 9, r -> R, d -> D)
Response:
```python
def modify_password(password):
    modified = ""
    for char in password:
        if char.isalpha():
            modified += char.swapcase()
        elif char.isdigit():
            modified += str(9 - int(char))
        else:
            modified += char
    return modified
```

Instruction: Write a Python function called 'sum_even_odd_indices' that takes a non-empty list of integers as input and returns the sum of the even elements that are at odd indices.
Response:
```python
def sum_even_odd_indices(lst):
    """
    Adds the even elements that are at odd indices in a list of integers.

    Args:
        lst (list): The list of integers.

    Returns:
        int: The sum of the even elements at odd indices.
    """
    return sum(lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0)

# Test cases
print(sum_even_odd_indices([4, 2, 6, 7]))  # Output should be 2
```

Instruction: Write a Python function called 'intersperse_chars' that takes a list of characters as input and returns a new list where a given character delimiter is inserted between every two consecutive characters of the input list.
Response:
```python
from typing import List

def intersperse_chars(chars: List[str], delimiter: str) -> List[str]:
    """
    This function inserts a character delimiter between every two consecutive characters of the input list.

    Args:
        chars (list): List of characters.
        delimiter (str): Character delimiter to be inserted between characters.

    Returns:
        list: List with delimiter inserted between consecutive characters.
    """
    if not chars:
        return []
    result = []
    for char in chars[:-1]:
        result.extend([char, delimiter])
    result.append(chars[-1])
    return result

# Test cases
print(intersperse_chars([], "-"))       # Output should be []
print(intersperse_chars(["a", "b", "c"], "-"))  # Output should be ['a', '-', 'b', '-', 'c']
```

Instruction: Write a function that takes a list of strings as input and returns the number of strings that have both their first and last characters as vowels ('a', 'e', 'i', 'o', 'u').

For example:
count_vowel_bookends(["apple", "banana", "orange", "pear", "kiwi"]) ➞ 2 (only "apple" and "orange" have both first and last characters as vowels)
count_vowel_bookends(["cat", "dog", "bird", "fish"]) ➞ 0 (none of the strings have both first and last characters as vowels)
count_vowel_bookends(["eye", "ear", "opal", "umbrella"]) ➞ 4 (all strings have both first and last characters as vowels)
Response:
```python
def count_vowel_bookends(strings):
    vowels = "aeiouAEIOU"
    count = 0
    for string in strings:
        if string[0].lower() in vowels and string[-1].lower() in vowels:
            count += 1
    return count
```

Instruction: Write a Python function called 'make_symmetric_string' that takes a string as input and returns the shortest symmetric string that begins with the supplied string. The algorithm idea is to find the longest postfix of the supplied string that is symmetric and then append to it the reverse of the prefix of the string before the symmetric suffix.
Response:
```python
def is_symmetric(string: str) -> bool:
    """Test if given string is symmetric."""
    return string == string[::-1]

def make_symmetric_string(string: str) -> str:
    """Find the shortest symmetric string that begins with a supplied string.
    Algorithm idea is simple:
    - Find the longest postfix of the supplied string that is symmetric.
    - Append to the end of the string the reverse of a prefix of the string before the symmetric suffix.

    Args:
        string (str): The supplied string.

    Returns:
        str: The shortest symmetric string that begins with the supplied string.

    >>> make_symmetric_string('')
    ''
    >>> make_symmetric_string('cat')
    'catac'
    >>> make_symmetric_string('cata')
    'catac'
    """
    if not string:
        return ''
    for i in range(len(string), 0, -1):
        if is_symmetric(string[-i:]):
            return string + string[:-i][::-1]

# Test cases
print(make_symmetric_string(''))       # Output should be ''
print(make_symmetric_string('cat'))    # Output should be 'catac'
print(make_symmetric_string('cata'))   # Output should be 'catac'
```

Instruction: Write a Python function called 'sort_unique_chars' that takes a string as input and returns a sorted list of unique characters in the string.
Response:
```python
def sort_unique_chars(s: str):
    """
    Returns sorted unique characters in a string.

    Args:
        s (str): Input string.

    Returns:
        list: Sorted list of unique characters.
    """
    return sorted(set(s))

# Test case
print(sort_unique_chars("hello"))  # Output should be ['e', 'h', 'l', 'o']
```

Instruction: Write a Python function called 'min_abs_sum_subarray' that takes a list of integers 'nums' as input and finds the minimum sum of any non-empty sub-array of 'nums'.
Response:
```python
def min_abs_sum_subarray(nums: List[int]) -> int:
    """
    Finds the minimum sum of any non-empty sub-array of nums.

    Args:
        nums (List[int]): The list of integers.

    Returns:
        int: The minimum sum of any non-empty sub-array.
    """
    if not nums:
        return 0

    current_sum = nums[0]
    min_sum = nums[0]

    for num in nums[1:]:
        current_sum = min(num, current_sum + num)
        min_sum = min(min_sum, current_sum)

    return min_sum

# Test cases
print(min_abs_sum_subarray([2, 3, 4, 1, 2, 4]))  # Output should be 1
print(min_abs_sum_subarray([-1, -2, -3]))        # Output should be -6
```

Instruction: Write a Python function called 'calculate_stats' that takes a list of floats as input and returns a tuple consisting of the sum and the average of all the floats in the list. If the list is empty, the sum should be 0 and the average should be None.
Response:
```python
from typing import List, Tuple

def calculate_stats(numbers: List[float]) -> Tuple[float, float]:
    """
    Calculates the sum and average of all the floats in a list.

    Args:
        numbers (List[float]): List of floats.

    Returns:
        Tuple[float, float]: A tuple consisting of the sum and the average of the floats.
    """
    if not numbers:
        return 0, None
    total_sum = sum(numbers)
    average = total_sum / len(numbers)
    return total_sum, average

# Test cases
print(calculate_stats([]))             # Output should be (0, None)
print(calculate_stats([1.5, 2.5, 3.5])) # Output should be (7.5, 2.5)
```

Instruction: Create a function that takes a string as input which contains only square brackets.
The function should return True if and only if there is a valid subsequence of brackets
where at least one bracket in the subsequence is nested.

is_nested('[[]]') ➞ True
is_nested('[]]]]]]][[[[[]') ➞ False
is_nested('[][]') ➞ False
is_nested('[]') ➞ False
is_nested('[[][]]') ➞ True
is_nested('[[]][[') ➞ True
Response:
```python
def is_nested(string):