How to get every nth element from a list in Python

Getting every nth element from a list returns all elements whose indices are multiples of n, starting with index 0. For example, getting every 2nd element from [0, 1, 2, 3] results in [0, 2].

Solution for How to get every nth element from a list in Python : You can use extended slicing to get every nth element from a list Use the extended slicing syntax list[start:stop:step] to get a new list containing every nth element. Leave start and stop empty, and set step to the desired n.


how-to-get-every-nth-element-from-a-list-in-python