array of objects

Moshe Zadka moshez at zadka.site.co.il
Mon Jan 1 13:26:43 EST 2001


On Sun, 31 Dec 2000, "Daniel Klein" <DanielK at aracnet.com> wrote:

> How then is list comprehension 

Which means, 

obj = [test() for x in range(N)]

> different (and/or better) than say:
> 
> obj = []
> for x in range(N): obj.append(test())

Well, a lot of people here seem to think it's more readable. It may
be more efficient in the future too. For me, the killer advantage is

def tests(N):
	return [test() for x in range(N)]

vs.

def test(N):
	obj = []
	for x in rnage(N):
		obj.append(test())
	return obj

look-ma-no-variables-ly y'rs, Z.
-- 
Moshe Zadka <sig at zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!




More information about the Python-list mailing list