Lists

Daley, MarkX markx.daley at intel.com
Tue Apr 18 18:26:34 CEST 2000


This feels like a real newbie question, but here is the code that is causing
my question:

# Learning exceptions

def test():
	a = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
	print a
	b = 5
	for item in a:
		try:
			print b / a[item]
		except ZeroDivisionError:
			pass

Here is the output of this code under IDLE:

[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
5
2
1
1
1
-1
-2
-2
-3
-5

Why is the list being processed in reverse?  The exception works fine, but
the math is backwards.  I don't recall this happening before.

TIA

- Mark





More information about the Python-list mailing list