Matthew Woodcraft <[EMAIL PROTECTED]> writes:
> How do you transform this?
>
> height = 0
> for block in stack:
> if block.is_marked():
> print "Lowest marked block is at height", height
> break
> height += block.height
> else:
> raise SomeError("No marked block")
Untested:
all_heights = [block.height for block in stack if block.is_marked()]
if all_heights:
height = sum(all_heights)
else:
raise SomeError("No marked block")
Alternatively (lower memory usage for large list):
all_heights = (block.height for block in stack if block.is_marked())
try:
height = all_heights.next()
height += sum(all_heights)
except StopIteration:
raise SomeError("No marked block")
--
http://mail.python.org/mailman/listinfo/python-list