There's got to be an easy way to do this

John Machin machin_john_888 at hotmail.com
Fri Jul 6 08:10:24 EDT 2001


Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.994359729.14667.python-list at python.org>...
> Ooh!  A performance thread!  This function is about one-third better than
> str_join.
> 
>     def str_join2(iters):
> 	has = {0:1,1:1,2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1}.has_key
> 	for i in iters:
> 	    "".join([x for x in '(123)/456-7890' if has(x)])
> 
> :-)

The arguments to has() will be strings of unit length. The keys in the
dictionary are integers. has_key() will always return false. The
join() will have very little to do. A very clever peep-hole optimiser
could perhaps replace the last line with '""', then proceed to replace
the whole function body with 'pass'. Is there a peep-hole optimiser
guru in the house?



More information about the Python-list mailing list