ZhangZhihui's Blog  

The itertools module contains special functions to create iterators for efficient looping. It has three broad categories of iterators - infinite iterators, iterators terminating on the shortest input sequence and combinatoric iterators. We will see the usage of some of them in the upcoming sections:

Infinite iterators

count() cycle() repeat()

Iterators terminating on the shortest input sequence

accumulate() chain() compress() dropwhile() filterfalse() groupby() islice() pairwise() takewhile() tee() zip_longest()

Combinatoric iterators

combinations() combinations_with_replacement() permutations() product()

 

COLOR_ITER = itertools.cycle(["red", "green", "blue", "black", "yellow", "pink", "purple", "cyan"])

......

m.color(next(COLOR_ITER))

 

posted on 2024-07-31 10:40  ZhangZhihuiAAA  阅读(3)  评论(0编辑  收藏  举报