40 likes | 506 Views
Working with Dictionaries. def reply (sentence): """Returns a reply to the sentence.""” if 'mom' or 'work' or 'died' in sentence.split(): for word in sentence.split(): if word == 'mom' : return random.choice(keywords.get( 'mom' )) if word == 'work' :
E N D
Working with Dictionaries def reply(sentence): """Returns a reply to the sentence.""” if'mom'or'work'or'died'in sentence.split(): for word in sentence.split(): if word == 'mom': return random.choice(keywords.get('mom')) if word == 'work': return random.choice(keywords.get('work')) if word == 'died': return random.choice(keywords.get('died')) probability = random.randint(0, 3) if probability == 0: return random.choice(hedges)) etc.
Working with Dictionaries def reply(sentence): """Returns a reply to the sentence.""” probability = random.randint(0, 3) if probability == 0: return random.choice(hedges)) elif probability == 1: return getKeywordResponse(sentence) etc.
Working with Dictionaries def getKeywordResponse(sentence): """Returns a keyword response to the sentence.""” if'mom'or'work'or'died'in sentence.split(): for word in sentence.split(): if word == 'mom': return random.choice(keywords.get('mom')) if word == 'work': return random.choice(keywords.get('work')) if word == 'died': return random.choice(keywords.get('died')) return reply(sentence)
Working with Dictionaries def getKeywordResponse(sentence): """Returns a keyword response to the sentence.""” for word in sentence.split(): if word in keywords: return random.choice(keywords.get(word)) return reply(sentence)