Some thougts on cartesian products

Christoph Zwerschke cito at
Sun Jan 22 19:51:32 CET 2006

Generally, if you could multiply strings in the above fashion, you could 
spare one more more sub loops, as in this example:

for f in ('index', 'default')*('.html', '.htm', '.shtml'):
	if exists(f):

In this case, it would be not really be better than that:

for f in 'index', 'default':
	for e in '.html', '.htm', '.shtml':
		if exists(f+e):

The password cracking was already a better example.

But this would be only efficient if the product of two strings is 
returned as a generator, not a list. And I don't know if you really 
would expect that, since multiplying a string or a list with a number 
does not change its type.

-- Christoph

More information about the Python-list mailing list