Re: suggestions for improving code fragment please

Discussion in 'Python' started by Rick Johnson, Feb 28, 2013.

  1. Rick Johnson

    Rick Johnson Guest

    On Thursday, February 28, 2013 1:47:12 PM UTC-6, The Night Tripper wrote:
    > 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)


    Depends. If the length of arglist is "known" you could simply unpack it:

    a,b,c,d = (1,2,3,4)

    If the length is unknown, a while loop would do the trick. All you need is to figure out what "truth condition" to test for on each iteration of the while loop.

    while truthCondition:
    #assign variable to value
    Rick Johnson, 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. Joel Goldstick
    Replies:
    0
    Views:
    97
    Joel Goldstick
    Feb 28, 2013
  2. Ian Kelly
    Replies:
    0
    Views:
    89
    Ian Kelly
    Feb 28, 2013
  3. Tim Chase
    Replies:
    0
    Views:
    86
    Tim Chase
    Feb 28, 2013
  4. MRAB
    Replies:
    0
    Views:
    83
  5. Mitya Sirenef
    Replies:
    0
    Views:
    99
    Mitya Sirenef
    Feb 28, 2013
Loading...

Share This Page