Given a string, find the lexical sequence:
import math
def num(word):
length=len(word)
ans=math.factorial(length)
wordset=set(word)
for letter in wordset:
fre=word.count(letter)
ans=ans/fre
return ans
def get_ranks( words):
if len(words)==1:
return 0
setwords=set(words)
listwords=list(setwords)
listwords.sort()
prenumber=0
head=words[0]
seq=listwords.index(head)
for i in range(seq):
absent=listwords[i]
k=words.index(absent)
prenumber+=num(words[0:k]+words[k+1:])
return prenumber+get_ranks(words[1:])