Splitting a list in half results in two smaller lists containing elements from the original in the same order. For example, splitting
[1, 2, 3, 4] in half results in
[1, 2] and
iterable as a list to find its length.
Floor divide the length by
2 using the
// operator to find the
middle_index of the list.
Use the slicing syntax
list[:middle_index] to get the first half of the list and
list[middle_index:] to get the second half of the list.
[1, 2, 3, 4]
length = len(a_list)
middle_index = length//2
Floor division rounds down
first_half = a_list[:middle_index]
Slice first half
second_half = a_list[middle_index:]
Slice second half