On 04/10/2012 11:28 AM, Hs Hs wrote:
> sorry I did this following, please advise if any better way exist:
>

You top-posted, so we lose the context you were using.

You never really say why you're using lists with exactly one element in
them, but presuming that the real lists consist of something like
    a = [4, "Tom Jones"]
    b = [12, "Peter Rabbit", "March Hare"]

I'll follow your convention of assuming only the zeroth element is
relevant to your 'definition of add'.

> gc = lambda x,y: x[0]+y[0]
>
> atgc = lambda x,y,k,l: x[0]+y[0]+k[0]+l[0]
>
>

No point in using lambda for that purpose.  Since you are not trying to
make it anonymous, you could simply use

def gc(x, y):
   return x[0] + y[0]

for example.

But the more interesting question is how to combine the two functions,
and make one which can take a variable number of items.


def gc(*many):
     return sum( [ x[0] for x in many ] )





-- 

DaveA

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to