Created
May 18, 2018 23:54
-
-
Save aleglez22/8796740a3a9fe7362bfb5965aa70bb65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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