Using
[charD]*len()
as an argument tomap()
is clever, but in this context is a very poor "example of the map function" because it is so unPythonic.
In 2.4 is better (and simpler) to do:charD = dict([ (n, chr(n)) for n in range(32, 256) ])
replacing five lines (including the
import
) with one, and a simple one at that. Perhaps a better title for this snippet would be 'an example of functional programming style in Python'.
I think this is unfair: before list comprehensions became the rule, using map was considered a very pythonic way to do. You should better ask Guido Van Rossum why he didn't invent list comprehensions earlier. The language changes slowly and there is no point in reviving old snippets just to say that they are poor programming style.
Furthermore, map exists in many functional and non functional languages (lisp, ocaml, haskell, perl ...) and at a time, it sounded like a quite natural feature in python.