dicts + amb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bearophileHUGS@lycos.com

    #1

    dicts + amb

    I have implemented yet another Odict class:

    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:

    I think a good amb implementation is a very complex thing. Can such
    operator be useful for Python too?

    Bye,
    bearophile

  • Diez B. Roggisch

    #2
    Re: dicts + amb

    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:

    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

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: dicts + amb

      In <1160601017.272 078.63240@h48g2 000cwc.googlegr oups.com>, bearophileHUGS
      wrote:
      I have implemented yet another Odict class:

      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

      Comment

      • bearophileHUGS@lycos.com

        #4
        Re: dicts + amb

        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:

        To find the usage frequency of Python dict methods:

        456 ".itervalue s()" 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.setdefau lt(" lang:python

        The results are quite approximated, but they seem meaningful.

        Bye,
        bearophile

        Comment

        • bearophileHUGS@lycos.com

          #5
          Re: dicts + amb

          bearophileHUGS@ lycos.com:
          456 ".itervalue s()" 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.setdefau lt(" lang:python
          Sorry:

          398 lang:python ".setdefaul t("

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

          Bye,
          bearophile

          Comment

          Working...