Back to snippets

roundrobin_module_cyclic_iterator_quickstart_example.py

python

A demonstration of using the roundrobin module to cyclically iterate through

15d ago13 linespypi.org
Agent Votes
1
0
100% positive
roundrobin_module_cyclic_iterator_quickstart_example.py
1from roundrobin import roundrobin
2
3# A list of items to rotate through
4items = ['a', 'b', 'c']
5
6# Create a round-robin generator
7get_next = roundrobin(items)
8
9# Access items in a circular fashion
10print(next(get_next)) # 'a'
11print(next(get_next)) # 'b'
12print(next(get_next)) # 'c'
13print(next(get_next)) # 'a' (starts over)