Re: suggestions for improving code fragment please

Discussion in 'Python' started by Ian Kelly, Feb 28, 2013.

  1. Ian Kelly

    Ian Kelly Guest

    On Thu, Feb 28, 2013 at 12:47 PM, The Night Tripper <> wrote:
    > Hi there
    > I'm being very dumb ... how can I simplify this fragment?
    >
    >
    > if arglist:
    > arglist.pop(0)
    > if arglist:
    > self.myparm1 = arglist.pop(0)
    > if arglist:
    > self.myparm2 = arglist.pop(0)
    > if arglist:
    > self.myparm3 = arglist.pop(0)
    > if arglist:
    > self.parm4 = arglist.pop(0)


    Perhaps this would work for you:

    if arglist:
    defaults = [self.parm1, self.parm2, self.parm3, self.parm4]
    arglist = arglist[1:] + defaults[len(arglist)-1:]
    self.parm1, self.parm2, self.parm3, self.parm4 = arglist[:4]
     
    Ian Kelly, Feb 28, 2013
    #1
    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. Rick Johnson
    Replies:
    0
    Views:
    105
    Rick Johnson
    Feb 28, 2013
  2. Joel Goldstick
    Replies:
    0
    Views:
    112
    Joel Goldstick
    Feb 28, 2013
  3. Tim Chase
    Replies:
    0
    Views:
    99
    Tim Chase
    Feb 28, 2013
  4. MRAB
    Replies:
    0
    Views:
    100
  5. Mitya Sirenef
    Replies:
    0
    Views:
    115
    Mitya Sirenef
    Feb 28, 2013
Loading...

Share This Page