![]() This is what is meant by the functions in itertools forming an “iterator algebra.” itertools is best viewed as a collection of building blocks that can be combined to form specialized “data pipelines” like the one in the example above. ![]() Multiple assignment and tuple unpacking improve Python code readability.Chapter 6 of Python Tricks: The Book by Dan Bader.Python Iterators: A Step-By-Step Introduction.If you aren’t, or if you need to brush up on your knowledge, consider checking out the following before reading on: Before diving in, you should be confident using iterators and generators in Python 3, multiple assignment, and tuple unpacking. Rather than introducing itertools to you one function at a time, you will construct practical examples designed to encourage you to “think iteratively.” In general, the examples will start simple and gradually increase in complexity.Ī word of warning: this article is long and intended for the intermediate-to-advanced Python programmer. ![]() The real power lies in composing these functions to create fast, memory-efficient, and good-looking code. The thing about itertools, though, is that it is not enough to just know the definitions of the functions it contains. The docs themselves are a great place to start. It has been called a “gem” and “pretty much the coolest thing ever,” and if you have not heard of it, then you are missing out on one of the greatest corners of the Python 3 standard library: itertools.Ī handful of excellent resources exist for learning what functions are available in the itertools module.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |