s = 'long string that I want to split up'
indices = [0,5,12,17]
parts = [s[i:j] for i,j in zip(indices, indices[1:]+[None])]

returns

['long ', 'string ', 'that ', 'I want to split up']

which you can print using:

print '\n'.join(parts)

Another possibility (without copying indices) would be:

s = 'long string that I want to split up'
indices = [0,5,12,17]
indices.append(None)
parts = [s[indices[i]:indices[i+1]] for i in xrange(len(indices)-1)]
Answer from eumiro on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › how can i split a string at index?
r/learnpython on Reddit: How can i split a string at index?
December 15, 2018 -

I googled those ['python split string at index', 'python regex split string at index'], and i couldn't find what i wanted.

This is what i want:

Example 1:

number = '8471923'
values = ['8', '471', '923']

Example 2:

number = '7013'
values = ['7', '013']

EDIT: i tried this but it doesn't work.

number = '7013'
values = [number[:3], number[3:6], number[6:9]]
print(values)
# out: ['701', '3', '']

EDIT: I was trying to solve this kata and here is my final code, but guess what, i did it the other way around, i had to convert 'twenty' to 20, but i'm converting 20 to 'twenty' :D.

Anyway thanks all, this f'{number:_}'.split('_') solved my problem.

Discussions

How do I split a list every 2 indexes
https://stackoverflow.com/questions/8991506/iterate-an-iterator-by-chunks-of-n-in-python More on reddit.com
🌐 r/learnpython
3
1
August 2, 2022
How can i split a string at index?
So basically, all you need is to split a number by every 4th digit? number = '8471923' values = f"{int(number):_}".split('_') I'm exploiting the format-specification mini language here to separate the thousands by underscores, and then just split by them. EDIT: If you are using a Python version earlier than 3.6, you can use this instead: number = '8471923' values = "{:_}".format(int(number)).split('_') EDIT #2: Forgot that this needs number to be a numerical value. EDIT #3: Switched back to number being a string and just used int. More on reddit.com
🌐 r/learnpython
16
6
December 15, 2018
Using Split only on the first occurrence of a character?
Why not just split with (.) , grab the last two fields; contoso and com ...then join the two with a dot when you're all done? This covers FQDN that might have multiple subdomains too, fwiw. $var.Split(".")[-2,-1] -join "." #this gives you "contoso.com" More on reddit.com
🌐 r/PowerShell
14
7
May 22, 2015
Why does re.split cause first index to be empty string?
re.split splits by whatever it matches, if you want the groups returned, use find or findall. it matched "1a." and split around it, on the left of it is empty, and on the right the rest. More on reddit.com
🌐 r/learnpython
3
0
March 10, 2020
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-split
Python split() Method - GeeksforGeeks
July 1, 2026 - Explanation: s.split(',') splits the string s at every comma and returns a list of the parts ['one', 'two', 'three'].
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string. Get the characters from position 2 to position 5 (not included): b = "Hello, World!" ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
Learn how to index and slice strings in Python 3 with step-by-step examples. Master substring extraction, negative indexing, and slice notation.
🌐
ReqBin
reqbin.com › code › python › nxrhfweu › python-split-string-example
How do I split a string in Python?
December 20, 2022 - In some rare cases, you can split a Python string using the range operator [] to take a subrange of characters from the string. In this Python Split String example, we use the string.split() method to split the string into a list. Other splitting options are presented below, with detailed examples and a description of each.
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › string-split-method
Learn Python's String Split Method, Simplify Text Processing
Start your coding journey with Python. Learn basics, data types, control flow, and more ... 1. Split by Whitespace (Default): If you call .split() with no arguments, it splits the string by any sequence of whitespace (spaces, tabs, newlines) and discards empty strings.
🌐
CodeSignal
codesignal.com › learn › courses › string-manipulation-for-python-coders › lessons › mastering-text-analysis-with-python-splitting-and-joining-strings-like-a-pro
Mastering Text Analysis with Python: Splitting and Joining ...
sentence = "Welcome to Python programming." words = sentence.split() print(words) # prints: ['Welcome', 'to', 'Python', 'programming.'] The split() method divides the string at spaces. However, we can specify a different delimiter.
🌐
Enki
enki.com › post › how-to-split-strings-in-python
Enki | Blog - How to Split Strings in Python
In this snippet, we grab specific parts of unique_id using index ranges. Mastering the split() function in Python opens many avenues for text processing. From simple space-based splits to complex delimiter-based parsing, understanding these methods is key to effective data manipulation. Keep honing your skills with Enki to learn more Python tricks and techniques. Our interactive courses empower you to build engaging projects and make your coding journey enjoyable. ... Professional athletes ...
🌐
Vultr Docs
docs.vultr.com › python › standard library › str › split()
Python str split() - Split String
December 11, 2024 - By specifying 2 for maxsplit, the method splits the string only twice, resulting in three parts: ['Welcome', 'to', 'Python programming']. This technique is useful for separating only the initial segments of a string.
🌐
W3Schools
w3schools.com › python › ref_string_split.asp
Python String split() Method
Remove List Duplicates Reverse ... Syllabus Python Study Plan Python Interview Q&A Python Training ... The split() method splits a string into a list....
🌐
Quora
quora.com › How-do-I-split-an-input-string-in-Python-without-using-input-split
How to split an input string in Python without using input().split() - Quora
Answer (1 of 3): Assuming this is some nasty problem given to you in a course where you need to replicate the .split(…) method in some way. The most obvious way is to step through the characters of the input string, keeping track of where you are in the string - the enumerate function will ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
Split a String in Python (Delimiter, Line Breaks, Regex) | note.nkmk.me
May 4, 2025 - When a delimiter appears consecutively, the resulting list will include empty strings (''). Additionally, if the delimiter is at the beginning or end of the string, empty strings will also appear at those positions. s_hyphen = '-one--two-' print(s_hyphen.split('-')) # ['', 'one', '', 'two', ''] ... Since empty strings are considered falsy in Python, you can use a list comprehension to filter them out.
🌐
Finxter
blog.finxter.com › home › learn python blog › python | split string at position
Python | Split String at Position - Be on the Right Side of Change
October 28, 2022 - Summary: You can split a given string at a specific position/index using Python’s string–slicing syntax. Minimal Example: Problem Formulation 💬Problem: Given a string, how will you split the given string at any given position? Let’s have a look at a couple of examples that demonstrate ...
🌐
HackerNoon
hackernoon.com › how-to-split-string-every-nth-character-in-python
How to Split String Every Nth Character in Python | HackerNoon
May 31, 2024 - It can be tedious to loop through the string and extract substrings, one at a time. In this article, we will learn three simple ways to quickly split a string into substrings of N consecutive characters each. Let us say you have the following string in Python. ... Let us say you want to split it after every two characters. ... In this approach, we use list comprehension along with indexes to get a list of substrings.
🌐
Real Python
realpython.com › python-split-string
How to Split a String in Python – Real Python
October 22, 2025 - Therefore, Python provides a dedicated ... final index. The .splitlines() method splits a string at line boundaries, such as the newline characters (\n), carriage returns (\r), and some combinations like \r\n....
🌐
Rollbar
rollbar.com › home › how to fix the “list index out of range” error in python split()
Fix List Index Out of Range in Python | Rollbar
Python uses zero-based indexing, meaning that the first element has index 0, and since the list has only one element, accessing index 1 exceeds the valid range of indices and causes the IndexError to be raised.
Published: June 30, 2026
🌐
Index.dev
index.dev › blog › how-to-split-strings-in-python
5 Best Ways to Split a String in Python [+Examples]
Sometimes you have to split a string over many delimiter points. Python's split() method cannot directly handle this; nevertheless, the re module offers a workaround via re.split().
🌐
Reddit
reddit.com › r/learnpython › how do i split a list every 2 indexes
r/learnpython on Reddit: How do I split a list every 2 indexes
August 2, 2022 -

Hello I have a list of integers:

trackIndex = [0, 22, 23, 58, 59,79,80,100,101,122]

These serve as indexes for another list of strings from a text file and I only need to extract certain indexes.

strings = [ "sentence 1", "sentence 2","sentence 3","sentence 4"....]

How can I loop through trackIndex and split it every two indexes (i.e. [0,22], [23,58],[59,79],[80, 100], [101,122] and then take those to extract those indexes from the "strings list" and store it in a new list called "newList"?