DESCRIPTION.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. ==============
  2. More Itertools
  3. ==============
  4. .. image:: https://coveralls.io/repos/github/erikrose/more-itertools/badge.svg?branch=master
  5. :target: https://coveralls.io/github/erikrose/more-itertools?branch=master
  6. Python's ``itertools`` library is a gem - you can compose elegant solutions
  7. for a variety of problems with the functions it provides. In ``more-itertools``
  8. we collect additional building blocks, recipes, and routines for working with
  9. Python iterables.
  10. Getting started
  11. ===============
  12. To get started, install the library with `pip <https://pip.pypa.io/en/stable/>`_:
  13. .. code-block:: shell
  14. pip install more-itertools
  15. The recipes from the `itertools docs <https://docs.python.org/3/library/itertools.html#itertools-recipes>`_
  16. are included in the top-level package:
  17. .. code-block:: python
  18. >>> from more_itertools import flatten
  19. >>> iterable = [(0, 1), (2, 3)]
  20. >>> list(flatten(iterable))
  21. [0, 1, 2, 3]
  22. Several new recipes are available as well:
  23. .. code-block:: python
  24. >>> from more_itertools import chunked
  25. >>> iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]
  26. >>> list(chunked(iterable, 3))
  27. [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
  28. >>> from more_itertools import spy
  29. >>> iterable = (x * x for x in range(1, 6))
  30. >>> head, iterable = spy(iterable, n=3)
  31. >>> list(head)
  32. [1, 4, 9]
  33. >>> list(iterable)
  34. [1, 4, 9, 16, 25]
  35. For the full listing of functions, see the `API documentation <https://more-itertools.readthedocs.io/en/latest/api.html>`_.
  36. Development
  37. ===========
  38. ``more-itertools`` is maintained by `@erikrose <https://github.com/erikrose>`_
  39. and `@bbayles <https://github.com/bbayles>`_, with help from `many others <https://github.com/erikrose/more-itertools/graphs/contributors>`_.
  40. If you have a problem or suggestion, please file a bug or pull request in this
  41. repository. Thanks for contributing!
  42. Version History
  43. ===============
  44. 4.1.0
  45. -----
  46. * New itertools:
  47. * split_at (thanks to michael-celani)
  48. * circular_shifts (thanks to hiqua)
  49. * make_decorator - see the blog post `Yo, I heard you like decorators <https://sites.google.com/site/bbayles/index/decorator_factory>`_
  50. for a tour (thanks to pylang)
  51. * always_reversible (thanks to michael-celani)
  52. * nth_combination (from the `Python 3.7 docs <https://docs.python.org/3.7/library/itertools.html#itertools-recipes>`_)
  53. * Improvements to existing itertools:
  54. * seekable now has an ``elements`` method to return cached items.
  55. * The performance tradeoffs between roundrobin and
  56. interleave_longest are now documented (thanks michael-celani,
  57. pylang, and MSeifert04)
  58. 4.0.1
  59. -----
  60. * No code changes - this release fixes how the docs display on PyPI.
  61. 4.0.0
  62. -----
  63. * New itertools:
  64. * consecutive_groups (Based on the example in the `Python 2.4 docs <https://docs.python.org/release/2.4.4/lib/itertools-example.html>`_)
  65. * seekable (If you're looking for how to "reset" an iterator,
  66. you're in luck!)
  67. * exactly_n (thanks to michael-celani)
  68. * run_length.encode and run_length.decode
  69. * difference
  70. * Improvements to existing itertools:
  71. * The number of items between filler elements in intersperse can
  72. now be specified (thanks to pylang)
  73. * distinct_permutations and peekable got some minor
  74. adjustments (thanks to MSeifert04)
  75. * always_iterable now returns an iterator object. It also now
  76. allows different types to be considered iterable (thanks to jaraco)
  77. * bucket can now limit the keys it stores in memory
  78. * one now allows for custom exceptions (thanks to kalekundert)
  79. * Other changes:
  80. * A few typos were fixed (thanks to EdwardBetts)
  81. * All tests can now be run with ``python setup.py test``
  82. The major version update is due to the change in the return value of always_iterable.
  83. It now always returns iterator objects:
  84. .. code-block:: python
  85. >>> from more_itertools import always_iterable
  86. # Non-iterable objects are wrapped with iter(tuple(obj))
  87. >>> always_iterable(12345)
  88. <tuple_iterator object at 0x7fb24c9488d0>
  89. >>> list(always_iterable(12345))
  90. [12345]
  91. # Iterable objects are wrapped with iter()
  92. >>> always_iterable([1, 2, 3, 4, 5])
  93. <list_iterator object at 0x7fb24c948c50>
  94. 3.2.0
  95. -----
  96. * New itertools:
  97. * lstrip, rstrip, and strip
  98. (thanks to MSeifert04 and pylang)
  99. * islice_extended
  100. * Improvements to existing itertools:
  101. * Some bugs with slicing peekable-wrapped iterables were fixed
  102. 3.1.0
  103. -----
  104. * New itertools:
  105. * numeric_range (Thanks to BebeSparkelSparkel and MSeifert04)
  106. * count_cycle (Thanks to BebeSparkelSparkel)
  107. * locate (Thanks to pylang and MSeifert04)
  108. * Improvements to existing itertools:
  109. * A few itertools are now slightly faster due to some function
  110. optimizations. (Thanks to MSeifert04)
  111. * The docs have been substantially revised with installation notes,
  112. categories for library functions, links, and more. (Thanks to pylang)
  113. 3.0.0
  114. -----
  115. * Removed itertools:
  116. * ``context`` has been removed due to a design flaw - see below for
  117. replacement options. (thanks to NeilGirdhar)
  118. * Improvements to existing itertools:
  119. * ``side_effect`` now supports ``before`` and ``after`` keyword
  120. arguments. (Thanks to yardsale8)
  121. * PyPy and PyPy3 are now supported.
  122. The major version change is due to the removal of the ``context`` function.
  123. Replace it with standard ``with`` statement context management:
  124. .. code-block:: python
  125. # Don't use context() anymore
  126. file_obj = StringIO()
  127. consume(print(x, file=f) for f in context(file_obj) for x in u'123')
  128. # Use a with statement instead
  129. file_obj = StringIO()
  130. with file_obj as f:
  131. consume(print(x, file=f) for x in u'123')
  132. 2.6.0
  133. -----
  134. * New itertools:
  135. * ``adjacent`` and ``groupby_transform`` (Thanks to diazona)
  136. * ``always_iterable`` (Thanks to jaraco)
  137. * (Removed in 3.0.0) ``context`` (Thanks to yardsale8)
  138. * ``divide`` (Thanks to mozbhearsum)
  139. * Improvements to existing itertools:
  140. * ``ilen`` is now slightly faster. (Thanks to wbolster)
  141. * ``peekable`` can now prepend items to an iterable. (Thanks to diazona)
  142. 2.5.0
  143. -----
  144. * New itertools:
  145. * ``distribute`` (Thanks to mozbhearsum and coady)
  146. * ``sort_together`` (Thanks to clintval)
  147. * ``stagger`` and ``zip_offset`` (Thanks to joshbode)
  148. * ``padded``
  149. * Improvements to existing itertools:
  150. * ``peekable`` now handles negative indexes and slices with negative
  151. components properly.
  152. * ``intersperse`` is now slightly faster. (Thanks to pylang)
  153. * ``windowed`` now accepts a ``step`` keyword argument.
  154. (Thanks to pylang)
  155. * Python 3.6 is now supported.
  156. 2.4.1
  157. -----
  158. * Move docs 100% to readthedocs.io.
  159. 2.4
  160. -----
  161. * New itertools:
  162. * ``accumulate``, ``all_equal``, ``first_true``, ``partition``, and
  163. ``tail`` from the itertools documentation.
  164. * ``bucket`` (Thanks to Rosuav and cvrebert)
  165. * ``collapse`` (Thanks to abarnet)
  166. * ``interleave`` and ``interleave_longest`` (Thanks to abarnet)
  167. * ``side_effect`` (Thanks to nvie)
  168. * ``sliced`` (Thanks to j4mie and coady)
  169. * ``split_before`` and ``split_after`` (Thanks to astronouth7303)
  170. * ``spy`` (Thanks to themiurgo and mathieulongtin)
  171. * Improvements to existing itertools:
  172. * ``chunked`` is now simpler and more friendly to garbage collection.
  173. (Contributed by coady, with thanks to piskvorky)
  174. * ``collate`` now delegates to ``heapq.merge`` when possible.
  175. (Thanks to kmike and julianpistorius)
  176. * ``peekable``-wrapped iterables are now indexable and sliceable.
  177. Iterating through ``peekable``-wrapped iterables is also faster.
  178. * ``one`` and ``unique_to_each`` have been simplified.
  179. (Thanks to coady)
  180. 2.3
  181. -----
  182. * Added ``one`` from ``jaraco.util.itertools``. (Thanks, jaraco!)
  183. * Added ``distinct_permutations`` and ``unique_to_each``. (Contributed by
  184. bbayles)
  185. * Added ``windowed``. (Contributed by bbayles, with thanks to buchanae,
  186. jaraco, and abarnert)
  187. * Simplified the implementation of ``chunked``. (Thanks, nvie!)
  188. * Python 3.5 is now supported. Python 2.6 is no longer supported.
  189. * Python 3 is now supported directly; there is no 2to3 step.
  190. 2.2
  191. -----
  192. * Added ``iterate`` and ``with_iter``. (Thanks, abarnert!)
  193. 2.1
  194. -----
  195. * Added (tested!) implementations of the recipes from the itertools
  196. documentation. (Thanks, Chris Lonnen!)
  197. * Added ``ilen``. (Thanks for the inspiration, Matt Basta!)
  198. 2.0
  199. -----
  200. * ``chunked`` now returns lists rather than tuples. After all, they're
  201. homogeneous. This slightly backward-incompatible change is the reason for
  202. the major version bump.
  203. * Added ``@consumer``.
  204. * Improved test machinery.
  205. 1.1
  206. -----
  207. * Added ``first`` function.
  208. * Added Python 3 support.
  209. * Added a default arg to ``peekable.peek()``.
  210. * Noted how to easily test whether a peekable iterator is exhausted.
  211. * Rewrote documentation.
  212. 1.0
  213. -----
  214. * Initial release, with ``collate``, ``peekable``, and ``chunked``. Could
  215. really use better docs.