python中的伪代码
我对python相当陌生 我得到的练习之一是为以下问题创建python伪代码:python中的伪代码,python,list,pseudocode,Python,List,Pseudocode,我对python相当陌生 我得到的练习之一是为以下问题创建python伪代码: write an algorithm that given a dictionary (list) of words, finds up to 10 anagrams of a given word. 我一直在想如何解决这个问题 目前我有(它甚至不是正确的伪) 我想这太笼统了,我在网上搜索过我可以使用的特定功能,但没有找到任何 关于特定函数的任何帮助,在生成稍微更具体的伪代码时都会有所帮助吗 这里有一些帮助,不需要
write an algorithm that given a dictionary (list) of words, finds up to 10 anagrams of a given word.
我一直在想如何解决这个问题
目前我有(它甚至不是正确的伪)
我想这太笼统了,我在网上搜索过我可以使用的特定功能,但没有找到任何
关于特定函数的任何帮助,在生成稍微更具体的伪代码时都会有所帮助吗 这里有一些帮助,不需要为您编写代码
#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
“我想这太笼统了,为什么你认为是这样?”TimCastelijns在评分部分,这是一个10分的问题,我原以为会有更多的步骤。这些步骤看起来很好。唯一看起来可疑的是第二步。也许它应该读-从单词的字母中创建所有可能的组合。除此之外,还算不错。我不想让代码为我编写,只想指出哪些函数可用于体面的psuedo代码。如上图所示,尝试使用方法
keyof
,ingestWordSet
和'getAngrams'。
#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