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.
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.
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.
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.
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.
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.