Exclude every nth element from list?

BartC bc at freeuk.com
Sat Mar 26 13:50:03 EDT 2016


On 26/03/2016 16:49, beliavsky at aol.com wrote:
> I can use x[::n] to select every nth element of a list.

I would use x[n-1::n] if 'nth' means the 3rd element of 
[10,20,30,40,...] is 30. Otherwise every selection will include the 
first, no matter what n is.

-- 
Bartc





More information about the Python-list mailing list