Thanks John, I'd seen Python comprehensions before, but since I was trying to do all in a one-liner, I think I overlooked your elegant and simple solution. One comprehension at a time is quite neat, but several is just unreadable.
On Tue, Jul 14, 2009 at 4:28 PM, John H Palmieri <jhpalmier...@gmail.com>wrote: > > > > On Jul 14, 1:52 pm, Carlos Córdoba <ccordob...@gmail.com> wrote: > > Sorry for not answering before, I've being a bit busy. I'll try to give a > > concrete example of what I'm trying to do so you can understand me > better. > > I have a list of real numbers, for example > > > > [1,2,3] > > Python "list comprehensions" might be what you want -- see > <http://docs.python.org/tutorial/datastructures.html#list- > comprehensions> > > > I want to multiply by 2 to get > > > > [2,4,6] > > sage: x = [1,2,3] > sage: y = [2*a for a in x] > > > the to sum it to 3 > > > > [5,7,9] > > sage: z = [b + 3 for b in y] > > > then divide by the max number > > > > [5/9, 7/9, 1] > > sage: w = [a/max(z) for a in z] > > > then convert every point to a point in the circle with > > > > [[cos(5/9), sin(5/9)], [cos(7/9), sin(7/9)], [cos(1), sin(1)]] > > sage: v = [[cos(a), sin(a)] for a in w] > > > Is that helpful at all? > > John > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---