无法弄清楚是什么问题,我想制作一个程序,该程序需要一行字符串,并按“ In”函数中的描述返回单词及其类型。
这是代码
def __init__(self):
self.Action = "Action"
self.Noun = "Noun"
self.Shit = "Shit"
self.Error = "Error"
ACTION = ["Go","Kill","Jump"]
NOUN = ["Lion","Building","World"]
SHIT = ["shit","shit5"]
def Hard_worker(word):
Action = "Action"
Noun = "Noun"
Shit = "Shit"
Error = "Error"
raw_data = word.lower()
if raw_data in Action:
return(Action,word)
elif raw_data in Noun:
return(Noun,word)
elif raw_data in Shit:
return(Shit,word)
else:
return(Error,word)
def scan(line):
print"Scanning the line %r" % line
words = line.split()
return map(Hard_worker(words))
scan("Go Kill Jump")
任何帮助将不胜感激。
答案 0 :(得分:1)
return map(Hard_worker(words))
那不是您所说的map
。函数和迭代器必须是两个参数。
return map(Hard_worker, words)
您还可以在此处使用列表理解。
return [Hard_worker(word) for word in words]