Stackless 3.0 alpha 1 at blinding speed
anton at vredegoor.doge.nl
Sun Apr 20 17:42:24 CEST 2003
"A.M. Kuchling" <amk at amk.ca> wrote:
Thanks. It seems Tim is making a heroic effort to explain the new in
terms of the old. This necessarily must fail, but what other option is
there instead of rebuilding all terminology out of gotos?
By the way, I have a hunch the anagram script below is somehow related
to the operations described, since the script "changes directions"
depending on the order the lists items are popped. A simple
permutation could just do a series of divmods.
If not, please excuse me, it's just a natural defensive reaction to
try to hold of the unknown with the shield of the known. In fact
knowledgeable people are welcome to hide behind *my* ignorance :-)
#anagram.py by Anton Vredegoor anton at vredegoor.doge.nl Apr 20, 2003
Starters(L) returns a 2-tuple for each *different* item
in the list L:
a) the index of the first occurrence of the item,
b) the number of anagrams starting with this item.
The function starters is used by the function anagram to
construct indexed anagrams of a list.
#return a list of 2-tuples containing info about list L
n,np,R = len(L),1,range(len(L))
bf = [L[:i].count(L[i]) for i in R]
for i in R: np = np*(n-i)/(bf[i]+1)
return [(i,np*L[i:].count(L[i])/n) for i in R if not bf[i]]
#return an anagram of list L
remain, res, T = index, , L[:]
for j,k in starters(T):
if remain-k < 0:
remain -= k
#return the number of possible anagrams of list L
return reduce(lambda a,b:a+b,[k for j,k in starters(L)])
L = [,,,]
np = nperm(L)
for i in range(np):
print '%2i %s' %(i,anagram(L,i))
More information about the Python-list