On Jul 14, 3:35 pm, William Stein <wst...@gmail.com> wrote: > 2009/7/14 Carlos Córdoba <ccordob...@gmail.com>: > > > 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. > > That could be a function of familiarity. Quick poll -- Do you find > the following "just unreadable"? > > x = [1,2,3] > y = [2*a for a in x] > z = [b + 3 for b in y] > w = [a/max(z) for a in z] > v = [[cos(a), sin(a)] for a in w] > > ANSWER: > [ ] Yes, the above is just unreadable. > [ ] No, I can read the above just fine. It is crystal clear.
I think it's readable, but I think the issue was whether this was unreadable: [[cos(a/9), sin(a/9)] for a in [b+3 for b in [2*c for c in [1,2,3]]]] (This is using a/9 instead of a/max(z) since I don't know how to do 'max(z)' in a one-liner like this.) I think the above is not very readable, but of course you can write it as [[cos((2*a+3)/9), sin((2*a+3)/9)] for a in [1,2,3]] and it's not too bad. 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 -~----------~----~----~----~------~----~------~--~---