473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

proposed proposal: set.values()

I'm thinking of proposing that a values method be added to set
objects, analogously with dicts. If x is a set, x.values() would be
the same as list(x). This feels logical, and it would allow unified
treatment of dicts and sets in some contexts. Any objections?
Mar 30 '06 #1
6 1434

"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message
news:7x***************@ruckus.brouhaha.com...
I'm thinking of proposing that a values method be added to set
objects, analogously with dicts. If x is a set, x.values() would be
the same as list(x). This feels logical, and it would allow unified
treatment of dicts and sets in some contexts. Any objections?


1. It is pure duplication that *adds* keystrokes.

2. It copies the wrong aspect of dict. A set is like dict.keys (no
duplicates, hashable), not dict.values (duplicates and non-hashables ok).

3. It copies a workaround. Conceptually, dict.keys() and dict.items()
should each be a set, not list, and would have been if Python had had sets
at birth. Dict.values() should be a multiset or bag. The order of any is
purely artificial and random. Set.keys() or set.values() should be the set
itself.

4. The workaround will change or even better go away. In 3.0, ,keys,
..values and .items not be lists. The initial proposal was to replace them
with iterators (the current iterkeys, etc). A current proposal (still in
development) is for an iterable set- or multiset-like view on the
underlying dict.

Terry Jan Reedy

Mar 31 '06 #2
"Terry Reedy" <tj*****@udel.edu> writes:
1. It is pure duplication that *adds* keystrokes.
Nobody says you shouldn't use list(s) if you know you're dealing with
a set. The idea of s.values() is so you can duck-type between dicts
and sets.
2. It copies the wrong aspect of dict. A set is like dict.keys (no
duplicates, hashable), not dict.values (duplicates and non-hashables ok).
I'd say keys is incorrect, since sets don't have keys:
import sets
s=sets.Set((1,2,3))
s[1]

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unindexable object

I don't think it's important that some values that can occur in dicts
(e.g. non-hashables) can't occur in sets. There are similarly values
for complex numbers that can't be expressed as floats, but that
doesn't mean __add__ shouldn't work on both.
3. It copies a workaround. Conceptually, dict.keys() and dict.items()
should each be a set, not list, and would have been if Python had had sets
at birth. Dict.values() should be a multiset or bag. The order of any is
purely artificial and random. Set.keys() or set.values() should be the set
itself.
I guess it's ok if sets.items() is the same as sets.values(). Sets
don't have keys. dict.values() is what it is for historical reasons
as you state, and would be hard to change, so it makes sense for
set.values() to work the same way.
4. The workaround will change or even better go away. In 3.0, ,keys,
.values and .items not be lists. The initial proposal was to replace them
with iterators (the current iterkeys, etc). A current proposal (still in
development) is for an iterable set- or multiset-like view on the
underlying dict.


I hadn't heard of this but it does make some sense. However,
sets.values (and maybe sets.items) should be treated the same way,
under my proposed proposal.
Mar 31 '06 #3
Paul Rubin wrote:
1. It is pure duplication that *adds* keystrokes.


Nobody says you shouldn't use list(s) if you know you're dealing with
a set. The idea of s.values() is so you can duck-type between dicts
and sets.


if y is a dict, "x in y" looks for a matching key, not for a matching value.

</F>

Mar 31 '06 #4
"Fredrik Lundh" <fr*****@pythonware.com> writes:
Nobody says you shouldn't use list(s) if you know you're dealing with
a set. The idea of s.values() is so you can duck-type between dicts
and sets.


if y is a dict, "x in y" looks for a matching key, not for a
matching value.


Good point, the duck typing mismatches on "x in y" and there's nothing
that can be done about that.

Imagine a Bag (multiset) object; it can have multiple occurrences of a
single value. A keys() operation on it should return unique items,
but values() should return the multiple occurrences.
Mar 31 '06 #5
"Terry Reedy" <tj*****@udel.edu> writes:
1. It is pure duplication that *adds* keystrokes.
Nobody says you shouldn't use list(s) if you know you're dealing with
a set. The idea of s.values() is so you can duck-type between dicts
and sets.
2. It copies the wrong aspect of dict. A set is like dict.keys (no
duplicates, hashable), not dict.values (duplicates and non-hashables ok). I'd say keys is incorrect, since sets don't have keys:
import sets
s=sets.Set((1,2,3))
s[1]
Traceback (most recent call last): File "<stdin>", line 1, in ?
TypeError: unindexable object

I don't think it's important that some values that can occur in dicts
(e.g. non-hashables) can't occur in sets. There are similarly values
for complex numbers that can't be expressed as floats, but that
doesn't mean __add__ shouldn't work on both.
3. It copies a workaround. Conceptually, dict.keys() and dict.items() should each be a set, not list, and would have been if Python had had sets at birth. Dict.values() should be a multiset or bag. The order of any is purely artificial and random. Set.keys() or set.values() should be the set itself.
I guess it's ok if sets.items() is the same as sets.values(). Sets
don't have keys. dict.values() is what it is for historical reasons
as you state, and would be hard to change, so it makes sense for
set.values() to work the same way.
4. The workaround will change or even better go away. In 3.0, ,keys, .values and .items not be lists. The initial proposal was to replace them with iterators (the current iterkeys, etc). A current proposal (still in development) is for an iterable set- or multiset-like view on the
underlying dict.

I hadn't heard of this but it does make some sense. However,
sets.values (and maybe sets.items) should be treated the same way,
under my proposed proposal.

Mar 31 '06 #6
Paul Rubin wrote:
"Terry Reedy" <tj*****@udel.edu> writes:
1. It is pure duplication that *adds* keystrokes.

Nobody says you shouldn't use list(s) if you know you're dealing with
a set. The idea of s.values() is so you can duck-type between dicts
and sets.


You could just do the following...

class vset(set): .... values = set.copy
....
s = vset([1,2,3]) s.values() vset([1, 2, 3])
for x in s.values():

.... x
....
1
2
3
Cheers,
Ron
Mar 31 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
0
by: Anne van Kesteren | last post by:
Ok, here it goes. Originally I submitted this proposal to www-style. Since I don't get feedback there, I think I missed a few (maybe a lot) of points. Proposal:...
29
by: C A Upsdell | last post by:
Comments re these three related, proposed CSS 3 additions? 1. Add 'text-transform:time', which would transform text in the format hours:minutes:seconds (24 hour clock) to the local format for...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
2
by: Richard Cornford | last post by:
Anyone who has taken a look at the online FAQ today may have noticed that I have updated it. The majority of the changes are the updating of broken links and the implementation of that extensive...
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.