Question

Write a function named make_phrases(my_tags_dictionary) which takes a tags dictionary as a parameter and generates and...

Write a function named make_phrases(my_tags_dictionary) which takes a tags dictionary as a parameter and generates and prints a number of phrases using the content of the dictionary. Note: You can assume that the parameter tags dictionary only contains three tags (i.e. "DT", "JJ" and "NN").

We can generate a meaningful phrase if we start a phrase with a word which is classed as an article (i.e. a word with a 'DT' tag) followed by an adjective (i.e. a word with a 'JJ' tag) and end with a noun (i.e. a word with an 'NN' tag). For example: if the tags dictionary contains the following tag-words_list pairs:

{'JJ': ['brown'], 'NN': ['grass', 'summer'], 'DT': ['the']}

The phrases printed would be:

the brown grass
the brown summer

For example:

Test Result
tags = {'JJ': ['brown'], 'NN': ['grass', 'summer'], 'DT': ['the']}
make_phrases(tags
the brown grass
the brown summer
tags ={'JJ': ['brown', 'hot'], 'NN': ['bushes', 'days', 'grass', 'shrubs', 'summer', 'trees'], 'DT': ['the']}
make_phrases(tags)
the brown bushes
the brown days
the brown grass
the brown shrubs
the brown summer
the brown trees
the hot bushes
the hot days
the hot grass
the hot shrubs
the hot summer
the hot trees
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def make_phrases(my_tags_dictionary):
    for noun in my_tags_dictionary['DT']:
        for adjective in my_tags_dictionary['JJ']:
            for article in my_tags_dictionary['NN']:
                print(noun, adjective, article)
Add a comment
Know the answer?
Add Answer to:
Write a function named make_phrases(my_tags_dictionary) which takes a tags dictionary as a parameter and generates and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • help Question 12 (20 points) Write a function named inverse that takes a single parameter, a...

    help Question 12 (20 points) Write a function named inverse that takes a single parameter, a dictionary. In this key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. dictionary each The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course For...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT