[Tutor] skip/slice more than every second?

Steven D'Aprano steve at pearwood.info
Tue Sep 29 06:16:39 CEST 2015


On Tue, Sep 29, 2015 at 01:54:44PM +1000, 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

A little more tricky. The version I showed using iter() and a while loop 
will work, but perhaps this is simpler:

py> for i in range(0, len(a), 4):
...     print(a[i+1:i+4])
...
[2, 3, 4]
[6, 7, 8]
[10, 11, 12]
[14]



-- 
Steve


More information about the Tutor mailing list