петля только до 6 -го элемента Python
import itertools
for s in itertools.islice(sample,None,None,n):
print(s)
Doubtful Dotterel
import itertools
for s in itertools.islice(sample,None,None,n):
print(s)
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)