Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

list get every 2nd element

a_list = [0, 1, 2, 3]

n = 2
every_second_element = a_list[::n]
# Get every 2nd element of `a_list`

print(every_second_element)
# OUTPUT
# [0, 2]
Comment

PREVIOUS NEXT
Code Example
Python :: find next multiple of 5 python 
Python :: TypeError: Can only append a dict if ignore_index=True 
Python :: subprocess.popen no output 
Python :: remove column by index 
Python :: python cv2 canny overlay on image 
Python :: python series unique 
Python :: openpyxl read cell value 
Python :: try python 
Python :: numpy randn with a shape of another array 
Python :: pandas groupby and show specific column 
Python :: encryption using python 
Python :: Invalid comparison between dtype=datetime64[ns] and date filter 
Python :: kivy dropdown list 
Python :: python plot arrays from matrix 
Python :: .split python 
Python :: I have string index in pandas DataFrame how can I select by startswith? 
Python :: python webbrowser module 
Python :: User serializer in django rest framework 
Python :: how to username in python? 
Python :: how to vonvert 1 d list to 2d list in pytohn 
Python :: python community 
Python :: insert list python 
Python :: Python round to only two decimal 
Python :: python number of elements in list of lists 
Python :: serialization in django 
Python :: how to check how many digits string has in python 
Python :: python close gile 
Python :: groupby where only 
Python :: how to convert python to exe 
Python :: how to make a dice program in python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =