Answers for "loop only to the 6th element python"

0

loop only to the 6th element python

sample = "This is a string"
n = 3 # I want to iterate over every third element
for i,x in enumerate(sample):
    if i % n == 0:
        print("do something with x "+x)
    else:
        print("do something else with x "+x)
Posted by: Guest on July-19-2021
0

loop only to the 6th element python

import itertools
for s in itertools.islice(sample,None,None,n):
    print(s)
Posted by: Guest on July-19-2021

Code answers related to "loop only to the 6th element python"

Python Answers by Framework

Browse Popular Code Answers by Language