Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

loop only to the 6th element python

import itertools
for s in itertools.islice(sample,None,None,n):
    print(s)
Comment

PREVIOUS NEXT
Code Example
Python :: pip install rejson 
Python :: gizeh python 
Python :: how to read json file from s3 bucket into aws glue job 
Python :: python copy dictionary keep original same 
Python :: 1038 solution python 
Python :: replace substrings to float 
Python :: numpy prod 
Python :: TypeError: get() takes 1 positional argument but 2 were given 
Python :: ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’ meaning in resample 
Python :: input character in python like getchar in c 
Python :: 2 liste to a dictionary 
Python :: exterat pdf python 
Python :: /var/www/html/flag 
Python :: plotly garden wing map 
Python :: How split() works when maxsplit is specified 
Python :: how to open Website from CMD using python 
Python :: Iterate over several iterables in parallel 
Python :: split dataset folders in train test valid using python 
Python :: how to check columns with the numerical values 
Python :: login() takes 1 positional argument but 2 were given 
Python :: web parser python 
Python :: getroot xml python 
Python :: Python List Note 
Python :: pandas merge keep one of column copy 
Python :: assert isinstance python 
Python :: Power Without BuiltIn Function 
Python :: increase tkinter window resolution 
Python :: Source Code: Check Armstrong number of n digits 
Python :: clustermap subplots 
Python :: 56.5 to 57 in python 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =