Since you want to iterate in an unusual way, a generator is a good way to abstract that:

def chunks(s, n):
    """Produce `n`-character chunks from `s`."""
    for start in range(0, len(s), n):
        yield s[start:start+n]

nums = "1.012345e0070.123414e-004-0.1234567891.21423"
for chunk in chunks(nums, 12):
    print chunk

produces:

1.012345e007
0.123414e-00
4-0.12345678
91.21423

(which doesn't look right, but those are the 12-char chunks)

Answer from Ned Batchelder on Stack Overflow
🌐
EyeHunts
tutorial.eyehunts.com β€Ί home β€Ί python split string by character count | example code
Python split string by character count | Example code
March 7, 2023 - string = 'ABC XYZ PQRS' n = 3 # every 3 characters count res = [string[i:i + n] for i in range(0, len(string), n)] print(res) ... a_string = "abcde" res = [] n = 2 for index in range(0, len(a_string), n): res.append(a_string[index: index + n]) print(res) ... Do comment if you have any doubts or suggestions on this Pytho string split topic. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Discussions

How can I split a string in Python after a specific character count? - Stack Overflow
I apologize if this is a duplicate but I can't seem to find anything out there that involves splitting a string based on a character count. For example, let's say I have the following string: Lorem More on stackoverflow.com
🌐 stackoverflow.com
python - How to split a long string based on character count - Stack Overflow
As an example: if the character count is set to 100 the string containing a long paragraph should be split in to several lines with a max limit of 100. Lines should not contain incomplete words (if the line contains part of the word it should move to the next line). I can split the string but I can't think of handling incomplete words (words are set of characters separated from space). Finally, those lines should be returned as a list. ... Use the tool fmt or the Python ... More on stackoverflow.com
🌐 stackoverflow.com
Example of Character Count in a String
Example of Character Count in a String. #code: input_string = "programming" ip = " ".join(input_string).split() char_count = {} for i in input_string: if i not in char_count: char_count[i] = 1 else: char_count[i]+=1 print(char_count) #Output: {β€˜p’: 1, β€˜r’: 2, β€˜o’: 1, β€˜g’: 2, ... More on discuss.python.org
🌐 discuss.python.org
2
0
January 9, 2024
How does `split()` work?
Question: As per this lesson, we are trying to break apart a word to determine the number of times a sequence of characters is present. One method to solve this is using the .split() method, which I’ll explain below. Solution: If you check the documentation here, we can learn a bit about ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
2
August 19, 2019
🌐
TechBeamers
techbeamers.com β€Ί python-string-splitting
Python String Split and More - TechBeamers
November 30, 2025 - In this example, the function str_split_by_count takes the input string and passes the desired character count. It initializes an empty list (result) and a variable (cur_pos) to keep track of the current position in the string.
🌐
tutorialpedia
tutorialpedia.org β€Ί blog β€Ί split-string-by-count-of-characters
How to Split a String by Character Count Without Delimiters in Python: A Step-by-Step Guide β€” tutorialpedia.org
Use range(0, len(string), n) to generate starting indices for each chunk (step = n). For each index i, extract the substring string[i:i+n] (from i to i+n; if i+n exceeds the string length, slicing safely returns the remaining characters). def ...
Top answer
1 of 2
4

Here is an example for using the textwrap library:

import textwrap

text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
lines = textwrap.wrap(text, width=100)
print('\n'.join(lines))

Output:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.

The method textwrap comes with many additional keyword arguments. Have a look into the documentation for more information.

2 of 2
2

First, split all text into words:

words = [w for w in text.split(' ') if w]

Then loop through the words and add them one by one to the new string, until it's length not breaks the limit. In the case add the string to the list of results and start to create the next string.

MAX_LENGTH = 100

results = []
r = ''

for w in words:
    if len(r) + len(w) + 1 > MAX_LENGTH:
        results.append(r)
        r = ''
    r += '{}{}'.format(' ' if r else '', w)

print results
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί string_split.htm
Python String split() Method
The Python String split() method splits all the words in a string separated by a specified separator. This separator is a delimiter string, and can be a comma, full-stop, space character or any other character used to separate strings.
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_string_split.asp
Python String split() Method
Remove List Duplicates Reverse a String Add Two Numbers Β· Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The split() method splits a string into a list.
🌐
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 - 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.
🌐
Python.org
discuss.python.org β€Ί python help
Example of Character Count in a String - Python Help - Discussions on Python.org
January 9, 2024 - Example of Character Count in a String. #code: input_string = "programming" ip = " ".join(input_string).split() char_count = {} for i in input_string: if i not in char_count: char_count[i] = 1 else: char_count[i]+=1 print(char_count) #Output: {β€˜p’: 1, β€˜r’: 2, β€˜o’: 1, β€˜g’: 2, β€˜a’: 1, β€˜m’: 2, β€˜i’: 1, β€˜n’: 1}
🌐
Finxter
blog.finxter.com β€Ί home β€Ί learn python blog β€Ί python | split string and count results
Python | Split String and Count Results - Be on the Right Side of Change
December 2, 2022 - All you have to do is split the string using the split() function and then use the len method upon the resultant list returned by the split method to get the number of split strings present.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-split-string-in-groups-of-n-consecutive-characters
Python | Split string in groups of n consecutive characters - GeeksforGeeks
March 23, 2023 - The simplest way to do is by using a loop and split().Using Loop and split()In this method, we'll iterate through each word in the list using for loop and split it based on given K character using spli
🌐
Codecademy Forums
discuss.codecademy.com β€Ί frequently asked questions β€Ί python faq
How does `split()` work? - Python FAQ - Codecademy Forums
August 19, 2019 - Question: As per this lesson, we are trying to break apart a word to determine the number of times a sequence of characters is present. One method to solve this is using the .split() method, which I’ll explain below. Solution: If you check ...
🌐
Python Examples
pythonexamples.org β€Ί python-split-string-into-specific-length-chunks
Split String into Specific Length Chunks - 3 Python Examples
In this example we will split a string into chunks of length 4. Also, we have taken a string such that its length is not exactly divisible by chunk length. In that case, the last chunk contains characters whose count is less than the chunk size we provided. str = 'Welcome to Python Examples' n = 4 chunks = [str[i:i+n] for i in range(0, len(str), n)] print(chunks)
🌐
Python Basics
pythonbasics.org β€Ί home β€Ί python basics β€Ί python string split() method
Python String split() Method - pythonbasics.org
Given a sentence, the string can be split into words. If you have a paragraph, you can split by phrase. If you have a word, you can split it into individual characters. In most cases, the split() method will do. For characters, you can use the list method. Practice now: Test your Python skills ...
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί split words and count characters at each position
r/learnpython on Reddit: Split Words and Count Characters at Each Position
August 23, 2023 -

I have a list of 5 letter words (Wordle) and I'm trying to find the most frequent character at each of the 5 positions.

The goal is to be able to see at the 5th position, T is the most frequent letter with 40 occurrences, R is next with 38, etc. Ideally the output would be something like the example below that I manually did in Excel.

I want to learn how to do this programmatically but I'm not sure how to get started. Would I use pandas to import and manipulate the data and then count it somehow? I currently have this in an excel or csv file.

If you can point me in the right direction I would appreciate it. Thank you!

Letter	First	Second	Third	Fourth	Fifth
A	44	81	85	45	19
B	45	3	12	4	3
C	54	10	14	31	11
D	21	3	20	15	32
E	20	52	48	77	120
F	35	0	5	8	7
G	28	7	18	23	9
H	23	48	4	8	30
I	13	41	62	42	3
J	4	1	1	0	0
K	8	3	5	17	30
L	22	60	22	39	36
M	32	10	11	22	10
N	8	32	38	44	22
O	5	83	76	30	21
P	32	14	19	11	17
Q	6	3	0	0	0
R	23	64	42	50	53
S	84	5	14	42	9
T	43	23	27	41	75
U	14	35	40	22	2
V	10	3	12	14	0
W	22	10	6	5	6
X	0	6	2	2	2
Y	3	3	14	1	81
Z	1	0	3	7	2
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-split-string-into-list-of-characters
Split String into List of characters in Python - GeeksforGeeks
Explanation: This code splits the string s = "hello" into a list of characters by iterating through each character and appending it to the list a. ... Python Tutorial Ҁ“ Python is one of the most popular programming languages. ItҀ™s simple to use, packed with features and supported ...
Published: April 19, 2025
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-string-split
Python split() Method - GeeksforGeeks
July 1, 2026 - It returns the resulting parts as a list of strings. ... Explanation: s.split(',') splits the string s at every comma and returns a list of the parts ['one', 'two', 'three'].