the python way?
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Thu Jun 16 10:36:44 EDT 2005
On Mon, 06 Jun 2005 14:52:04 -0400, rumours say that Kent Johnson
<kent37 at tds.net> might have written:
>def newZip(a1,a2):
> """ reassemble """
> l1=len(a1)
> l2=len(a2)
> longest, shortest = [[a1,a2], [a2,a1]][l1<l2]
<snip>
Other ways to write the last line:
----------------------------------
/a/ execution in 22.5% of the original time taken
longest, shortest = l1 < l2 and (a2,a1) or (a1,a2)
/b/ execution in 12.5% of the original time taken
if l1 < l2: longest, shortest= a2, a1
else: longest, shortest= a1, a2
/c/ execution in 6.5% of the original time taken
if l1 < l2: longest= a2; shortest= a1
else: longest= a1; shortest= a2
Another exotic way to write the last *three* lines, running in 228.7% of
the original time:-)
shortest, longest=sorted([a1,a2], key=len)
Numbers from 2.4c1 on a Pentium-M running at 600 MHz (battery powered).
Suggestion /a/ has the advantage of no repetion of the names like the
original line.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
More information about the Python-list
mailing list