You can add the desired output to your existing for loop in the same way you print your sequences while re-using your loop variable i. To start with Sequence 1: , instead of Sequence 0: you can add i + 1 to the print statement.


for i in range(N):
    print(f'Sequence {i + 1}:')
    print(randseq("ATCG", 120))

More information regarding print can be found here. More information to format strings can be found here.

Answer from marcel h on Stack Overflow
🌐
Mathspp
mathspp.com › blog › pydonts › sequence-indexing
Sequence indexing | Pydon't 🐍 | mathspp
Sequences in Python, like strings, lists, and tuples, are objects that support indexing: a fairly simple operation that we can use to access specific elements.
🌐
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 ...
🌐
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - In Python, indexing refers to the process of accessing a specific element in a sequence, such as a string or list, using its position or index number. Indexing in Python starts at 0, which means that the first element in a sequence has an index of 0, the second element has an index of 1, and so on.
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - In Python, indexing starts from 0, which means the first element in a sequence is at position 0, the second element is at position 1, and so on.
🌐
Towards Data Science
towardsdatascience.com › home › latest › mastering indexing and slicing in python
Mastering Indexing and Slicing in Python | Towards Data Science
January 19, 2025 - Slicing is one form of indexing that allows us to infer an entire (sub)section of the original sequence rather than just a single item. To perform a slicing over a sequence in Python, you need to provide two offsets separated by a colon although in some cases you can define just one of the two, or even none (more on these cases are discussed below).
🌐
University of Toronto
teach.cs.toronto.edu › ~csc110y › fall › notes › 12-interlude-nifty-python-features › 01-sequences-revisited.html
12.1 Sequences Revisited: Ranges, Indexing, and Slicing
Given any sequence Python data type (e.g., str, list, tuple), we know that we can use indexing to access an element by index in the sequence:
🌐
Mimo
mimo.org › glossary › python › index-element
Python Index: Efficient Data Retrieval and Navigation
In Python, an index is the numbered position of an element inside a sequence like a list, string, or a tuple.
Find elsewhere
Top answer
1 of 2
21

With a list comprehension:

>>> [(i, i+len(b)) for i in range(len(a)) if a[i:i+len(b)] == b]
[(3, 6)]

Or with a for-loop:

>>> indexes = []
>>> for i in range(len(a)):
...    if a[i:i+len(b)] == b:
...        indexes.append((i, i+len(b)))
... 
>>> indexes
[(3, 6)]
2 of 2
4

Also, for efficiency, you can use KMP algorithm that is used in string matching (from here):

def KMPSearch(pat, txt): 
    M = len(pat) 
    N = len(txt) 

    # create lps[] that will hold the longest prefix suffix  
    # values for pattern 
    lps = [0]*M 
    j = 0 # index for pat[] 

    # Preprocess the pattern (calculate lps[] array) 
    computeLPSArray(pat, M, lps) 

    i = 0 # index for txt[] 
    while i < N: 
        if pat[j] == txt[i]: 
            i += 1
            j += 1

        if j == M: 
            print("Found pattern at index " + str(i-j))
            j = lps[j-1] 

        # mismatch after j matches 
        elif i < N and pat[j] != txt[i]: 
            # Do not match lps[0..lps[j-1]] characters, 
            # they will match anyway 
            if j != 0: 
                j = lps[j-1] 
            else: 
                i += 1

def computeLPSArray(pat, M, lps): 
    len = 0 # length of the previous longest prefix suffix 

    lps[0] # lps[0] is always 0 
    i = 1

    # the loop calculates lps[i] for i = 1 to M-1 
    while i < M: 
        if pat[i]== pat[len]: 
            len += 1
            lps[i] = len
            i += 1
        else: 
            # This is tricky. Consider the example. 
            # AAACAAAA and i = 7. The idea is similar  
            # to search step. 
            if len != 0: 
                len = lps[len-1] 

                # Also, note that we do not increment i here 
            else: 
                lps[i] = 0
                i += 1

a = [2,3,5,2,5,6,7,2]
b = [2,5,6]
KMPSearch(b, a) 

This find the first index of the b in a. Hence, the range is the result of the search and its plus to the length of b.

🌐
TutorialsPoint
tutorialspoint.com › How-to-iterate-by-sequence-index-in-Python
Python - For Loops
February 26, 2020 - Python's list object is also an indexed sequence, and hence you can iterate over its items using a for loop.
🌐
Art of Problem Solving
artofproblemsolving.com › wiki › index.php › Sequence_(Python)
Sequence (Python) - AoPS Wiki
len(mySeq), short for length, returns the number of elements in the sequence mySeq. mySeq.index(x) returns the index of the first occurrence of x in mySeq. Note that if x isn't in mySeq index will return an error.
🌐
Oreate AI
oreateai.com › blog › concept-and-application-analysis-of-indexing-in-python-sequences › bb27ab87cd28e54e57153c6f0e90c853
Concept and Application Analysis of Indexing in Python Sequences - Oreate AI Blog
January 7, 2026 - The indexing system employs two complementary numbering methods: forward indexing and backward indexing. Forward indexing starts counting from the first element of the sequence with an initial value of 0, incrementally increasing thereafter.
🌐
Npblue
npblue.com › tech › python › indexing-and-slicing
Python Indexing and Slicing: Accessing Sequences the Pythonic Way
The syntax is compact and expressive, but the rules around stop values being exclusive and negative indices counting from the end cause confusion until they click. Once they do, you’ll use slicing constantly. Python uses zero-based indexing: the ...
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.7 documentation
Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys.
🌐
Real Python
realpython.com › ref › glossary › indexing
indexing | Python Glossary – Real Python
In Python, indexing is an operation that allows you to access individual items within a sequence, such as a list, tuple, or string, using integer indices and the syntax sequence[index].
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › indexing.html
[] (index operator) — Python Reference (The Right Way) 0.1 documentation
Since all sequences are ordered and indexed arrays of objects, each object stored in a sequence has it’s associated index number - positive one, zero indexed and starting from left, and the negative one starting at -1 from the right.
🌐
Pythonforall
pythonforall.com › python › DataTypes › dt_indexing
Python Data Types | PythonForAll
May 24, 2026 - We do this through two essential techniques: Indexing: Accessing a single specific item at a known position. Slicing: Accessing a range or subsection of items. Let us learn exactly how these systems work in Python!
🌐
CodeRivers
coderivers.org › blog › find-index-of-occurrence-python
Finding the Index of Occurrence in Python - CodeRivers
February 22, 2026 - In Python, indexing starts at 0. For example, in a list my_list = [10, 20, 30, 40], the element 10 has an index of 0, 20 has an index of 1, and so on. The index of occurrence refers to the position of a specific element within a sequence.
🌐
Real Python
realpython.com › python-sequences
Python Sequences: A Comprehensive Guide – Real Python
March 18, 2026 - The term sequence doesn’t refer ... that contains items arranged in order, and you can access each item using an integer index that represents its position in the sequence....
🌐
Medium
medium.com › @shilpasree209 › indexing-slicing-in-python-f45d9caed433
Indexing & Slicing in Python!!!. These 2 things are interesting terms… | by Shilpa Sreekumar | Medium
January 23, 2024 - These 2 things are interesting ... Henry & Co. on Unsplash · Indexing is a process or technique used to access the elements in a sequence using its position(index) in the sequence....