[Tutor] Mappage.

Tesla Coil tescoil@irtc.net
Sun, 04 Mar 2001 07:18:46 -0500


In the spirit of "Useless Python", just thought 
I'd share an interpreter session with a couple
moments of what don't work and what does...

>>> percentages = range(1.05, 1.5, .05)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: zero step for range()

# What am I thinking?  Can't do that.

>>> percentages = range(105, 155, 5)
>>> def percentify(x):return x*.01
... 
>>> percentages = map(percentify, percentages)
>>> percentages
[1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5]

# That's what I want.  Next phase of the formula:

>>> dimensions = [33.46, 11, 5.5, 2.75]
>>> def scaleup(dims, prcnt):return dims*prnct
... 
>>> for prcnt in percentages:
...     map(scaleup, dimensions, prcnt)
... 
Traceback (innermost last):
  File "<stdin>", line 2, in ?
TypeError: argument 3 to map() must be a sequence object

# Err, gotta pass prcnt to the scaleup function.
# Wait, if I can "def percentify(x):return x*.01" ...

>>> for prcnt in percentages:
...     def scaleup(dims):return dims*prcnt
...     map(scaleup, dimensions)
... 
[35.133, 11.55, 5.775, 2.8875]
[36.806, 12.1, 6.05, 3.025]
[38.479, 12.65, 6.325, 3.1625]
[40.152, 13.2, 6.6, 3.3]
[41.825, 13.75, 6.875, 3.4375]
[43.498, 14.3, 7.15, 3.575]
[45.171, 14.85, 7.425, 3.7125]
[46.844, 15.4, 7.7, 3.85]
[48.517, 15.95, 7.975, 3.9875]
[50.19, 16.5, 8.25, 4.125]