"Douglas Philips" <d...@mac.com> wrote in message
news:9ee00578-6af7-4c6c-9968-af5f25a00...@mac.com...
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.
This *was* a very short script. My point was using a list comp. If you
want to nitpick, don't use lower-case L for variables either :^)
my_map = { 38: 34, 40: 39 }
def filter_item(item):
return my_map.get(item, item)
L = [filteritem(n) for n in L]
Happy?
-Mark
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor