[Tutor] skip/slice more than every second?

Peter Otten __peter__ at web.de
Tue Sep 29 09:33:16 CEST 2015


questions anon wrote:

> thankyou but I just realised I wrote the question wrong -
> 
> how do I do the inverse of above
> so
> hide 1 show 2,3,4 hide 5, show 6,7,8 etc.
> 
> thanks in advance

You can use del on a slice:

>>> a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
>>> del a[::4]
>>> a
[2, 3, 4, 6, 7, 8, 10, 11, 12, 14]

As this modifies the list you may want to make a copy first.



More information about the Tutor mailing list