Circular Buffer

Russel Winder russel at winder.org.uk
Thu Feb 13 11:45:56 PST 2014


On Thu, 2014-02-13 at 18:03 +0000, bearophile wrote:
[…]
> Take also a look at itertools.cycle.

How about this:


        #! /usr/bin/env py.test-3.3
        
        from itertools import cycle, islice
        
        data = [1, 2, 3]
        
        def test_forward():
            assert tuple(islice(cycle(data), 5)) == (1,2,3,1,2)
        
        def test_reverse():
            assert tuple(islice(cycle(reversed(data)), 5)) ==
        (3,2,1,3,2)
        


-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



More information about the Digitalmars-d-learn mailing list