Skip to content

Instantly share code, notes, and snippets.

@aleglez22
Created May 18, 2018 23:54
Show Gist options
  • Save aleglez22/8796740a3a9fe7362bfb5965aa70bb65 to your computer and use it in GitHub Desktop.
Save aleglez22/8796740a3a9fe7362bfb5965aa70bb65 to your computer and use it in GitHub Desktop.
class Product():
def __init__(self,name,continent,country,city):
self._name=name
self._continent=continent
self._country=country
self._city=city
def get_location(self):
return [self._continent,self._country,self._city]
def get_name(self):
return self._name
def location_objects(products):
location_array={}
for product in products:
location_array[product.get_name()]= product.get_location()
return location_array
product_list=[
Product("Baguette","Europe","France","Paris"),
Product("Pizza","Europe","Italy","Naples"),
Product("Burrito","America","Mexico","Guanajuato"),
Product("Spring Rolls","Asia","China","Hong Kong"),
]
#Example
products=location_objects(product_list)
print("The origin location of the Burritos is " + str(products["Burrito"]))
#--> The origin location of the Burritos is ['America', 'Mexico', 'Guanajuato']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment