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 Top answer 1 of 16
361
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)
2 of 16
109
A little more generic solution (you can specify the number of parts you want, not just split 'in half'):
def split_list(alist, wanted_parts=1):
length = len(alist)
return [ alist[i*length // wanted_parts: (i+1)*length // wanted_parts]
for i in range(wanted_parts) ]
A = [0,1,2,3,4,5,6,7,8,9]
print split_list(A, wanted_parts=1)
print split_list(A, wanted_parts=2)
print split_list(A, wanted_parts=8)
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
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): def splitList(array): half = ... More on stackoverflow.com
Splitting an Array into two and Swapping the First Half With the Second Half
So this problem could actually be solved without any loops at all, just by using array splicing, you may want to take a look at that. Also, I'm not 100% sure, but I think in your odd example the output isn't actually what you want, since the 4 is out of place More on reddit.com
Split list into smaller lists
There are likely some helper functions that make this possible in a line or two but it's almost 4am here so I'm drawing a blank. Doing it with a dumb loop is pretty simple though: def splitList(input, delim): # We'll return a list of lists outLists = [] # Read each item, if it's not the delimiter (e.g. "x") # add it to the current list. If it is the delimiter, # add the current list to the output and empty it. currentList = [] for item in input: if item == delim: if len(currentList) > 0: outLists.append(currentList) currentList = [] else: currentList.append(item) # If we get to the end and there are leftovers in the current # list, add them as well if len(currentList) > 0: outLists.append(currentList) return outLists You could call this like: splitList(your_list_above, "x") Might be some edge cases I'm not thinking of, maybe multiple delimiters in a row or something (?), didn't really test this but it should get you started Edit: Made a stupid mistake above but not going to fix it, should never use "input" as a variable, so call it something else, like "inputList" instead More on reddit.com
02:11
How To Split Any List Into Equally-Sized Chunks (Python Recipes) ...
02:14
Split list into smaller lists (split in half) - YouTube
04:01
Python : How do you split a list into evenly sized chunks? - YouTube
13:15
How to Divide Each Element in a List in Python - YouTube
01:11
PYTHON : Split list into smaller lists (split in half) - YouTube
04:36
How to split a list into evenly sized chunks in Python | Python ...
TutorialsPoint
tutorialspoint.com › article › python-program-to-split-a-list-into-two-halves
Python Program to Split a List into Two Halves
March 27, 2026 - 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 ?
AdamSmith.haus
adamsmith.haus › python › answers › how-to-split-a-list-in-half-in-python
How to split a list in half in Python - Adam Smith
Python answers, examples, and documentation
Finxter
blog.finxter.com › home › learn python blog › how to split a list in half in 5 ways
How to Split a List in Half in 5 Ways - Be on the Right Side of Change
July 15, 2022 - Above defines a function with one (1) argument (split_half(pop)). This function splits the list in half using the Right Shift Operator and returns the results as a Tuple with two (2) nested lists.
Finxter
blog.finxter.com › 5-best-ways-to-split-a-python-list-into-two-halves
5 Best Ways to Split a Python List into Two Halves – Be on the Right Side of Change
This method involves splitting a list into two halves by using slice notation. Slice notation in Python allows us to access a subset of a list with a start, stop, and step parameters. By calculating the midpoint of the list, we can easily create two new lists representing the two halves.
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]
Top answer 1 of 5
4
So this problem could actually be solved without any loops at all, just by using array splicing, you may want to take a look at that. Also, I'm not 100% sure, but I think in your odd example the output isn't actually what you want, since the 4 is out of place
2 of 5
3
array[len(array)//2:] + array[:len(array)//2] should do it without a need of any loops or branches.
GeeksforGeeks
geeksforgeeks.org › python-ways-to-spilt-the-list-by-some-value
How to Split the list by some value ? - GeeksforGeeks
December 18, 2024 - Method #1 : Using itemgetter ... Splitting a list into two halves is a common operation that can be useful in many cases, such as when dealing with large datasets or when performing specific algorithms (e.g., merge sort).
GeeksforGeeks
geeksforgeeks.org › python › how-to-split-lists-in-python
How to Split Lists in Python? - GeeksforGeeks
July 23, 2025 - Explanation: Slicing operator : is used to divide the list into two parts, with the first slice containing elements up to index 3 and the second slice starting from index 3. For situations where you need to split a list into chunks of equal ...