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: Return median of elements in the list l.
>>> median([3, 1, 2, 4, 5])
3
>>> median([-10, 4, 6, 1000, 10, 20])
15.0
Response:
```python
def median(l: list):


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: Checks if given string is a palindrome
>>> is_palindrome('')
True
>>> is_palindrome('aba')
True
>>> is_palindrome('aaaaa')
True
>>> is_palindrome('zbcd')
False
Response:
```python
def is_palindrome(text: str):


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: Return 2^n modulo p (be aware of numerics).
>>> modp(3, 5)
3
>>> modp(1101, 101)
2
>>> modp(0, 101)
1
>>> modp(3, 11)
8
>>> modp(100, 101)
1
Response:
```python
def modp(n: int, p: 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:  Takes as input string encoded with encode_shift function. Returns decoded string.
Response:
```python

def encode_shift(s: str):
    """
    returns encoded string by shifting every character by 5 in the alphabet.
    """
    return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s])

def decode_shift(s: str):
    """
    takes as input string encoded with encode_shift function. Returns decoded string.
    """


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: remove_vowels is a function that takes string and returns string without vowels.
>>> remove_vowels('')
''
>>> remove_vowels("abcdef\nghijklm")
'bcdf\nghjklm'
>>> remove_vowels('abcdef')
'bcdf'
>>> remove_vowels('aaaaa')
''
>>> remove_vowels('aaBAA')
'B'
>>> remove_vowels('zbcd')
'zbcd'
Response:
```python
def remove_vowels(text):


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: Return True if all numbers in the list l are below threshold t.
>>> below_threshold([1, 2, 4, 10], 100)
True
>>> below_threshold([1, 20, 4, 10], 5)
False
Response:
```python
def below_threshold(l: list, t: 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: Add two numbers x and y
>>> add(2, 3)
5
>>> add(5, 7)
12
Response:
```python
def add(x: int, y: 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: Check if two words have the same characters.
>>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')
True
>>> same_chars('abcd', 'dddddddabc')
True
>>> same_chars('dddddddabc', 'abcd')
True
>>> same_chars('eabcd', 'dddddddabc')
False
>>> same_chars('abcd', 'dddddddabce')
False
>>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')
False
Response:
```python
def same_chars(s0: str, s1: str):