[Tutor] Re: A small aftermath [recreational Python]
Gregor Lingl
glingl@aon.at
Mon, 7 Jan 2002 21:08:40 +0100
As I now observed, that
>>> teresl('mammamia')
['amaimamm', 'amaamimm', 'amiamamm', 'imaamamm']
runs nearly 5000 times(!) as fast as
>>> uniq([x for x in permIter("mammamia")
if isFixedLetterRearrangement(x,
"mammamia")])
['amaimamm', 'amaamimm', 'imaamamm', 'amiamamm']
I suppose, the reason for this may be, that the teresl-program
doesn't need to perform any comparisons of found candidates
with the original input-word. Instead in case that there is no
more letter found fitting to a given position, the search-space
is - sometimes (mammamia!) severely - cut!
This conjecture may be supported by the fact that in case of
no repetitions
>>> len(teresl('abcdefgh'))
14833
runs only less than 5 times as fast as the corresponding uniq - call
Gregor