On Saturday, March 26, 2016 at 1:02:06 PM UTC-4, Gary Herron wrote: > On 03/26/2016 09:49 AM, beliavsky--- via Python-list wrote: > > I can use x[::n] to select every nth element of a list. Is there a > > one-liner to get a list that excludes every nth element? > > Yes: > > >>> L=list(range(20)) > >>> [x for i,x in enumerate(L) if i%3 != 0] > [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19] > > > Gary Herron > > > -- > Dr. Gary Herron > Department of Computer Science > DigiPen Institute of Technology > (425) 895-4418
Thanks to you and others who replied. I see that enumerate is a useful function. -- https://mail.python.org/mailman/listinfo/python-list