Filtering Lists

Dec 01
2008

Ruby

arr = (1..10).to_a
arr.select{ |e| e % 2 != 0 }

Python

arr = range(1,11)
[e for e in arr if e % 2]

Perl

@arr = (1..10);
grep($_ % 2, @arr);

Lists and Values

Nov 30
2007

Perl

($a, $b) = (1, 2);
@arr    = (1, 2);

Python

 a, b = 1, 2
arr = 1, 
arr = 1,2

Ruby

 a, b = 1, 2
arr  = 1, 2
arr  = 1,2, *[11,22] # the same as
arr  = [1,2, [11,22]].flatten

Calendar

July 2010
M T W T F S S
« Apr    
 1234
567891011
12131415161718
19202122232425
262728293031  

Tags