On Wed, 24 Jul 2013 13:17:12 -0400, Terry Reedy wrote:
On 7/24/2013 12:34 PM, Chris Angelico wrote:
Side point: Why is iterating over a dict equivalent to .keys() rather
than .items()? It feels odd that, with both options viable, the
implicit version iterates over half the dict instead of
On Wed, 24 Jul 2013 17:59:43 -0700, Ethan Furman wrote:
Repeat after me: In Python 2, d.keys() returns a list of keys, so if I
want a list of keys in Python 3, call list explicitly list(d.keys()).
Actually, I would recommend `list(d)`, which also works the same in both
2 and 3.
Fair point.
On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Dicts aren't sets, and don't support set methods:
py d1 - d2
Traceback (most recent call last):
File stdin, line 1, in module
TypeError: unsupported operand type(s) for -: 'dict' and 'dict'
I
On 25/07/2013 4:31 AM, Ethan Furman wrote:
2) Hopefully learn something about when a view is useful.
I haven't seeen this mentioned - forgive me if it's a repeat - but views
are constant references to whichever set they represent.
Python 2.7:
dd = dict(a=1,b=2,c=3)
keys = dd.keys()
On Wed, 24 Jul 2013 11:31:58 -0700, Ethan Furman wrote:
On 07/24/2013 10:23 AM, Stefan Behnel wrote:
Peter Otten, 24.07.2013 08:23:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys()
different from dict? What are the use cases?
To me it looks like views
On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote:
On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Dicts aren't sets, and don't support set methods:
py d1 - d2
Traceback (most recent call last):
File stdin, line 1, in module
TypeError:
On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
- Views support efficient (O(1) in the case of keys) membership testing,
which neither iterkeys() nor Python2 keys() does.
To save me the trouble and potential error of digging through the
source code:
Chris Angelico wrote:
On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
- Views support efficient (O(1) in the case of keys) membership testing,
which neither iterkeys() nor Python2 keys() does.
To save me the trouble and potential error of
On Thu, Jul 25, 2013 at 5:27 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote:
On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Dicts aren't sets, and don't support set methods:
On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote:
On Thu, Jul 25, 2013 at 5:27 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote:
On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano
On Thu, Jul 25, 2013 at 7:44 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote:
That's true, but we already have that issue with sets. What's the union
of {0} and {0.0}? Python's answer: It depends on the order of the
On 25.07.2013 07:48, Steven D'Aprano wrote:
Then you aren't looking very closely. d.keys() returns a set-like view
into the dict, which is great for comparing elements:
py d1 = dict.fromkeys([1, 2, 3, 4])
py d2 = dict.fromkeys([3, 4, 5, 6])
py d1.keys() d2.keys() # keys that are in both
On 07/24/2013 11:01 PM, alex23 wrote:
On 25/07/2013 4:31 AM, Ethan Furman wrote:
2) Hopefully learn something about when a view is useful.
I haven't seeen this mentioned - forgive me if it's a repeat - but views are
constant references to whichever set they
represent.
Python 2.7:
dd =
On 07/24/2013 10:48 PM, Steven D'Aprano wrote:
On Wed, 24 Jul 2013 08:57:11 -0700, Ethan Furman wrote:
My point is that in 2.x .keys() did something different from the dict,
while in 3.x it appears to me that they are the same.
Then you aren't looking very closely.
Actually, I am. That's
On Thu, 25 Jul 2013 20:34:23 +1000, Chris Angelico wrote:
On Thu, Jul 25, 2013 at 7:44 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote:
That's true, but we already have that issue with sets. What's the
union of {0} and
On Fri, Jul 26, 2013 at 12:57 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
[ snip lengthy explanation of sets ]
The union operator ought to
be symmetrical, a ∪ b should be identical to b ∪ a, but isn't. Another
leaky abstraction.
Right. I agree with all your theory, which
On Thu, Jul 25, 2013 at 2:13 AM, Peter Otten __pete...@web.de wrote:
Chris Angelico wrote:
On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
- Views support efficient (O(1) in the case of keys) membership testing,
which neither iterkeys() nor
Terry Reedy wrote:
On 7/24/2013 4:34 PM, Prasad, Ramit wrote:
I am still not clear on the advantage of views vs. iterators.
A1: Views are iterables that can be iterated more than once. Therefore,
they can be passed to a function that re-iterates its inputs, or to
multiple functions.
Ian Kelly wrote:
On Thu, Jul 25, 2013 at 2:13 AM, Peter Otten __pete...@web.de wrote:
Chris Angelico wrote:
On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
- Views support efficient (O(1) in the case of keys) membership
testing, which neither
On 07/25/2013 09:11 AM, Prasad, Ramit wrote:
Terry Reedy wrote:
On 7/24/2013 4:34 PM, Prasad, Ramit wrote:
I am still not clear on the advantage of views vs. iterators.
A1: Views are iterables that can be iterated more than once. Therefore,
they can be passed to a function that re-iterates
On 7/25/2013 12:21 PM, Ethan Furman wrote:
On 07/25/2013 09:11 AM, Prasad, Ramit wrote:
Hmm, that is a change that makes some sense to me. Does the view
get updated when dictionary changes or is a new view needed? I
assume the latter.
Nope, the former. That is a big advantage that the
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
I just grepped through /usr/lib/python3, and could not identify a single
line where some_object.keys() wasn't either wrapped in a list (or set,
sorted, max) call,
On Jul 24, 2013 7:25 AM, Peter Otten __pete...@web.de wrote:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
I just grepped through /usr/lib/python3, and could not identify a single
line where
On 2013-07-24, Peter Otten __pete...@web.de wrote:
So, my question boils down to: in Python 3 how is dict.keys()
different from dict? What are the use cases?
I just grepped through /usr/lib/python3, and could not identify
a single line where some_object.keys() wasn't either wrapped in
a
Oscar Benjamin wrote:
On Jul 24, 2013 7:25 AM, Peter Otten __pete...@web.de wrote:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys()
different
from dict? What are the use cases?
I just grepped through /usr/lib/python3, and could not identify a single
What do you mean? Why would you want to create a temporary list just to
iterate over it explicitly or implicitly (set, sorted, max,...)?
Because while iterating over the keys, he might also want to add or
delete keys to/from the dict. You can't do that while iterating over
them in-place.
This
On Tue, Jul 23, 2013 at 8:11 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Basically, views are set-like, not list-like.
The keys and items views are set-like. The values view is not.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Jul 24, 2013 at 8:58 AM, Skip Montanaro s...@pobox.com wrote:
What do you mean? Why would you want to create a temporary list just to
iterate over it explicitly or implicitly (set, sorted, max,...)?
Because while iterating over the keys, he might also want to add or
delete keys
On 07/24/2013 05:51 AM, Oscar Benjamin wrote:
On Jul 24, 2013 7:25 AM, Peter Otten __pete...@web.de
mailto:pete...@web.de wrote:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
I just grepped through
On Jul 24, 2013 2:27 PM, Peter Otten __pete...@web.de wrote:
Oscar Benjamin wrote:
On Jul 24, 2013 7:25 AM, Peter Otten __pete...@web.de wrote:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys()
different
from dict? What are the use cases?
I
On Thu, Jul 25, 2013 at 1:57 AM, Ethan Furman et...@stoneleaf.us wrote:
On 07/24/2013 05:51 AM, Oscar Benjamin wrote:
What do you mean? Why would you want to create a temporary list just to
iterate over it explicitly or implicitly (set,
sorted, max,...)?
You wouldn't. But you don't need
On 7/24/2013 12:34 PM, Chris Angelico wrote:
Side point: Why is iterating over a dict equivalent to .keys() rather
than .items()? It feels odd that, with both options viable, the
implicit version iterates over half the dict instead of all of it.
Obviously it can't be changed now, even if
Chris Angelico, 24.07.2013 18:34:
On Thu, Jul 25, 2013 at 1:57 AM, Ethan Furman wrote:
On 07/24/2013 05:51 AM, Oscar Benjamin wrote:
What do you mean? Why would you want to create a temporary list just to
iterate over it explicitly or implicitly (set,
sorted, max,...)?
You wouldn't. But
Peter Otten, 24.07.2013 08:23:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
I just grepped through /usr/lib/python3, and could not identify a single
line where some_object.keys() wasn't either wrapped in a
On Thu, Jul 25, 2013 at 3:17 AM, Terry Reedy tjre...@udel.edu wrote:
On 7/24/2013 12:34 PM, Chris Angelico wrote:
Side point: Why is iterating over a dict equivalent to .keys() rather
than .items()? It feels odd that, with both options viable, the
implicit version iterates over half the dict
On 07/24/2013 10:23 AM, Stefan Behnel wrote:
Peter Otten, 24.07.2013 08:23:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
To me it looks like views are a solution waiting for a problem.
They reduce the API
Ethan Furman, 24.07.2013 20:31:
On 07/24/2013 10:23 AM, Stefan Behnel wrote:
Peter Otten, 24.07.2013 08:23:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
To me it looks like views are a solution waiting for
On 07/24/2013 12:59 PM, Stefan Behnel wrote:
I think the question is: how else would you implement an interface that
doesn't restrict itself to returning a list? I mean, previously, the
following was totally inefficient in terms of memory:
value in d.values()
It now avoids creating an
Stefan Behnel wrote:
Ethan Furman, 24.07.2013 20:31:
On 07/24/2013 10:23 AM, Stefan Behnel wrote:
Peter Otten, 24.07.2013 08:23:
Ethan Furman wrote:
So, my question boils down to: in Python 3 how is dict.keys() different
from dict? What are the use cases?
To me it looks like
Am 24.07.2013 18:34, schrieb Chris Angelico:
Side point: Why is iterating over a dict equivalent to .keys() rather
than .items()? It feels odd that, with both options viable, the
implicit version iterates over half the dict instead of all of it.
Obviously it can't be changed now, even if
On 7/24/2013 4:34 PM, Prasad, Ramit wrote:
I am still not clear on the advantage of views vs. iterators.
A1: Views are iterables that can be iterated more than once. Therefore,
they can be passed to a function that re-iterates its inputs, or to
multiple functions. They support 'x in view'
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
On 07/23/2013 07:11 PM, Steven D'Aprano wrote:
On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:
So now, in Python 3, .keys(), .values(), even .items() all return these
'view' thingies.
And everything I thought I knew about when to use one or the other went
out the window.
Surely not.
Ethan Furman et...@stoneleaf.us writes:
On 07/23/2013 07:11 PM, Steven D'Aprano wrote:
On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:
And everything I thought I knew about when to use one or the other went
out the window.
Surely not. The fundamental behaviour of Python's data
On Wed, 24 Jul 2013 08:57:11 -0700, Ethan Furman wrote:
My point is that in 2.x .keys() did something different from the dict,
while in 3.x it appears to me that they are the same.
Then you aren't looking very closely. d.keys() returns a set-like view
into the dict, which is great for
On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:
Back in Python 2.x days I had a good grip on dict and dict.keys(), and
when to use one or the other.
Then Python 3 came on the scene with these things called 'views', and
while range couldn't be bothered, dict jumped up and down
46 matches
Mail list logo