Answers for "python do something every x elements"

2

python extract every nth value from list

# Basic syntax:
new_list = your_list[start_index::spacing]

# Example usage using list slicing:
# Say you have the following list and want every third item
your_list = [0,1,2,3,4,5,6,7,8,9]
new_list = your_list[0::3]

print(new_list)
--> [0, 3, 6, 9]
Posted by: Guest on November-06-2020
1

get every nth element in list python

start_from = 0
every_nth = 2
a_list[start_from::every_nth]
Posted by: Guest on September-11-2020

Code answers related to "python do something every x elements"

Python Answers by Framework

Browse Popular Code Answers by Language