[Tutor] re: range function

D-Man dsh8290@rit.edu
Wed, 23 May 2001 12:47:15 -0400


On Wed, May 23, 2001 at 06:31:32AM -1000, Doug Stanfield wrote:
...
| >>> y = range(100,100000,455)
| >>> y
| [100, 555, 1010, 1465, 1920, 2375, 2830, 3285, 3740, 4195, 4650, 5105, 5560,
| -----------snip------------
| 97470, 97925, 98380, 9883
| 5, 99290, 99745]
| >>> for counter in range(len(y)):
| ...   y[counter] = float(y[counter])/100
| ...
| >>> y
| [1.0, 5.55, 10.1, 14.65, 19.2, 23.75, 28.3, 32.85, 37.4, 41.95, 46.5, 51.05,
| -------------snip------------
| .8, 988.35, 992.9, 997.45]
| >>>

Just to see if I can write a list comprehension :

>>>y = [ x/100.0  for x in range( 100 , 100000 , 455 ) ]
>>> def p( n ) :
...     return "%.2f" % n
...
>>> print map( p , y )
['1.00', '5.55', '10.10', '14.65', '19.20', '23.75', '28.30', '32.85', '37.40',
'41.95', '46.50', '51.05', '55.60', '60.15', '64.70', '69.25', '73.80', '78.35',
 '82.90', '87.45', '92.00', '96.55', '101.10', '105.65', '110.20', '114.75', '11
9.30', '123.85', '128.40', '132.95', '137.50', '142.05', '146.60', '151.15', '15
-------------snip------------
6.50', '961.05', '965.60', '970.15', '974.70', '979.25', '983.80', '988.35', '99
2.90', '997.45']
>>>


(that 'p' function was just to truncate the output to 2 decimal
 places;  a side effect of this was to generate a list of strings,
 hence the quotes in the output)

-D