Loading topic
iter() and next()). Knowing what yield does helps but is not required.2 min readitertools: count, cycle and repeat.3 min readnext() that is used up after one pass). Generators help but are not required.2 min read* argument unpacking.2 min readlambda expressions can serve as predicates. A predicate is a function that returns true or false for an item. The four tools here filter lazily. They produce items on demand and never build an intermediate list.2 min readzip. It also assumes you know that an iterator can be consumed only once. Two itertools tools extend what zip can do. zip_longest handles inputs of unequal length. pairwise looks at neighbouring items in a single stream.3 min readislice calls, and have used generators or generator expressions. Batching is the next step after slicing and pairing. You cut a stream into consecutive chunks of a fixed size without loading the whole stream into memory.2 min readsorted with key=, and the iterator basics from earlier chapters. itertools.groupby splits an iterable into runs of consecutive items that share a key. It looks like SQL's GROUP BY, but it works differently, and that difference causes most o2 min readitertools code such as islice. If an iterator is exhausted, list(it) returns [] the second time. tee is the tool for the case where you need to read the same stream more than once.2 min readmap, and the basic itertools functions from earlier chapters: chain, islice, takewhile, filterfalse, and accumulate.2 min readgroupby, tee and pipelines. It collects the mistakes that cause most itertools bugs and gives rules for choosing a plain list or loop instead.3 min read