"""
Recommended Python Style Guide:
https://peps.python.org/pep-0008/#introduction
"""

"""
Reorder a list [e0, e1, ..., e(n-2), e(n-1)] as [e0, e(n-1), e1, e(n-2), ...].
For example, [1, 2, 33, 24, 15] becomes [1, 15, 2, 24, 33].
"""

# Original list
l = [1, 2, 33, 24, 15]
print(f"Original list = {l}")

i = 0
l_swap_symmetric = []

# The idea is to alternate between adding elements from the beginning and the end
while i < len(l) / 2:
    # Add element from the start of the list
    l_swap_symmetric.append(l[i])
    # Ensure we don't duplicate the middle element in case of an odd-length list
    if len(l) - i - 1 != i:
        # Add corresponding element from the end
        l_swap_symmetric.append(l[len(l) - i - 1])
    i += 1

# Output the modified list
print(f"l_swap_symmetric = {l_swap_symmetric}")


"""
# Alternative solution: modifying the list in-place (without creating a new list)
"""
l = [1, 2, 33, 24, 15]

# Iterate over every second index (starting from the first) to rearrange the list
for i in range(1, len(l), 2):
    # The idea is to take the last element and insert it in the correct place
    # Pop removes and returns the last element of the list
    last_element_to_place = l.pop()

    # Insert the popped element at the correct position
    l.insert(i, last_element_to_place)

# Output the modified list
print(f"l_swap_symmetric = {l_swap_symmetric}")
