defmyswap(i,L):defmove(beg,step,L):
i = beg+step
t = L[beg]
while(i<len(L)):
L[i-step] = L[i]
i += step
L[i-step] = t
for i in range(i):
move(i,3,L)
return L
defGet_Count(word):
count = [0]*26for w in word:
count[ord(w)-97] += 1
ans = ''for key,item in enumerate(count):
while(item!=0):
ans += chr(key)
item -= 1;
return ans
defmyquery(obj_word,word_dict):
count = Get_Count(obj_word)
for words in word_dict:
if(count == Get_Count(words)):
print(words)
假如可以进行预处理,那么就将字典处理成一个开放散列结构,将相同的标志收集到一块来:
defpreprocess(word_dict):
New_dict = {}
for words in word_dict:
count = Get_Count(words)
if(New_dict.get(count)==None):
New_dict[count] = [words]
else:
New_dict[count].append(words)
return New_dict
defnew_query(obj_word,new_dict):return new_dict[Get_Count(obj_word)]