A = [1,2,3,4,5,6]
B = A[:len(A)//2]
C = A[len(A)//2:]

If you want a function:

def split_list(a_list):
    half = len(a_list)//2
    return a_list[:half], a_list[half:]

A = [1,2,3,4,5,6]
B, C = split_list(A)
Answer from Jason Coon on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ splitting an array into two and swapping the first half with the second half
r/learnpython on Reddit: Splitting an Array into two and Swapping the First Half With the Second Half
May 18, 2020 -

Here's the algorithm:

array = [int(num) for num in input().split()]
len = len(array)

mid=int(len/2)

if mid%2==0:
    for i in range(mid):
        temp=array[i]
        array[i]=array[mid+i]
        array[mid + i]=temp
else:
    for i in range(mid):
        temp=array[i]
        array[i]=array[mid+i+1]
        array[mid + i + 1]=temp

print(array)

The issue is, the program has to decide between two loops depending on the length of the array (odd or even), which I think is very inefficient. Can someone suggest a way to bring this down to a single loop?

Sample I/O for even:

1 2 3 4 5 6 7 8
[5, 6, 7, 8, 1, 2, 3, 4]

Sample I/O for odd:

1 2 3 4 5 6 7 
[5, 6, 7, 4, 1, 2, 3]
Discussions

python - separate an array into two halves - Stack Overflow
I like to split an array into first half and its second half. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How can I split a Python list in half? - Ask a Question - TestMu AI (formerly LambdaTest) Community
How can I split a Python list in half? For example, if I have the list: A = [0, 1, 2, 3, 4, 5] I want to split it into two smaller lists: B = [0, 1, 2] C = [3, 4, 5] What is the best way to achieve this in Python? More on community.testmuai.com
๐ŸŒ community.testmuai.com
0
January 20, 2025
Split array Python - Stack Overflow
Not splitting the array into half. Btw I got the answer. Thanks for the comment. ... Your welcome, the article was specifically about splitting in half but you can use the implementation for your purposes :) ... Sign up to request clarification or add additional context in comments. ... should do it, assuming list1 is a standard python ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - What is the most efficient way to split a list evenly in half - Stack Overflow
I need to split a list into halves such that if it has an odd length the middle element is ignored entirely, I have a function for this, but it's quite slow for what I'm trying to do. My function (variables renamed because they make no sense out of context): Copydef splitList(array): half = ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-split-a-list-into-two-halves
Python Program to Split a List into Two Halves - GeeksforGeeks
July 23, 2025 - For working with numeric data or using the numpy library, numpy.array_split() provides a clean way to split lists (or arrays) into two or more parts. This function automatically handles splitting the list and is efficient for large datasets.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_split.asp
NumPy Splitting Array
Use the array_split() method, pass in the array you want to split and the number of splits you want to do.
๐ŸŒ
pythoncodelab
pythoncodelab.com โ€บ home โ€บ how to split a list in half python
How to split a list in half Python - - pythoncodelab
November 2, 2024 - We have NumPy inbuilt function which helps to split the list into half. You have to first install NumPy by running the following command โ€œpip install numpyโ€ in the command prompt. Now letโ€™s explore the code. import numpy as np def split_list_into_approx_equal_parts(lst, parts=2): return np.array_split(lst, parts) my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] parts_np = split_list_into_approx_equal_parts(my_list, parts=2) print("Parts (numpy array_split):", parts_np)
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ split list in half in python
How to Split Python List in Half | Delft Stack
February 2, 2024 - def split_list(a_list): half = len(a_list) // 2 return a_list[:half], a_list[half:] A = ["a", "b", "c", "d", "e", "f"] B, C = split_list(A) print(B) print(C) ... We created a function split_list that returns two halves of an existing list.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-program-to-split-a-list-into-two-halves
Python Program to Split a List into Two Halves
April 21, 2023 - The most straightforward method to split a list is using Python's slicing technique. This approach divides the list at a specific index, creating two separate parts. When a list has an even number of elements, splitting results in two equal halves ?
Find elsewhere
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third-party โ€บ numpy โ€บ split
Python Numpy split() - Divide Array | Vultr Docs
January 1, 2025 - In this article, you will learn how to effectively use the split() function to divide arrays into sub-arrays of equal or defined sizes.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.split.html
numpy.split โ€” NumPy v2.5 Manual
If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If such a split is not possible, an error is raised.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python lists โ€บ python: split a list (in half, in chunks)
Python: Split a List (In Half, in Chunks) โ€ข datagy
December 30, 2022 - This function allows you to split an array into a set number of arrays. Letโ€™s see how we can use NumPy to split our list into 3 separate chunks: # Split a Python List into Chunks using numpy import numpy as np a_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] our_array = np.array(a_list) chunked_arrays = np.array_split(our_array, 3) chunked_list = [list(array) for array in chunked_arrays] print(chunked_list) # Returns: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
๐ŸŒ
TestMu AI Community
community.testmuai.com โ€บ ask a question
How can I split a Python list in half? - Ask a Question - TestMu AI (formerly LambdaTest) Community
January 20, 2025 - How can I split a Python list in half? For example, if I have the list: A = [0, 1, 2, 3, 4, 5] I want to split it into two smaller lists: B = [0, 1, 2] C = [3, 4, 5] What is the best way to achieve this in Python?
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ splitting-arrays-in-numpy
Splitting Arrays in NumPy - GeeksforGeeks
December 23, 2025 - Explanation: Array shape is (2, 3, 4) and dsplit(..., 2) splits last axis into 2 equal parts. Each result contains half of the last dimension
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.split.html
numpy.split โ€” NumPy v2.6.dev0 Manual
If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If such a split is not possible, an error is raised.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-split-list
How to Split Lists in Python: Basic and Advanced Methods | DataCamp
June 21, 2024 - import numpy as np my_list = [1, ... np.int32(12), np.int32(13), np.int32(14), np.int32(15)]] One can use slicing to split Python list into half....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-program-for-split-the-array-and-add-the-first-part-to-the-end
Python Program to Split the array and add the first part to the end | GeeksforGeeks
March 28, 2023 - Use a list comprehension to create a new list result of the same length as the input array, where each element of the new list is computed using the formula (i + n) % arr_len where i is the index of the current element in the input array. Return the new list result. ... def split_and_add(arr, n): return [arr[(i + n) % len(arr)] for i in range(len(arr))] arr = [12, 10, 5, 6, 52, 36] n = 2 result = split_and_add(arr, n) print(*result)
๐ŸŒ
Kanoki
kanoki.org โ€บ 2020 โ€บ 06 โ€บ 11 โ€บ how-to-split-numpy-arrays
How to split Numpy Arrays | kanoki
June 11, 2020 - In this post we will see how to split a 2D numpy array using split, array_split , hsplit, vsplit and dsplit.
๐ŸŒ
Real Python
realpython.com โ€บ how-to-split-a-python-list-into-chunks
How to Split a Python List or Iterable Into Chunks โ€“ Real Python
January 27, 2025 - If your data is strictly numeric, then you can try leveraging one of the functions provided by the esteemed NumPy library to split a sequence of numbers into chunks. Thanks to its unmatched speed, NumPy is well suited to all kinds of number crunching, which would otherwise run significantly slower when implemented in pure Python. ... This scientific library comes with several array-splitting functions, which you can use to divide an array into smaller parts.