crimes in Python

Dan Schmidt dfan at harmonixmusic.com
Wed Mar 8 11:27:25 EST 2000


Michael Hudson <mwh21 at cam.ac.uk> writes:

| kragen at dnaco.net (Kragen Sitaker) writes:
| 
| > >> sys.stderr.write(join(
| > >> 	map((lambda x: 'age' + `x` + "\tsex" 
| > >> 	     + `x` + "\trace" + `x`),
| > >> 	range(1, max_suspects+1)))
| > >> 	)
| 
| Random advice: while you're learning Python, forget map exists.
| 
| This is a particularly heinous use of it, as you're using it for
| side-effects and ignoring the results.

Isn't he passing the resulting list to join()?

| I think map is occasionally useful for actually mapping a function
| over a list of inputs, but in this context it makes no sense.
| 
| > for i in range(1, max_suspects+1):
| > 	sys.stderr.write('\tage%d\tsex%d\trace%d' % (i, i, i))
| 
| This is so much better, isn't it?  I can tell at a glance what you're
| up to, whereas I couldn't really tell from your `map'.

Both the map and the explicit for are equally intelligible to me, but
I've always been a fan of a functional style.

I do agree that using map on a range (rather than a list you already
have) is kind of awkward.

-- 
Dan Schmidt | http://www.dfan.org



More information about the Python-list mailing list