On Tue, Apr 10, 2012 at 11:22 AM, Hs Hs <ilhs...@yahoo.com> wrote: > Hi: > > I have 4 lists: > > >>> a > [40] > >>> b > [2] > >>> c > [23] > >>> d > [12] > > > how is it possible to do add elements in list. I can do this using > tupples, but I do not know how to append elements to tuple, thats the > reason I am using list. > > I want to find the value of a+c/a+b+c+d - which is 40+23/40+2+23+12. > > Any help appreciated. > > thanks > Hs. > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > In python, the '+' operator when applied to lists will concatenate the lists together. So:
>>> a = [1] >>> b = [2] >>> print a+b [1,2] the 'sum' function in python can be used on lists. >>> a = [1] >>> b = [2] >>> print sum(a+b) 3
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor