From: Luigi Ballabio Date: 2001-10-11T16:34:41+09:00 Subject: [ruby-talk:22423] Re: list comprehensions alike Python ??? At 09:08 AM 10/11/01 +0900, you wrote: >On Thu, 11 Oct 2001, Paul Prescod wrote: > > > Out of curiousity, what would the Ruby for this look like: > > > > >>> arr = [x*x for x in range(0,10) if x%2==0] > > >>> arr > > [0, 4, 16, 36, 64] > > > > A combination of filter and map? > >sure: >arr = (0..10).collect{|x| x*x}.select{|x| x.even?} How about >>> l = [(x,y) for x in range(1,5) for y in range(1,5) if x+y < 5] >>> l [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (3, 1)] Bye, Luigi