diff options
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/configparser.rst | 5 | ||||
-rw-r--r-- | Doc/library/itertools.rst | 29 |
2 files changed, 32 insertions, 2 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 89bd441..aa4dc7c 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -176,8 +176,9 @@ RawConfigParser Objects .. method:: RawConfigParser.add_section(section) Add a section named *section* to the instance. If a section by the given name - already exists, :exc:`DuplicateSectionError` is raised. - + already exists, :exc:`DuplicateSectionError` is raised. If the name + ``DEFAULT`` (or any of it's case-insensitive variants) is passed, + :exc:`ValueError` is raised. .. method:: RawConfigParser.has_section(section) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 013ed38..af73b57 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -289,6 +289,29 @@ loops that truncate the stream. example :func:`islice` or :func:`takewhile`). +.. function:: product(*iterables) + + Cartesian product of input iterables. + + Equivalent to nested for-loops in a generator expression. For example, + ``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). + + Equivalent to (but without building the entire result in memory):: + + def product(*args): + pools = map(tuple, args) + 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) + + .. function:: repeat(object[, times]) Make an iterator that returns *object* over and over again. Runs indefinitely @@ -526,3 +549,9 @@ which incur interpreter overhead. :: pending -= 1 nexts = cycle(islice(nexts, pending)) + def powerset(iterable): + "powerset('ab') --> set([]), set(['b']), set(['a']), set(['a', 'b'])" + skip = object() + for t in product(*izip(repeat(skip), iterable)): + yield set(e for e in t if e is not skip) + |