enumerate improvement proposal

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Holden

    #16
    Re: enumerate improvement proposal

    James Stroud wrote:
    Diez B. Roggisch wrote:
    >
    >>>Okay, I've googled "leaky abstractions" (as was probably your intended
    >>>affect with your silence), read the famous essay, and still
    >>>don't know what you mean and how it applies to what I have described.
    >>>
    >>>Do you plan to justify your statement or emptily accuse people of
    >>>violating
    >>>esoteric principles?
    >>
    >>
    >>While I can't claim to know what the effbot thinks (the
    >>skull-socks-wearing-python-coder-mindlink-technology is yet to be
    >>developed), I think it's pretty clear what he is after here:
    >>
    >>Computers compute offsets into data zero-based. Some languages like
    >>pascal completely abstract that away from the user, but python doesn't.
    >>
    >>So if your colleague/boss/whatever insists on indices being one-based,
    >>this abstraction you introduced for her pretty fast leaks pretty badly.
    >>Consider this simple example:
    >>
    >>for offset, item in enumerate(some_ list, start=1):
    > if item.is_the_cho sen_one():
    > chosen_one_offs et = offset
    >>
    >>the_chosen_on e = some_list[chosen_one_offs et]
    >>
    >>And bang, its Judas not Petrus who gets the pearly gates inc. stock
    >>options.
    >>
    >>Diez
    >
    >
    Thank you for this explanation. Very illuminating. I think understand
    this idea well and the thought of 1 basing this function makes me cringe
    as much as the next guy (though I lacked the vocabulary to explain
    exactly why I cringe).
    >
    But you see, weaning this university faculty level economist (who
    already has her own way of doing everything...an d to whom I happen to be
    married) from the traditional economics tools of gauss and sas towards
    the more sane and flexible tools of python, numarray, and rpy has been a
    multi-stage process. Tweaking the chosen abstractions to not be as leaky
    (thank you and thank Fredrik for introducing me to this vocabulary) is
    still one of the things I'm working towards. I want to solidify the
    conversion before I concentrate on nuance.
    >
    So, before too much criticism, I challenge even the most skilled python
    programmer to find his or her own faculty economist (or statistician or
    physicist) and get them to radically change their computational tools.
    When you've walked a mile in my shoes, leaky abstractions won't seem
    like such a big deal after all.
    >
    Divorce is obviously the only answer. How could you end up marrying
    someone who counts from one and not zero? ;-)

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • James Stroud

      #17
      Re: enumerate improvement proposal

      Steve Holden wrote:
      How could you end up marrying
      someone who counts from one and not zero? ;-)
      She's the only other person I've ever met who used vi key binding at the
      command line.

      James


      --
      James Stroud
      UCLA-DOE Institute for Genomics and Proteomics
      Box 951570
      Los Angeles, CA 90095


      Comment

      • Mark Elston

        #18
        Re: enumerate improvement proposal

        * James Stroud wrote (on 10/30/2006 4:39 PM):
        Steve Holden wrote:
        >How could you end up marrying someone who counts from one and not
        >zero? ;-)
        >
        She's the only other person I've ever met who used vi key binding at the
        command line.
        >
        James
        >
        >
        Well, there's your problem. You need to C-x C-f a new mate. :)

        Mark
        (Emacs rules)

        Comment

        • Ben Finney

          #19
          Re: enumerate improvement proposal

          Mark Elston <m.elston@advan test-ard.comwrites:
          * James Stroud wrote (on 10/30/2006 4:39 PM):
          She's the only other person I've ever met who used vi key binding
          at the command line.
          >
          Well, there's your problem. You need to C-x C-f a new mate. :)
          I don't have the commitment for that. What if I were to C-x C-v
          a few different ones instead?

          --
          \ "If you continue running Windows, your system may become |
          `\ unstable." -- Microsoft, Windows 95 BSOD message |
          _o__) |
          Ben Finney

          Comment

          • Paddy

            #20
            Re: enumerate improvement proposal


            James Stroud wrote:
            Steve Holden wrote:
            How could you end up marrying
            someone who counts from one and not zero? ;-)
            >
            She's the only other person I've ever met who used vi key binding at the
            command line.
            >
            Wow. Now I see!

            It's only Python. Just add one to indices where appropriate, buy her
            chocolates. Don't say a thing when you squelch your seventh off-by-one
            error. Look interested in the shoe store. (even for the fifth shoe, of
            the third store). - *Your partner does vi*

            Whoa!

            - Paddy :-)

            Comment

            • Steven D'Aprano

              #21
              Re: enumerate improvement proposal

              On Mon, 30 Oct 2006 23:42:16 +0000, Steve Holden wrote:
              Divorce is obviously the only answer. How could you end up marrying
              someone who counts from one and not zero? ;-)

              "Should array indices start at 0 or 1? My compromise of 0.5 was rejected
              without, I thought, proper consideration." (Stan Kelly-Bootle)


              --
              Steven.

              Comment

              • Raymond Hettinger

                #22
                Re: enumerate improvement proposal

                James Stroud wrote:
                I think that it would be handy for enumerate to behave as such:
                >
                def enumerate(itrbl , start=0, step=1):
                i = start
                for it in itrbl:
                yield (i, it)
                i += step
                I proposed something like this long ago and Guido has already rejected
                it. Part of the reason is that it doesn't match his mental model of
                enumerate being about pairing sequence elements with their indices.
                Another reason is that the syntax has more than one obvious
                interpretation:

                enumerate('abcd ef', 2) -- (2, 'c'), (3, 'd'), ...
                enumerate('abcd ef', 2) -- (0, 'c'), (1, 'd'), ...
                enumerate('abcd ef', 2) -- (2, 'a'), (2, 'b'), ...

                Also, the order of arguments is odd in comparison with the output order
                -- this suggests a syntax like enumerate(2, 'abcdef') --(2, 'a'), (3,
                'b') ...

                FWIW, it is not hard to roll-your-own with something like:

                for pagenum, page in izip(count(1), book): ...

                The izip/count combination runs at C speed, matches enumerate() in its
                efficiency, and is arguably clearer in expressing its intended
                behavior.


                Raymond

                Comment

                Working...