On Oct 27, 2008, at 2:15 PM, cesarnda wrote: > is there a way to do that in a fancy way in pure cython?
No, the cartesian_product_iterator will still work in the context of Sage though, as will Georg's solution. If I needed to do this loop super fast for an arbitrary number of k, I might either implement it as a map ZZ -> {-2,...,2}^n and iterate over ZZ, or implement a manual "add and carry." > > On Oct 26, 4:02 pm, Georg <[EMAIL PROTECTED]> wrote: >> Hi Roland, >> >>> 2. Is there a more elegant way for: >>> for k1 in range(-2,3): >>> for k2 in range(-2,3): >>> for k3 in range(-2,3): >>> for k4 in range(-2,3): >>> for k5 in range(-2,3): >>> for k6 in range(-2,3): >>> for k7 in range(-2,3): ? >> >>> Roland >> >> if you want to stay in pure python do this: >> >> Python 2.4.4 (#2, Apr 15 2008, 23:43:20) >> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information.>>> for x in [(k1,k2) for k1 in range(-2,3) for k2 in >> range(-2,3)]: >> >> ... print x >> >> Georg > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---