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: The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fibfib(0) == 0
fibfib(1) == 0
fibfib(2) == 1
fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
Please write a function to efficiently compute the n-th element of the fibfib number sequence.
>>> fibfib(1)
0
>>> fibfib(5)
4
>>> fibfib(8)
24
Response:
```python
def fibfib(n: int):


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 vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.

Example:
>>> vowels_count("abcde")
2
>>> vowels_count("ACEDY")
3
Response:
```python
FIX = """
Add more test cases.
"""

def vowels_count(s):
    """Write a function vowels_count which takes a string representing
    a word as input and returns the number of vowels in the string.
    Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
    vowel, but only when it is at the end of the given word.

    Example:
    >>> vowels_count("abcde")
    2
    >>> vowels_count("ACEDY")
    3
    """


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: Circular shift the digits of the integer x, shift the digits right by shift
and return the result as a string.
If shift > number of digits, return digits reversed.
>>> circular_shift(12, 1)
"21"
>>> circular_shift(12, 2)
"12"
Response:
```python
def circular_shift(x, shift):


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: Task
Write a function that takes a string as input and returns the sum of the upper characters only'
ASCII codes.

Examples:
    digitSum("") => 0
    digitSum("abAB") => 131
    digitSum("abcCd") => 67
    digitSum("helloE") => 69
    digitSum("woArBld") => 131
    digitSum("aAaaaXa") => 153
Response:
```python
def digitSum(s):


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 task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the oranges and apples and an integer that represent the total number of the fruits
in the basket return the number of the mango fruits in the basket.
for examble:
fruit_distribution("5 apples and 6 oranges", 19) ->19 - 5 - 6 = 8
fruit_distribution("0 apples and 1 oranges",3) -> 3 - 0 - 1 = 2
fruit_distribution("2 apples and 3 oranges", 100) -> 100 - 2 - 3 = 95
fruit_distribution("100 apples and 1 oranges",120) -> 120 - 100 - 1 = 19
Response:
```python
def fruit_distribution(s,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 an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the same smallest even value are found return the node that has smallest index.

The plucked node should be returned in a list, [ smalest_value, its index ],
If there are no even values or the given array is empty, return [].

Example 1:
    Input: [4,2,3]
    Output: [2, 1]
    Explanation: 2 has the smallest even value, and 2 has the smallest index.

Example 2:
    Input: [1,2,3]
    Output: [2, 1]
    Explanation: 2 has the smallest even value, and 2 has the smallest index.

Example 3:
    Input: []
    Output: []

Example 4:
    Input: [5, 0, 3, 0, 4, 2]
    Output: [0, 1]
    Explanation: 0 is the smallest value, but  there are two zeros,
                 so we will choose the first zero, which has the smallest index.

Constraints:
    * 1 <= nodes.length <= 10000
    * 0 <= node.value
Response:
```python
def pluck(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: You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Examples:
    search([4, 1, 2, 2, 3, 1]) == 2
    search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
    search([5, 5, 4, 4, 4]) == -1
Response:
```python
def search(lst):