diff options
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/inspect.rst | 4 | ||||
-rw-r--r-- | Doc/library/itertools.rst | 45 | ||||
-rw-r--r-- | Doc/library/signal.rst | 4 |
3 files changed, 37 insertions, 16 deletions
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index c2bc15c..d622e1d 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -26,7 +26,7 @@ Types and members ----------------- The :func:`getmembers` function retrieves the members of an object such as a -class or module. The fifteen functions whose names begin with "is" are mainly +class or module. The sixteen functions whose names begin with "is" are mainly provided as convenient choices for the second argument to :func:`getmembers`. They also help you determine when you can expect to find the following special attributes: @@ -267,8 +267,6 @@ attributes: Return true if the object is an abstract base class. - .. versionadded:: 2.6 - .. function:: ismethoddescriptor(object) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 9da51aa..0d74c59 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -87,6 +87,7 @@ loops that truncate the stream. .. versionadded:: 2.6 + .. function:: combinations(iterable, r) Return successive *r* length combinations of elements in the *iterable*. @@ -121,6 +122,17 @@ loops that truncate the stream. indices[j] = indices[j-1] + 1 yield tuple(pool[i] for i in indices) + The code for :func:`combinations` can be also expressed as a subsequence + of :func:`permutations` after filtering entries where the elements are not + in sorted order (according to their position in the input pool):: + + def combinations(iterable, r): + pool = tuple(iterable) + n = len(pool) + for indices in permutations(range(n), r): + if sorted(indices) == list(indices): + yield tuple(pool[i] for i in indices) + .. versionadded:: 2.6 .. function:: count([n]) @@ -378,6 +390,18 @@ loops that truncate the stream. else: return + The code for :func:`permutations` can be also expressed as a subsequence of + :func:`product`, filtered to exclude entries with repeated elements (those + from the same position in the input pool):: + + def permutations(iterable, r=None): + pool = tuple(iterable) + n = len(pool) + r = n if r is None else r + for indices in product(range(n), repeat=r): + if len(set(indices)) == r: + yield tuple(pool[i] for i in indices) + .. versionadded:: 2.6 .. function:: product(*iterables[, repeat]) @@ -388,26 +412,25 @@ loops that truncate the stream. ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``. The leftmost iterators are in the outermost for-loop, so the output tuples - cycle in a manner similar to an odometer (with the rightmost element - changing on every iteration). This results in a lexicographic ordering - so that if the inputs iterables are sorted, the product tuples are emitted + cycle like an odometer (with the rightmost element changing on every + iteration). This results in a lexicographic ordering so that if the + inputs iterables are sorted, the product tuples are emitted in sorted order. To compute the product of an iterable with itself, specify the number of repetitions with the optional *repeat* keyword argument. For example, ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``. - Equivalent to the following except that the actual implementation does not - build-up intermediate results in memory:: + This function is equivalent to the following code, except that the + actual implementation does not build up intermediate results in memory:: def product(*args, **kwds): pools = map(tuple, args) * kwds.get('repeat', 1) - if pools: - result = [[]] - for pool in pools: - result = [x+[y] for x in result for y in pool] - for prod in result: - yield tuple(prod) + result = [[]] + for pool in pools: + result = [x+[y] for x in result for y in pool] + for prod in result: + yield tuple(prod) .. function:: repeat(object[, times]) diff --git a/Doc/library/signal.rst b/Doc/library/signal.rst index cf6f8f8..2e5cae5 100644 --- a/Doc/library/signal.rst +++ b/Doc/library/signal.rst @@ -128,12 +128,12 @@ The :mod:`signal` module defines the following functions: .. function:: siginterrupt(signalnum, flag) Change system call restart behaviour: if *flag* is :const:`False`, system calls - will be restarted when interrupted by signal *signalnum*, else system calls will + will be restarted when interrupted by signal *signalnum*, otherwise system calls will be interrupted. Returns nothing. Availability: Unix, Mac (see the man page :manpage:`siginterrupt(3)` for further information). Note that installing a signal handler with :func:`signal` will reset the restart - behaviour to interruptible by implicitly calling siginterrupt with a true *flag* + behaviour to interruptible by implicitly calling :cfunc:`siginterrupt` with a true *flag* value for the given signal. .. versionadded:: 2.6 |