[Tutor] mapping/filtering a sequence

Douglas Philips dgou at mac.com
Sat Sep 5 18:54:54 CEST 2009


On 2009 Sep 5, at 12:22 PM, Mark Tolonen wrote:
> As a list comp:
>
>>>> L=range(30,41)
>>>> [{38:34,40:39}.get(n,n) for n in L]
> [30, 31, 32, 33, 34, 35, 36, 37, 34, 39, 39]


True, that is terse, but IMHO has maintainability issues. The mapping  
data structure and the method of transformation (.get()) are tangled  
in with the transformation itself.
Again, IMHO, unless this is a very short script, the maintenance  
should outweigh raw terseness.

-Doug



More information about the Tutor mailing list