Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e74878

Browse files
committed
remove/update many of the references to dict.iter*()
1 parent afe0cd1 commit 2e74878

5 files changed

Lines changed: 28 additions & 44 deletions

File tree

Doc/howto/functional.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ dictionary's keys::
291291
Note that the order is essentially random, because it's based on the hash
292292
ordering of the objects in the dictionary.
293293

294-
Applying ``iter()`` to a dictionary always loops over the keys, but dictionaries
295-
have methods that return other iterators. If you want to iterate over keys,
296-
values, or key/value pairs, you can explicitly call the ``iterkeys()``,
297-
``itervalues()``, or ``iteritems()`` methods to get an appropriate iterator.
294+
Applying :func:`iter` to a dictionary always loops over the keys, but
295+
dictionaries have methods that return other iterators. If you want to iterate
296+
over values or key/value pairs, you can explicitly call the
297+
:meth:`values` or :meth:`items` methods to get an appropriate iterator.
298298

299299
The :func:`dict` constructor can accept an iterator that returns a finite stream
300300
of ``(key, value)`` tuples::

Doc/library/itertools.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ can be combined. ::
414414
# Show a dictionary sorted and grouped by value
415415
>>> from operator import itemgetter
416416
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
417-
>>> di = sorted(d.iteritems(), key=itemgetter(1))
417+
>>> di = sorted(d.items(), key=itemgetter(1))
418418
>>> for k, g in groupby(di, key=itemgetter(1)):
419419
... print(k, map(itemgetter(0), g))
420420
...
@@ -464,9 +464,6 @@ incur interpreter overhead. ::
464464
"Return function(0), function(1), ..."
465465
return imap(function, count())
466466

467-
def iteritems(mapping):
468-
return izip(mapping.iterkeys(), mapping.itervalues())
469-
470467
def nth(iterable, n):
471468
"Returns the nth item or raise StopIteration"
472469
return islice(iterable, n, None).next()

Doc/library/stdtypes.rst

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,39 +1804,24 @@ types should support too):
18041804

18051805
.. method:: dict.items()
18061806

1807-
Return a copy of the dictionary's list of ``(key, value)`` pairs.
1807+
Return an iterator over the dictionary's ``(key, value)`` pairs.
18081808

18091809
.. note::
18101810

18111811
Keys and values are listed in an arbitrary order which is non-random, varies
18121812
across Python implementations, and depends on the dictionary's history of
1813-
insertions and deletions. If :meth:`items`, :meth:`keys`, :meth:`values`,
1814-
:meth:`iteritems`, :meth:`iterkeys`, and :meth:`itervalues` are called with no
1813+
insertions and deletions. If :meth:`items`, :meth:`keys`, and
1814+
:meth:`values` are called with no
18151815
intervening modifications to the dictionary, the lists will directly correspond.
18161816
This allows the creation of ``(value, key)`` pairs using :func:`zip`: ``pairs =
18171817
zip(d.values(), d.keys())``. The same relationship holds for the
18181818
:meth:`iterkeys` and :meth:`itervalues` methods: ``pairs = zip(d.itervalues(),
18191819
d.iterkeys())`` provides the same value for ``pairs``. Another way to create the
1820-
same list is ``pairs = [(v, k) for (k, v) in d.iteritems()]``.
1821-
1822-
.. method:: dict.iteritems()
1823-
1824-
Return an iterator over the dictionary's ``(key, value)`` pairs.
1825-
See the note for :meth:`dict.items`.
1826-
1827-
.. method:: dict.iterkeys()
1828-
1829-
Return an iterator over the dictionary's keys. See the note for
1830-
:meth:`dict.items`.
1831-
1832-
.. method:: dict.itervalues()
1833-
1834-
Return an iterator over the dictionary's values. See the note for
1835-
:meth:`dict.items`.
1820+
same list is ``pairs = [(v, k) for (k, v) in d.items()]``.
18361821

18371822
.. method:: dict.keys()
18381823

1839-
Return a copy of the dictionary's list of keys. See the note for
1824+
Return an iterator over the dictionary's keys. See the note for
18401825
:meth:`dict.items`.
18411826

18421827
.. method:: dict.pop(key[, default])
@@ -1855,13 +1840,13 @@ types should support too):
18551840

18561841
.. method:: dict.setdefault(key[, default])
18571842

1858-
If *key* is in the dictionary, return its value. If not, insert *key* with a
1859-
value of *default* and return *default*. *default* defaults to ``None``.
1843+
If *key* is in the dictionary, return its value. If not, insert *key* with
1844+
a value of *default* and return *default*. *default* defaults to ``None``.
18601845

18611846
.. method:: dict.update([other])
18621847

1863-
Update the dictionary with the key/value pairs from *other*, overwriting existing
1864-
keys. Return ``None``.
1848+
Update the dictionary with the key/value pairs from *other*, overwriting
1849+
existing keys. Return ``None``.
18651850

18661851
:func:`update` accepts either another dictionary object or an iterable of
18671852
key/value pairs (as a tuple or other iterable of length two). If keyword
@@ -1870,8 +1855,8 @@ types should support too):
18701855

18711856
.. method:: dict.values()
18721857

1873-
Return a copy of the dictionary's list of values. See the note for
1874-
:meth:`mapping.items`.
1858+
Return an iterator over the dictionary's values. See the note for
1859+
:meth:`dict.items`.
18751860

18761861

18771862
.. _bltin-file-objects:

Doc/library/userdict.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ The :mod:`UserDict` module defines the :class:`UserDict` class and
3333

3434
.. note::
3535

36-
For backward compatibility, instances of :class:`UserDict` are not iterable.
36+
For backward compatibility, instances of :class:`UserDict` are not
37+
iterable.
3738

3839

3940
.. class:: IterableUserDict([initialdata])
@@ -62,8 +63,8 @@ provide the following attribute:
6263
:meth:`__delitem__` will preclude only :meth:`pop` and :meth:`popitem` from the
6364
full interface.
6465

65-
In addition to the four base methods, progressively more efficiency comes with
66-
defining :meth:`__contains__`, :meth:`__iter__`, and :meth:`iteritems`.
66+
In addition to the four base methods, progressively more efficiency comes
67+
with defining :meth:`__contains__` and :meth:`__iter__`.
6768

6869
Since the mixin has no knowledge of the subclass constructor, it does not define
6970
:meth:`__init__` or :meth:`copy`.
@@ -93,10 +94,11 @@ The :mod:`UserList` module defines the :class:`UserList` class:
9394
.. class:: UserList([list])
9495

9596
Class that simulates a list. The instance's contents are kept in a regular
96-
list, which is accessible via the :attr:`data` attribute of :class:`UserList`
97+
list, which is accessible via the :attr:`data` attribute of
98+
:class:`UserList`
9799
instances. The instance's contents are initially set to a copy of *list*,
98-
defaulting to the empty list ``[]``. *list* can be any iterable, e.g. a
99-
real Python list or a :class:`UserList` object.
100+
defaulting to the empty list ``[]``. *list* can be any iterable, for
101+
example a real Python list or a :class:`UserList` object.
100102

101103
In addition to supporting the methods and operations of mutable sequences (see
102104
section :ref:`typesseq`), :class:`UserList` instances provide the following

Doc/reference/datamodel.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,8 @@ a sequence, the allowable keys should be the integers *k* for which ``0 <= k <
15891589
N`` where *N* is the length of the sequence, or slice objects, which define a
15901590
range of items. It is also recommended that mappings provide the methods
15911591
:meth:`keys`, :meth:`values`, :meth:`items`, :meth:`has_key`, :meth:`get`,
1592-
:meth:`clear`, :meth:`setdefault`, :meth:`iterkeys`, :meth:`itervalues`,
1593-
:meth:`iteritems`, :meth:`pop`, :meth:`popitem`, :meth:`copy`, and
1592+
:meth:`clear`, :meth:`setdefault`,
1593+
:meth:`pop`, :meth:`popitem`, :meth:`copy`, and
15941594
:meth:`update` behaving similar to those for Python's standard dictionary
15951595
objects. The :mod:`UserDict` module provides a :class:`DictMixin` class to help
15961596
create those methods from a base set of :meth:`__getitem__`,
@@ -1608,7 +1608,7 @@ should be equivalent of :meth:`has_key`; for sequences, it should search through
16081608
the values. It is further recommended that both mappings and sequences
16091609
implement the :meth:`__iter__` method to allow efficient iteration through the
16101610
container; for mappings, :meth:`__iter__` should be the same as
1611-
:meth:`iterkeys`; for sequences, it should iterate through the values.
1611+
:meth:`keys`; for sequences, it should iterate through the values.
16121612

16131613
.. method:: object.__len__(self)
16141614

@@ -1677,7 +1677,7 @@ container; for mappings, :meth:`__iter__` should be the same as
16771677
This method is called when an iterator is required for a container. This method
16781678
should return a new iterator object that can iterate over all the objects in the
16791679
container. For mappings, it should iterate over the keys of the container, and
1680-
should also be made available as the method :meth:`iterkeys`.
1680+
should also be made available as the method :meth:`keys`.
16811681

16821682
Iterator objects also need to implement this method; they are required to return
16831683
themselves. For more information on iterator objects, see :ref:`typeiter`.

0 commit comments

Comments
 (0)