Here's a generator that yields evenly-sized chunks:

def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    for i in range(0, len(lst), n):
        yield lst[i:i + n]
import pprint
pprint.pprint(list(chunks(range(10, 75), 10)))
[[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
 [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
 [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
 [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
 [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
 [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
 [70, 71, 72, 73, 74]]

For Python 2, using xrange instead of range:

def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    for i in xrange(0, len(lst), n):
        yield lst[i:i + n]

Below is a list comprehension one-liner. The method above is preferable, though, since using named functions makes code easier to understand. For Python 3:

[lst[i:i + n] for i in range(0, len(lst), n)]

For Python 2:

[lst[i:i + n] for i in xrange(0, len(lst), n)]
Answer from Ned Batchelder on Stack Overflow
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ split-a-list-into-evenly-sized-parts
Here is how to split a list into evenly sized parts in Python
New: Practice Python, JavaScript & SQL with AI feedback โ€” Try ActiveSkill free โ†’ ร— ... # Define a list to split my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Define the size of the parts part_size = 3 # Use the range() function to create a list of the desired indices indices = range(0, len(my_list), part_size) # Use the enumerate() function to create pairs of (index, element) for each element in the list pairs = enumerate(my_list) # Use the zip() function to group the pairs of (index, element) by index parts = [list(group) for index, group in groupby(pairs, lambda x: x[0] // part_size)] # Print the resulting parts print(parts)
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ split-a-list-into-evenly-sized-chunks
Python Program to Split a List Into Evenly Sized Chunks | Vultr Docs
April 10, 2025 - This method demonstrates how to split a list into equal parts in Python using a straightforward loop-based technique.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ list-chunks
Python Program to Split a List Into Evenly Sized Chunks
To understand this example, you should have the knowledge of the following Python programming topics: ... def split(list_a, chunk_size): for i in range(0, len(list_a), chunk_size): yield list_a[i:i + chunk_size] chunk_size = 2 my_list = [1,2,3,4,5,6,7,8,9] print(list(split(my_list, chunk_size)))
๐ŸŒ
Medium
medium.com โ€บ ai-does-it-better โ€บ splitting-a-list-into-evenly-sized-chunks-in-python-a993786a6b6e
Splitting a List into Evenly Sized Chunks in Python | by Doug Creates | AI Does It Better | Medium
March 19, 2024 - It's a straightforward demonstration of how to divide a list into evenly sized chunks. ... # Python program to split a list into chunks of size n using list comprehension # Function to split list def split_list(lst, n): # Using list comprehension to split list return [lst[i:i + n] for i in range(0, len(lst), n)] # Example list example_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] # Desired chunk size chunk_size = 3 # Splitting the list chunks = split_list(example_list, chunk_size) # Printing the chunks print(chunks) # Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # This demonstrates how a list can be divided into smaller chunks of a specified size.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-do-you-split-a-list-into-evenly-sized-chunks-in-python
How do you split a list into evenly sized chunks in Python?
Yield is a Python keyword which is used to return from a function, where it does not forget its local states. When we want to have multiple returns (partial solutions) from a function without exiting the function and without losing its local states we use the yield keyword. The following is an example program to demonstrate the usage of yield keyword to split a list into evenly sized chunks in python ?
๐ŸŒ
Softhints
softhints.com โ€บ python-split-list-into-evenly-sized-lists
How to Split a List Into Evenly Sized Lists in Python
August 10, 2021 - One more option is to split lists in Python with zip. The solution seems to be a simple one as: my_list = list(range(15)) n = 3 list(zip(*[iter(my_list)]*n)) which will produce: [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14)] but in case of not evenly spread elements will produce unexpected results as: my_list = list(range(17)) n = 3 list(zip(*[iter(my_list)]*n)) result: [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11), (12, 13, 14)] By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
๐ŸŒ
Wordaligned
wordaligned.org โ€บ articles โ€บ slicing-a-list-evenly-with-python
Slicing a list evenly with Python
May 14, 2017 - def chunk(xs, n): '''Split the list, xs, into n evenly sized chunks''' L = len(xs) assert 0 < n <= L s, r = divmod(L, n) t = s + 1 return ([xs[p:p+t] for p in range(0, r*t, t)] + [xs[p:p+s] for p in range(r*t, L, s)])
Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python split a list into evenly sized chunks?
Python Split a list into evenly sized chunks? - Spark By {Examples}
May 31, 2024 - How to split a list into evenly-sized elements in Python? To split the list evenly use methods like slicing, zip(), iter(), numpy.array_split(), list
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-split-a-python-list-into-evenly-sized-chunks
How to split a Python list into evenly sized chunks - GeeksforGeeks
July 23, 2025 - import numpy as np def chunked_list(lst, chunk_size): return np.array_split(lst, np.ceil(len(lst) / chunk_size)) if __name__ == "__main__": lst = [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18] chunk_size = 4 chunks = chunked_list(lst, chunk_size) for chunk in chunks: print(chunk)
๐ŸŒ
Real Python
realpython.com โ€บ how-to-split-a-python-list-into-chunks
How to Split a Python List or Iterable Into Chunks โ€“ Real Python
July 23, 2026 - You associate each product with the corresponding sum by placing them in a Python dictionary, and then return the product with the smallest sum: ... In this case, the number of rows and columns that produce the most even chunks is four by four. You can now adapt your earlier split_n() function to turn such a tuple into slice objects:
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Program #57 - Split List Into Evenly Sized Chunks in Python - YouTube
Python Program #57 - Split List Into Evenly Sized Chunks in PythonIn this video by Programming for beginners we will see Python Program to Split a List Into ...
Published: June 30, 2023
๐ŸŒ
Codingem
codingem.com โ€บ home โ€บ python how to split a list to n chunks of even size
Python How to Split a List to N Chunks of Even Size
December 7, 2022 - To split a Python list into N equally sized chunks, determine the number of chunks and use a for loop to fill the chunks up.
Top answer
1 of 2
1

You can use:

np.array_split(list_of_users, NUMBER_OF_CLIENTS)

More in: Docs

2 of 2
0

DIY: Without external libraries

Here is one approach without external libraries. This implementation will assign an equal number of users to each client if possible. If not it will make sure the difference in number of users assigned to clients between clients is at max 1 (= my definition of fair). Additionally, it will make sure that additional users are not assigned to the same clients all the time, if you were to run this multiple times. It does this by randomly choosing the set of clients which will need to take on one of the remaining users (that could not be assigned to clients in equal parts). This ensures a fair allocation of users to clients.

It's a bit more code that I post, so here some high-level explanation:

The relevant function is called assign_users_to_clients(). This will do the job you intend to do. The two other functions verify_all_users_assigned() and print_mapping() are just utility functions for the sake of this demo. One will make sure the assignment is correct, i. e. users are assigned to exactly one client (no duplicate assignments, no unassigned users) and the other just prints the result a bit nicer so you can verify that the distribution of users to clients is actually fair.

import random


def verify_all_users_assigned(users, client_user_dict):
    """
    Verify that all users have indeed been assigned to a client.
    Not necessary for the algorithm but used to check whether the implementation is correct.
    :param users: list of all users that have to be assigned
    :param client_user_dict: assignment of users to clients
    :return:
    """
    users_assigned_to_clients = set()
    duplicate_users = list()

    for clients_for_users in client_user_dict.values():
        client_set = set(clients_for_users)
        # if there is an intersection those users have been assigned twice (at least)
        inter = users_assigned_to_clients.intersection(client_set)
        if len(inter) != 0:
            duplicate_users.extend(list(inter))
        # now make union of clients to know which clients have already been processed
        users_assigned_to_clients = users_assigned_to_clients.union(client_set)
    all_users = set(users)
    remaining_users = users_assigned_to_clients.difference(all_users)
    if len(remaining_users) != 0:
        print(f"Not all users have been assigned to clients. Missing are {remaining_users}")
        return
    if len(duplicate_users) != 0:
        print(f"Some users have been assigned at least twice. Those are {duplicate_users}")
        return
    print(f"All users have successfully been assigned to clients.")


def assign_users_to_clients(users, clients):
    """
    Assign users to clients.
    :param users: list of users
    :param clients: list of clients
    :return: dictionary with mapping from clients to users
    """
    users_per_client = len(users) // len(clients)
    remaining_clients = len(users) % len(clients)
    if remaining_clients != 0:
        print(
            f"An equal split is not possible! {remaining_clients} users would remain when each client takes on {users_per_client} users. Assigning remaining users to random clients.")

    # assign each client his fair share of users
    client_users = list()
    for i in range(0, len(users), users_per_client):
        # list of all clients for one user
        user_for_client = list()
        last_client = i + users_per_client
        # make sure we don't run out of bounds here
        if last_client > len(users):
            last_client = len(users)
        # run from current position (as determined by range()) to last client (as determined by the step value)
        # this will assign all users (that belong to the client's share of users) to one client
        for j in range(i, last_client):
            # assign user to client
            user_for_client.append(users[j])
        client_users.append(user_for_client)

    # Assign clients and users as determined above
    client_user_registry = {clients[i]: client_users[i] for i in range(len(clients))}
    # now we need to take care of the remaining clients
    # we could just go from back to front and assign one more user to each client but to make it fair, choose randomly without repetition
    start = users_per_client * len(clients)
    for i, client in enumerate(random.sample(clients, k=remaining_clients)):
        client_user_registry[client].append(users[start + i])
    return client_user_registry


def print_mapping(mapping):
    print("""
+-------------------------
| Mapping: User -> Client
+-------------------------""")
    for client, users in mapping.items():
        print(f" - Client: {client}\t =>\t Users ({len(users)}): {', '.join(users)}")


# users that need to be assigned
list_of_users = ["user_id1", "user_id2", "user_id3", "user_id4", "user_id5", "user_id6", "user_id7", "user_id8",
                 "user_id9", "user_id10", "user_id11",
                 "user_id12", "user_id13", "user_id14", "user_id15", "user_id16", "user_id17", "user_id18",
                 "user_id19",
                 "user_id20", "user_id21", "user_id22", "user_id23", "user_id24", "user_id25", "user_id26"]
# clients to assign users to
list_of_clients = ["client_1", "client_2", "client_3", "client_4", "client_5", "client_6", "client_7"]

# do assignment of users to clients
client_user_assignment = assign_users_to_clients(list_of_users, list_of_clients)

# verify that the algorithm works (just for demo purposes)
verify_all_users_assigned(list_of_users, client_user_assignment)

# print assignment
print_mapping(client_user_assignment)

Expected output

An equal split is not possible! 5 users would remain when each client takes on 3 users. Assigning remaining users to random clients.
All users have successfully been assigned to clients.

+-------------------------
| Mapping: User -> Client
+-------------------------
 - Client: client_1  =>  Users (4): user_id1, user_id2, user_id3, user_id23
 - Client: client_2  =>  Users (4): user_id4, user_id5, user_id6, user_id26
 - Client: client_3  =>  Users (3): user_id7, user_id8, user_id9
 - Client: client_4  =>  Users (3): user_id10, user_id11, user_id12
 - Client: client_5  =>  Users (4): user_id13, user_id14, user_id15, user_id24
 - Client: client_6  =>  Users (4): user_id16, user_id17, user_id18, user_id25
 - Client: client_7  =>  Users (4): user_id19, user_id20, user_id21, user_id22

Please note: as random.sample() chooses the clients that take on one more client randomly your result might differ, but it will always be fair (= see specification of fair above)

With external libraries

When using external libraries there are many options. See e.g. function pandas.cut() or numpy.split(). They will act differently when a fair distribution of users to clients is not possible so you should read on that in the documentation.

๐ŸŒ
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 - This function automatically handles splitting the list and is efficient for large datasets. Python ยท import numpy as np a = [1, 2, 3, 4, 5, 6] # Creates two sub-arrays, dividing the list evenly split_lst = np.array_split(a, 2) # Assign the first half to x x = split_lst[0] # Assign the second half to y y = split_lst[1] print(x) print(y) Output ยท
๐ŸŒ
Python Guides
pythonguides.com โ€บ split-a-python-list-into-evenly-sized-chunks
How To Split A Python List Into Evenly Sized Chunks?
March 19, 2025 - Let us get into the various methods and examples to split a Python list into chunks of equal size. ... One simple approach to split a list into evenly sized chunks is to use a loop along with Python list slicing.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-split-a-python-list-into-evenly-sized-chunks
How to split a Python list into evenly sized chunks
We can chunk the list into the given sizes using the islice method of the itertools module. Refer to What is itertools.islice() method in Python?
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-split-lists-in-python
How to Split Lists in Python? - GeeksforGeeks
July 23, 2025 - We can also use the numpy library for advanced operations. The array_split method in numpy allows splitting a list into a specified number of sublists, distributing elements as evenly as possible.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ how to split a python list into evenly sized chunks?
How to Split a Python List into Evenly Sized Chunks? - Intellipaat
February 3, 2026 - In Python, the array_split() function in NumPy is used to divide a large list into almost evenly sized chunks.