Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51175 > unrolled thread
| Started by | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| First post | 2013-07-24 16:22 -0700 |
| Last post | 2013-07-24 16:22 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-24 16:22 -0700
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2013-07-24 16:22 -0700 |
| Subject | Re: Python 3: dict & dict.keys() |
| Message-ID | <mailman.5072.1374709915.3114.python-list@python.org> |
On 07/24/2013 01:34 PM, Prasad, Ramit wrote:
>
> I am still not clear on the advantage of views vs. iterators. What
> makes d.viewkeys() better than d.iterkeys()? Why did they decide
> not to rename d.iterkeys() to d.keys() and instead use d.viewkeys()?
> Is the iteration over a set operation on keys really that common a
> use case?
From a practical standpoint, iterkeys() is a one-shot deal, while viewkeys() can be iterated over multiple times:
--> d = {1: 'one', 2: 'two', 3: 'three'}
--> di = d.iterkeys()
--> list(di)
[1, 2, 3]
--> list(di)
[]
--> dv = d.viewkeys()
--> list(dv)
[1, 2, 3]
--> list(dv)
[1, 2, 3]
And views are not sets -- they just support a couple set-like operations.
--
~Ethan~
Back to top | Article view | comp.lang.python
csiph-web