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 an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".

For example:
  arr = [2, 1, 1, 4, 5, 8, 2, 3]
        -> sort arr -> [1, 1, 2, 2, 3, 4, 5, 8]
        -> reverse arr -> [8, 5, 4, 3, 2, 2, 1, 1]
  return ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]

  If the array is empty, return an empty array:
  arr = []
  return []

  If the array has any strange number ignore it:
  arr = [1, -1 , 55]
        -> sort arr -> [-1, 1, 55]
        -> reverse arr -> [55, 1, -1]
  return = ['One']
Response:
```python
def by_length(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: Implement the function f that takes n as a parameter,
and returns a list of size n, such that 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.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
Example:
f(5) == [1, 2, 6, 24, 15]
Response:
```python
def f(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 a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.

Example 1:

    Input: 3
    Output: (1, 2)
    Explanation:
    Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.

Example 2:

    Input: 12
    Output: (4, 6)
    Explanation:
    Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.

Note:
    1. 1 <= n <= 10^3
    2. returned tuple has the number of even and odd integer palindromes respectively.
Response:
```python
def even_odd_palindrome(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: Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3.
>>> count_nums([]) == 0
>>> count_nums([-1, 11, -11]) == 1
>>> count_nums([1, 1, 2]) == 3
Response:
```python
def count_nums(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: We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
    You are allowed to perform right shift operation any number of times.

One right shift operation means shifting all elements of the array by one
position in the right direction. The last element of the array will be moved to
the starting position in the array i.e. 0th index.

If it is possible to obtain the sorted array by performing the above operation
then return True else return False.
If the given array is empty then return True.

Note: The given list is guaranteed to have unique elements.

For Example:

move_one_ball([3, 4, 5, 1, 2])==>True
Explanation: By performin 2 right shift operations, non-decreasing order can
             be achieved for the given array.
move_one_ball([3, 5, 4, 1, 2])==>False
Explanation:It is not possible to get non-decreasing order for the given
            array by performing any number of right shift operations.
Response:
```python
def move_one_ball(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: In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange elements between the lst1 and lst2 to make
all the elements of lst1 to be even, return "YES".
Otherwise, return "NO".
For example:
exchange([1, 2, 3, 4], [1, 2, 3, 4]) => "YES"
exchange([1, 2, 3, 4], [1, 5, 3, 4]) => "NO"
It is assumed that the input lists will be non-empty.
Response:
```python
def exchange(lst1, lst2):


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 string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.

Example:
histogram('a b c') == {'a': 1, 'b': 1, 'c': 1}
histogram('a b b a') == {'a': 2, 'b': 2}
histogram('a b c a b') == {'a': 2, 'b': 2}
histogram('b b b b a') == {'b': 4}
histogram('') == {}
Response:
```python
def histogram(test):