By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

dicts + amb

P: n/a
I have implemented yet another Odict class:
http://aspn.activestate.com/ASPN/Coo.../Recipe/498195
It's very slow, but it is O(1) for get, set and del too.

I have added ritervalues(), rkeys(), etc methods because I presume I
can't use the reversed(). So can an __riter__ hook be generally useful?
(I have seen few comments about it in the discussion regarding PEP
322).

What's the meaning of .updated() called without arguments? Can it
become an error in Python 3.0?

In practice I don't have problems using dict get() and pop() methods,
but their calling behaviour seem a bit incoherent. Both accept a second
value, that can be None too, that they return if the key is absent, but
the get() returns the None even if you don't specify it, while pop()
return a TypeError if you don't give explicitely something (like None)
as second argument. (Maybe in practice they are more useful if kept
with such different calling behaviour.)

------------

Something unrelated that I don't know where to put.
Recently I have seen the amb operator, it's not a simple operator. I
have seen a (very simple) Ruby implementation:
http://www.randomhacks.net/articles/...1/amb-operator
I think a good amb implementation is a very complex thing. Can such
operator be useful for Python too?

Bye,
bearophile

Oct 11 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Something unrelated that I don't know where to put.
Recently I have seen the amb operator, it's not a simple operator. I
have seen a (very simple) Ruby implementation:
http://www.randomhacks.net/articles/...1/amb-operator
I think a good amb implementation is a very complex thing. Can such
operator be useful for Python too?
You might consider researching ALMA, a constraint-imperative programming
language that allows for program execution to be rolled-back to
so-called choicepoints. It heavily reminds me of that amb-operator of
yours.

Diez
Oct 11 '06 #2

P: n/a
In <11*********************@h48g2000cwc.googlegroups. com>, bearophileHUGS
wrote:
I have implemented yet another Odict class:
http://aspn.activestate.com/ASPN/Coo.../Recipe/498195
It's very slow, but it is O(1) for get, set and del too.

I have added ritervalues(), rkeys(), etc methods because I presume I
can't use the reversed(). So can an __riter__ hook be generally useful?
(I have seen few comments about it in the discussion regarding PEP
322).
I don't know if this is documented somewhere but the `reversed()` function
looks for a `__reversed__()` method that returns an iterator.

Ciao,
Marc 'BlackJack' Rintsch
Oct 11 '06 #3

P: n/a
Marc 'BlackJack' Rintsch:
I don't know if this is documented somewhere but the `reversed()` function
looks for a `__reversed__()` method that returns an iterator.
You are right, thank you, I have done some tests already, and I'll soon
add that method too.

-------------------
Partially related.
I have used the new Google code search:
http://www.google.com/codesearch/advanced_code_search
To find the usage frequency of Python dict methods:

456 ".itervalues()" lang:python
415 ".iteritems()" lang:python
403 ".iterkeys()" lang:python
387 ".values()" lang:python
385 ".clear()" lang:python
256 ".update(" lang:python
254 ".fromkeys(" lang:python
224 ".has_key(" lang:python
201 ".get(" lang:python
200 ".items()" lang:python
159 ".popitem()" lang:python
113 "a.setdefault(" lang:python

The results are quite approximated, but they seem meaningful.

Bye,
bearophile

Oct 11 '06 #4

P: n/a
be************@lycos.com:
456 ".itervalues()" lang:python
415 ".iteritems()" lang:python
403 ".iterkeys()" lang:python
387 ".values()" lang:python
385 ".clear()" lang:python
256 ".update(" lang:python
254 ".fromkeys(" lang:python
224 ".has_key(" lang:python
201 ".get(" lang:python
200 ".items()" lang:python
159 ".popitem()" lang:python
113 "a.setdefault(" lang:python
Sorry:

398 lang:python ".setdefault("

Results are probably too much approximated to be of any use...

Bye,
bearophile

Oct 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.