[Python-Dev] sets, scanf
Andrew Bennetts
andrew-pythondev at puzzling.org
Fri May 21 11:02:52 EDT 2004
On Thu, May 20, 2004 at 01:31:09PM -0400, Mark.Lake at aigfpc.com wrote:
[...]
>
> 2. Sets are a useful addition to the language, but sorted sets (and
> dictionaries) would be more useful. C++/Java/C# all provide these types.
> In particular I'd like to see:
>
> A. Dictionaries support union, intersection, and symmetric difference
> operations as sets do.
What's the intersection of {'a': 1} and {'a': 2}? {'a': (1, 2)}? What
about of {1.0: 'one point oh'} and {1: 'one'}?
Also, this would place a significant burden on people trying to implement
their own classes that present a dictionary-like interface, although perhaps
UserDict.DictMixin could help there...
A PEP for this that's more than a sentence long would probably be a good
idea :)
[...]
> C. Binary searching for items in sorted sequence and mapping types.
See the bisect module. I'm not sure what binary searching of a mapping type
would mean, though (I guess you mean for your proposed sorted dictionary
type?).
> D. Ability to handle multiple getitems at once in sequence and mapping
> types (Akin to what can be done in numarray). Certainly there is no good
> reason why lists/tuples shouldn't support list[iterable] (not to be
> confused with list(iterable)) which returns or dictionaries support
> something like dict.getm(iterable).
Well, one reason is that it places a greater burden on people implementing
__getitem__, and it doesn't really offer much improvement over:
[l[x] for x in iterable]
Or for dictionaries:
dict(d[x] for x in iterable) # Assuming 2.4's generator expressions.
-Andrew.
More information about the Python-Dev
mailing list