Skip to content

Instantly share code, notes, and snippets.

@gonzalovazquez
Created May 24, 2019 15:45
Show Gist options
  • Save gonzalovazquez/b95d552de116758796ab744880805568 to your computer and use it in GitHub Desktop.
Save gonzalovazquez/b95d552de116758796ab744880805568 to your computer and use it in GitHub Desktop.
Recommendation Engine with Python
destinations = [
"Paris, France",
"Shanghai, China",
"Los Angeles, USA",
"São Paulo, Brazil",
"Cairo, Egypt"
]
attractions = [
[]
for destination in range(len(destinations))
]
test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]
def get_destination_index(destination):
destination_index = destinations.index(destination)
return destination_index
def get_traveler_location(traveler):
traveler_destination = traveler[1]
traveler_destination_index = get_destination_index(traveler_destination)
return traveler_destination_index
def add_attraction(destination, attraction):
try:
destination_index = get_destination_index(destination)
attractions_for_destination = attractions[destination_index]
attractions_for_destination.append(attraction)
return attractions_for_destination
except ValueError:
print("Destination is not supported")
return
def find_attractions(destination, interests):
destination_index = get_destination_index(destination)
attractions_in_city = attractions[destination_index]
attractions_with_interest = []
for temp_attractions in attractions_in_city:
possible_attraction = temp_attractions
attraction_tags = temp_attractions[1]
for interest in interests:
if interest in attraction_tags:
attractions_with_interest.append(possible_attraction[0])
return attractions_with_interest
def get_attractions_for_traveler(traveler):
traveler_destination = traveler[1]
traveler_interest = traveler[2]
traveler_attractions = find_attractions(traveler_destination, traveler_interest)
interests_string = ""
for attraction in traveler_attractions:
interests_string += attraction + ' , '
print("Hi "+ traveler[0] + ", we think you'll like these places around" + traveler_destination + ": the " + interests_string + ".")
# result = get_destination_index("Paris, France)
# test_destination_index = get_traveler_location(test_traveler)
add_attraction('Los Angeles, USA', ['Venice Beach', ['beach']])
add_attraction("Paris, France", ["the Louvre", ["art", "museum"]])
add_attraction("Paris, France", ["Arc de Triomphe", ["historical site", "monument"]])
add_attraction("Shanghai, China", ["Yu Garden", ["garden", "historcical site"]])
add_attraction("Shanghai, China", ["Yuz Museum", ["art", "museum"]])
add_attraction("Shanghai, China", ["Oriental Pearl Tower", ["skyscraper", "viewing deck"]])
add_attraction("Los Angeles, USA", ["LACMA", ["art", "museum"]])
add_attraction("São Paulo, Brazil", ["São Paulo Zoo", ["zoo"]])
add_attraction("São Paulo, Brazil", ["Pátio do Colégio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])
# print(attractions)
# la_arts = find_attractions("Los Angeles, USA", ["art"])
# print(la_arts)
get_attractions_for_traveler(['Dereck Smill', 'Paris, France', ['monument']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment