On Thu, Sep 29, 2005 at 05:17:21PM +1000, Erik de Castro Lopo wrote:
[...]
>
> Even Python has a better version (although not as nice as O'Caml)
> of this:
>
> integer_array = [ 1, -2, 3, -4, 5, -6, -7, 8, -9, 32727000]
>
> for k in range (len (integer_array)):
> print "integer [%d] = %d" % (k, integer_array [k])
Python can be nicer than that:
integer_array = [1, -2, 3, -4, 5, -6, -7, 8, -9, 32727000]
for index, value in enumerate(integer_array):
print "integer [%d] = %d" % (index, value)
You could also use the map function (or something similar from the itertools
module) if you really want, but it's a bit more awkward and doesn't really
enhance readability or correctness at all in this case.
-Andrew.
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html