473,508 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dicts + amb

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
4 1324
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8982
by: Afanasiy | last post by:
I have some code like this... self.write( ''' lots of stuff here with %(these)s named expressions ''' % vars(self) ) Then I wanted to add an item to the dict vars(self), so I tried :
1
1186
by: Kwikrick | last post by:
When calling str() on a sequence or dict object, the elements of the sequence/dict will be represented as if their __repr__ method was called. Why is this? Wouldn't it be more consistent when...
9
1618
by: rbt | last post by:
What's a good way to write a dictionary out to a file so that it can be easily read back into a dict later? I've used realines() to read text files into lists... how can I do the same thing with...
12
1411
by: Guyon Morée | last post by:
Hi all, I'm using simple classes as a container of named values and I'm instantiating a lot of them in a very short time. i was wondering if there is any benefit in using dicts instead from a...
6
1824
by: bearophileHUGS | last post by:
I have found that in certain situations ordered dicts are useful. I use an Odict class written in Python by ROwen that I have improved and updated some for personal use. So I'm thinking about a...
12
1844
by: Alan Isaac | last post by:
This discussion ended abruptly, and I'd like to see it reach a conclusion. I will attempt to synthesize Bill and Carsten's proposals. There are two proposed patches. The first is to...
0
965
by: Chris Rebert | last post by:
On Thu, Oct 16, 2008 at 12:19 PM, John Townsend <jtownsen@adobe.comwrote: Right, this clobbers the existing entry with this new blank one. This is evidenced by the fact that you're performing an...
4
1547
by: John Townsend | last post by:
Joe had a good point! Let me describe what problem I'm trying to solve and the list can recommend some suggestions. I have two text files. Each file contains data like this: Test file 1234 4567...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.