You can achieve this with Python's default package itertools.product.

import itertools

chars = "0123456789abcdefghijklmnopqrstuvwxyz"

n = 2
for i in xrange(1, n+1):
    for item in itertools.product(chars, repeat=i):
        print "".join(item)

Where n is the max number of characters.

The output will look like this.

0
1
2
...
y
z
00
01
02
...
Answer from Jaakko on Stack Overflow
🌐
Runestone Academy
runestone.academy › ns › books › published › py4e-int › strings › sequence.html
7.1. A string is a sequence — Python for Everybody - Interactive
A string is a sequence of characters. You can access the characters one at a time with the bracket operator: ... The second statement extracts the character at index position 1 from the fruit variable and assigns it to the letter variable. The expression in brackets is called an index.
Discussions

Sequence[str] - is this solution crazy?
You haven't really explained what problem you are trying to solve. Is it that you want to enforce that a function accepts a sequence that is not a string? If so, why, specifically? What is so different about strings compared to lists, tuples, dicts etc? More on reddit.com
🌐 r/learnpython
29
1
October 12, 2025
Question about Sequence[str]
I have a function like this def f(arg: Sequence[str]): if isinstance(arg, str): raise TypeError("arg should be a sequance of str, not str") for string in arg: print(string) If a str value is passed to this function, an error would raise. However, the IDE would not mark this as error. More on discuss.python.org
🌐 discuss.python.org
4
0
August 29, 2023
total stranger to python and dealing with invalid escape sequence...
You need an r prefix. (And you don't need the u on the other string.) return re.sub(r'[^\d.]', '', val) More on reddit.com
🌐 r/learnpython
17
3
April 18, 2024
PyLint: Error code for "invalid escape sequence" ?
Could it be W1401 - anomalous-backslash-in-string ? More on reddit.com
🌐 r/pythontips
1
2
November 10, 2023
🌐
Python.org
discuss.python.org › python help
What does Sequence[str] do in this program? - Python Help - Discussions on Python.org
June 7, 2023 - Hi. I uploaded arithmetic_arranger.py to my github repository. It’s for a freecodecamp test. I see Sequence[str] at line 54. Pycharm says they are both classes. I googled for info, found nothing. So, Sequence is act…
🌐
Fsu
ww2.cs.fsu.edu › ~nienaber › teaching › python › lectures › sequence-string.html
Sequences | Strings
P Traceback (most recent call last): File "test.py", line 4, in <module> print name[5] IndexError: string index out of range · The built in function len(sequence) returns the length of a sequence such as a string.
🌐
Kkiesling
kkiesling.github.io › python-novice-gapminder-custom › 05a-sequence-types
Plotting and Programming in Python: Sequence Types: Strings, Tuples and Lists
August 28, 2018 - For example, the string ‘AB’ is not the same as ‘BA’. Because of this ordering, we can give each item a number that is it’s position in the sequence.
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.7 documentation
The following table summarizes the text and binary sequence types methods by category. Textual data in Python is handled with str objects, or strings. Strings are immutable sequences of Unicode code points.
🌐
Python
docs.python.org › 2.4 › lib › typesseq.html
2.3.6 Sequence Types -- str, unicode, list, tuple, buffer, xrange
October 18, 2006 - There are six sequence types: strings, Unicode strings, lists, tuples, buffers, and xrange objects. String literals are written in single or double quotes: 'xyzzy', "frobozz". See chapter 2 of the Python Reference Manual for more about string literals. Unicode strings are much like strings, ...
Find elsewhere
🌐
TechVidvan
techvidvan.com › tutorials › python-strings
Python Strings - Get ready to work with sequence of characters - TechVidvan
August 22, 2024 - Python does not have arrays like C++ or Java. It has lists and strings. Lists are collections of values and are mutable. Strings are sequences of characters and are immutable.
🌐
Reddit
reddit.com › r/learnpython › sequence[str] - is this solution crazy?
r/learnpython on Reddit: Sequence[str] - is this solution crazy?
October 12, 2025 -

str is a Sequence[str] in Python -- a common footgun.

Here's the laziest solution I've found to this in my own projects. I want to know if it's too insane to introduce at work:

  1. Have ruff require the following import:

from useful_types import SequenceNotStr as Sequence

2. ...that's it.

You could avoid the useful_types dependency by writing the same SequenceNotStr protocol in your own module.

I plan to build up on this solution by writing a pre commit hook to allow this import to be unused (append the #noqa: F401 comment).

EDIT: https://github.com/python/typing/issues/256 for context if people don't know this issue.

🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module2_EssentialsOfPython › SequenceTypes.html
Sequence Types — Python Like You Mean It
Python allows you to retrieve individual members of a sequence by specifying the index of that member, which is the integer that uniquely identifies that member’s position in the sequence. Python implements 0-based indexing for its sequences, and also permits the use of negative integers to count from the end of the sequence. Consider the string "Python".
🌐
Python
docs.python.org › 2.0 › lib › typesseq.html
2.1.5 Sequence Types
There are six sequence types: strings, Unicode strings, lists, tuples, buffers, and xrange objects. Strings literals are written in single or double quotes: 'xyzzy', "frobozz". See chapter 2 of the Python Reference Manual for more about string literals. Unicode strings are much like strings, ...
🌐
Medium
pythonflood.com › python-sequences-weaving-the-story-of-order-and-logic-23dff398f83e
Python Sequences - Weaving the Story of Order and Logic. | by Rinu Gour | PythonFlood
July 11, 2023 - This will return a new string containing the characters from index 0 up to (but not including) index 5. As we saw earlier, you can access individual elements in a sequence using indexing. Indexing starts from 0 for the first element and goes up to the length of the sequence minus one. If you try to access an index that is out of bounds, Python will raise an IndexError.
🌐
Art of Problem Solving
artofproblemsolving.com › wiki › index.php › Sequence_(Python)
Sequence (Python) - AoPS Wiki
The elements of a list can be any ... like lists, but they are immutable - they can't be changed. Strings are a special type of sequence that can only store characters, and they have a special notation....
🌐
Python Geeks
pythongeeks.org › python geeks › learn python › sequences in python with types and examples
Sequences in Python with Types and Examples - Python Geeks
June 9, 2021 - tuple_1 = ("PythonGeeks", "Sequences", "Tutorial") # [all string tuple] tuple_1[2] = "Blog" print(tuple_1)
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python sequences
Python Sequences
March 27, 2025 - Python classifies sequence types as mutable and immutable. The mutable sequence types are lists and bytearrays while the immutable sequence types are strings, tuples, range, and bytes.
🌐
Compciv
2017.compciv.org › guide › cookbook › basic-sequences.html
Python Sequence Basics
The following snippet will result ... result tuple is empty: ... An iterable object is any kind of sequence. This includes strings, which are sequences of characters....
🌐
Python.org
discuss.python.org › python help
Question about Sequence[str] - Python Help - Discussions on Python.org
August 29, 2023 - I have a function like this def f(arg: Sequence[str]): if isinstance(arg, str): raise TypeError("arg should be a sequance of str, not str") for string in arg: print(string) If a str value is pas…
🌐
Wikibooks
en.wikibooks.org › wiki › Python_Programming › Sequences
Python Programming/Sequences - Wikibooks, open books for an open world
Sequences allow you to store multiple values in an organized and efficient fashion. There are seven sequence types: strings, bytes, lists, tuples, bytearrays, buffers, and range objects.