"""
Given a list, swap every two adjacent elements.
For example, [1, 2.5, 11, 4, 0.5] becomes [2.5, 1, 4, 11, 0.5].
"""

# 1.(a) Using a new list to store swapped elements
l = [1, 2.5, 11, 4, 0.5]
l_swap_adjacent = []
i = 0

# Iterate through the list in steps of 2 and swap adjacent elements
while (i + 1) < len(l):
    # Append the second element first
    l_swap_adjacent.append(l[i + 1])
    # Then append the first element
    l_swap_adjacent.append(l[i])
    # Move to the next pair of elements
    i += 2

# If the list has an odd number of elements, add the last element as is
if len(l) % 2 == 1:
    l_swap_adjacent.append(l[len(l) - 1])

# Output the swapped list
print(f"1.(a) {l_swap_adjacent}")

# 1.(b) In-place swap without creating a new list
l = [1, 2.5, 11, 4, 0.5]
i = 0

# Iterate through the list in steps of 2 and swap adjacent elements in-place
while (i + 1) < len(l):
    # Store the first element temporarily
    tmp = l[i]
    # Replace the first element with the second
    l[i] = l[i + 1]
    # Replace the second element with the stored first element
    l[i + 1] = tmp
    # Move to the next pair of elements
    i += 2

# Output the modified list
print(f"1.(b) {l}")
