"""
Recommended Python Style Guide:
https://peps.python.org/pep-0008/#introduction
"""


def binary_search(values, item):
    """
    Performs a binary search to find the index of 'item' in a sorted list 'values'.

    Parameters:
    values (list): A sorted list of elements to search within.
    item (Any): The target value to search for in the list.

    Returns:
    int: The index of 'item' if found, otherwise -1.
    """
    # Initialize the starting (from_index) and ending (to_index) bounds for the search
    from_index = 0
    to_index = len(values)

    # Perform iterative search
    while from_index < to_index:
        # Calculate the middle index
        middle_index = (from_index + to_index) // 2

        # Check if the middle element is the target
        if values[middle_index] == item:
            return middle_index  # Found item, return index
        elif item < values[middle_index]:  # Target is in the left half
            to_index = middle_index
        else:  # Target is in the right half
            from_index = middle_index + 1

    return -1  # Item not found


# Sorted example list
numbers = sorted([1, 5, 6, 2, 8, 12, 5])
print('Example list:', numbers)

# Test cases
for v in numbers:
    print(f'binary_search({numbers}, {v}) =', binary_search(numbers, v))

# Test cases for values not in the list
print(f'binary_search({numbers}, 3) =', binary_search(numbers, 3))
print(f'binary_search({numbers}, 7) =', binary_search(numbers, 7))
print(f'binary_search({numbers}, 42) =', binary_search(numbers, 42))
