1 / 4

Working with Dictionaries

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' :

tuari
Download Presentation

Working with Dictionaries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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.

  3. 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)

  4. 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)

More Related