Question
In Python 3.6 how would I do the following search if I am given the the image_info dictionary below? I know I am to use
In Python 3.6 how would I do the following search if I am given the the image_info dictionary below? I know I am to use a for loop, but I don't know how. The search term given to use would be a string that we could change to all lower(), but how would I complete the search? Please help.
Given a search term, search through the image title and image tags looking for matches. Your program should maintain a record of matches for each image. The image with the highest number of matches should be returned. If multiple images satisfy this condition, the image with the title that comes first alphabetically should be returned. For example, if the search term is cactus near a beach, your program would find 2 word matches for the image Quiet at dawn, Cabo San Lucas and 1 word match for the image View from our rental. As another example, if the search term is building in Italy, the image with the title Lombardia, september 2017 should be returned (and not Palazzo Madama). (Both images have 2 word matches.) The search should not be case sensitive.
image_info = [ { "id" : "34694102243_3370955cf9_z", "title" : "Eastern", "flickr_user" : "Sean Davis", "tags" : ["Los Angeles", "California", "building"] }, { "id" : "37198655640_b64940bd52_z", "title" : "Spreetunnel", "flickr_user" : "Jens-Olaf Walter", "tags" : ["Berlin", "Germany", "tunnel", "ceiling"] }, { "id" : "36909037971_884bd535b1_z", "title" : "East Side Gallery", "flickr_user" : "Pieter van der Velden", "tags" : ["Berlin", "wall", "mosaic", "sky", "clouds"] }, { "id" : "36604481574_c9f5817172_z", "title" : "Lombardia, september 2017", "flickr_user" : "Monica Pinheiro", "tags" : ["Italy", "Lombardia", "alley", "building", "wall"] }, { "id" : "36885467710_124f3d1e5d_z", "title" : "Palazzo Madama", "flickr_user" : "Kevin Kimtis", "tags" : [ "Rome", "Italy", "window", "road", "building"] }, { "id" : "37246779151_f26641d17f_z", "title" : "Rijksmuseum library", "flickr_user" : "John Keogh", "tags" : ["Amsterdam", "Netherlands", "book", "library", "museum"] }, { "id" : "36523127054_763afc5ed0_z", "title" : "Canoeing in Amsterdam", "flickr_user" : "bdodane", "tags" : ["Amsterdam", "Netherlands", "canal", "boat"] }, { "id" : "35889114281_85553fed76_z", "title" : "Quiet at dawn, Cabo San Lucas", "flickr_user" : "Erin Johnson", "tags" : ["Mexico", "Cabo", "beach", "cactus", "sunrise"] }, { "id" : "34944112220_de5c2684e7_z", "title" : "View from our rental", "flickr_user" : "Doug Finney", "tags" : ["Mexico", "ocean", "beach", "palm"] }, { "id" : "36140096743_df8ef41874_z", "title" : "Someday", "flickr_user" : "Thomas Hawk", "tags" : ["Los Angeles", "Hollywood", "California", "Volkswagen", "Beatle", "car"] } ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started