我是python的新手
我给出的一个练习是为以下问题创建python伪代码:
write an algorithm that given a dictionary (list) of words, finds up to 10 anagrams of a given word.
我一直坚持如何解决这个问题。
目前我有(它甚至不适合伪)
# Go through the words in the list
# put each letter in some sort of array
# Find words with the letters from this array
我想这太笼统了,我已经在网上搜索了我可以使用的具体功能,但还没找到。
有关特定功能的任何帮助,有助于制作稍微更具体的伪代码吗?
答案 0 :(得分:1)
以下是一些帮助,无需为您编写代码
#define a key method
#determine the key using each set of letters, such as the letters of a word in
#alphabetical order
#keyof("word") returns "dorw"
#keyof("dad") returns "add"
#keyof("add") returns "add"
#ingest the word set method
#put the word set into a dictionary which maps
#key->list of up to 10 angrams
#get angrams method
#accept a word as a parameter
#convert the word to its key
#look up the key in the dictionary
#return the up to 10 angrams
#test case: add "dad" and "add" to the word set.
# getting angrams for "dad" should return "dad" and "add"
#test case: add "palm" and "lamp" to the word set.
# getting angrams for "palm" should return "palm" and "lamp"
#consider storing 11 angrams in the list
#a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11.
#Then if a01 is provided, you can return a02-a11, which is 10 angrams