[Python-Dev] re: list comprehension / pop quiz

Moshe Zadka Moshe Zadka <moshez@math.huji.ac.il>
Wed, 12 Jul 2000 20:26:34 +0300 (IDT)


On Wed, 12 Jul 2000 esr@thyrsus.com wrote:

> Presto! All need for parallel loops has now disappeared.  If anyone
> doubts this, I will cheerfully produce source code for with().

Ummm.....you mean

def with(*args):
	apply(map, (None,)+args)

;-)

(Actually, this isn't right, since map() adds None's instead of stopping.
But that should be a considered a design bug in map() anyway)

What would people think about xmap(), which acts anologously to xrange(),
IOW calculate lazilly instead of eagerly? Or even, calculate "on demand",
without caching:

class xmap:

	def __init__(self, func, *args):
		self.func = func
		self.args = args

	def __getitem__(self, i):
		arg = [None]*len(self.args)
		for j in range(len(self.args)):
			arg[j] = self.args[j][i]
		return apply(self.func, arg)

Wouldn't this solve the parallel iteration problem?
--
Moshe Zadka <moshez@math.huji.ac.il>
There is no GOD but Python, and HTTP is its prophet.
http://advogato.org/person/moshez