Fw: Undeliverable Message

Discussion in 'Python' started by Matthew_WARREN@bnpparibas.com, Jan 25, 2008.

  1. Guest

    Hallo pyPeople,

    I wrote a little snippet of code that takes a list representing some
    'digits', and according to a list of symbols, increments the digits through
    the symbol list.

    so for example,

    digits=["a","a","a"]
    symbols=["a","b","c"]


    increment(digits,symbols) repeatedly would return digits as

    aab
    aac
    aba
    abb
    abc
    aca


    etc..

    Heres the code

    def increment(digits,symbols):
    overflow=True
    digitpos=-1
    while overflow and -digitpos<=len(digits):
    digitsymbolindex=symbols.index(digits[digitpos])
    if digitsymbolindex==len(symbols)-1:
    overflow=True
    digits[digitpos]=symbols[0]
    digitpos=digitpos-1
    else:
    digits[digitpos]=symbols[digitsymbolindex+1]
    overflow=False
    return digits



    Now, this works. All good. It's nice and simple. I'm just wondering how
    anyone else might approach it?


    Matt.


    This message and any attachments (the "message") is
    intended solely for the addressees and is confidential.
    If you receive this message in error, please delete it and
    immediately notify the sender. Any use not in accord with
    its purpose, any dissemination or disclosure, either whole
    or partial, is prohibited except formal approval. The internet
    can not guarantee the integrity of this message.
    BNP PARIBAS (and its subsidiaries) shall (will) not
    therefore be liable for the message if modified.
    Do not print this message unless it is necessary,
    consider the environment.

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

    Ce message et toutes les pieces jointes (ci-apres le
    "message") sont etablis a l'intention exclusive de ses
    destinataires et sont confidentiels. Si vous recevez ce
    message par erreur, merci de le detruire et d'en avertir
    immediatement l'expediteur. Toute utilisation de ce
    message non conforme a sa destination, toute diffusion
    ou toute publication, totale ou partielle, est interdite, sauf
    autorisation expresse. L'internet ne permettant pas
    d'assurer l'integrite de ce message, BNP PARIBAS (et ses
    filiales) decline(nt) toute responsabilite au titre de ce
    message, dans l'hypothese ou il aurait ete modifie.
    N'imprimez ce message que si necessaire,
    pensez a l'environnement.
     
    , Jan 25, 2008
    #1
    1. Advertising

  2. On Jan 25, 5:05 am, wrote:
    > Hallo pyPeople,
    >
    > I wrote a little snippet of code that takes a list representing some
    > 'digits', and according to a list of symbols, increments the digits through
    > the symbol list.
    >
    > so for example,
    >
    > digits=["a","a","a"]
    > symbols=["a","b","c"]
    >
    > increment(digits,symbols) repeatedly would return digits as
    >
    > aab
    > aac
    > aba
    > abb
    > abc
    > aca
    >
    > etc..
    >
    > Heres the code
    >
    > def increment(digits,symbols):
    >         overflow=True
    >         digitpos=-1
    >         while overflow and -digitpos<=len(digits):
    >                 digitsymbolindex=symbols.index(digits[digitpos])
    >                 if digitsymbolindex==len(symbols)-1:
    >                         overflow=True
    >                         digits[digitpos]=symbols[0]
    >                         digitpos=digitpos-1
    >                 else:
    >                         digits[digitpos]=symbols[digitsymbolindex+1]
    >                         overflow=False
    >         return digits
    >
    > Now, this works. All good. It's nice and simple.  I'm just wondering how
    > anyone else might approach it?


    I (not an expert at all) have only minor comments and one question:
    comments:
    why keep setting overflow to True, if you do not touch it will not
    change.
    digitpos -= 1 is easier to read in my mind
    question:
    Why first extract the indices and then compare (in your if statement),
    and
    why do you not just compare the symbols?

    Best,
    Bart
     
    Bart Kastermans, Jan 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. himgi
    Replies:
    5
    Views:
    6,291
    Roedy Green
    Mar 10, 2006
  2. System Administrator

    Undeliverable: Re: Movie

    System Administrator, Jul 1, 2003, in forum: Python
    Replies:
    0
    Views:
    410
    System Administrator
    Jul 1, 2003
  3. Postmaster

    Undeliverable Mail

    Postmaster, Jul 3, 2003, in forum: Python
    Replies:
    0
    Views:
    350
    Postmaster
    Jul 3, 2003
  4. Mail Delivery Subsystem

    Message Undeliverable!

    Mail Delivery Subsystem, Feb 10, 2004, in forum: Python
    Replies:
    0
    Views:
    287
    Mail Delivery Subsystem
    Feb 10, 2004
  5. Replies:
    0
    Views:
    280
Loading...

Share This Page