Skip to main content

Splits a list into sublists based on either a list of indices or a number of sections.

Project description

Splits a list into sublists based on either a list of indices or a number of sections.

Tested against Windows / Python 3.11 / Anaconda

pip install splitlistatindex

from splitlistatindex import list_split
l1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l2 = [3, 5, 7, 8, 12]

# Split `l1` using a list of indices
result1 = list_split(l=l1, indices_or_sections=l2)
# result1 will be: [[0, 1, 2], [3, 4], [5, 6], [7], [8, 9]]

# Split `l1` into 3 sections
result2 = list_split(l=l1, indices_or_sections=3)
# result2 will be: [[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

splitlistatindex-0.10.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

splitlistatindex-0.10-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page