On 26 June 2014 04:21, kcrisman <kcris...@gmail.com> wrote: > > >> Is there a way to only add the odd integers of a sum in Sage? > > > Do you mean something like this? > > sage: L = [1,2,3,4,5,6,7,8,9,10] > sage: L[1::2] > [2, 4, 6, 8, 10] > sage: L[0::2] > [1, 3, 5, 7, 9] > sage: sum(L[1::2]) > 30
Or perhaps this? sage: L = [1,2,3,4,5,6,7,8,9,10] sage: sum(L) 55 sage: sum([x for x in L if x%2==1]) 25 > > I didn't know about this cool feature of slice notation until looking it up > - see > http://stackoverflow.com/questions/12433695/extract-elements-of-list-at-odd-positions > > - kcrisman > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-support. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.