NEWBIE: map | zip | list comp

MetalOne jcb at
Sat Jan 3 23:06:58 CET 2004

The following produces the same result but in a 2 dimensional list. 
However, it is darn near impossible to read.

print map(lambda x: 
    map(lambda (c1,c2): 
    map(lambda ix: (c1*length)[:ix]+c2+(c1*length)[ix:-1], range(length)),
    filter(lambda (c,d): c!=d, map(lambda y: (x,y), base_seq))), base_seq)

for base_seq = "ABCD"
The (x,y) pairs produced are
(A,A), (A,B), (A,C), (A,D),
(B,A), (B,B), (B,C), (B,D), ...

The filter removes the duplicate pairs (A,A),(B,B),(C,C),(D,D)

for (c1,c2) in [(A,B), (A,C), (A,D)] the rotation function gets applied.

More information about the Python-list mailing list