Need help with calling function

I am wondering why when i call my last print statement at the end of my code it prints the result: ['Whats the scoop', 'Whats the scoop', 'Whats the scoop', 'Whats the scoop',], and not just once?

areas = ['Chicago', 'Boston', 'Boulder', 'L.A', 'New York']

test_person1 = ['Amber, Jesion', 'Boulder', ['Coffee', 'Double Chocolate']]

def get_area_index (area):
  get_area = areas.index(area)
  return get_area

def get_persons_area (person):
  person_area = test_person1[1]
  find_persons_area = get_area_index(person_area)
  return find_persons_area

ice_cream_shops = [[] for area in areas]

def add_shop_to_area (area, shop):
  get_area = get_area_index(area)
  shop_for_area = ice_cream_shops[get_area].append(shop)
  return shop_for_area

add_shop_to_area('Boston', ['Whats the Scoop', ['Coffee', 'Double Chocolate', 'Strawberry', 'Vanilla']])
add_shop_to_area('Chicago', ["Daffy's", ['Vanilla', 'Caramel Swirl', 'Peach', 'Black Rasberry', 'Rocky Road']])
add_shop_to_area('Boulder', ['Shoot for Scoop', ['Coffee', 'Double Chocolate', 'Strawberry', 'Rocky Road', 'Cookie Dough']])
add_shop_to_area('L.A', ['Creamy', ['Caramel Swirl', 'Peach', 'Black Rasberry', 'Rocky Road', 'Cookie Dough']])
add_shop_to_area('New York', ['Cold Cabin', ['Coffee', 'Double Chocolate', 'Rocky Road', 'Cookie Dough']])
add_shop_to_area('New York', ['The Ice Cream Shop', ['Vanilla']])

def find_shop_in_area(area, flavors):
  get_area = get_area = get_area_index(area)
  shops_in_area = ice_cream_shops[get_area]
  shops_with_flavors = [] 
  for shops in shops_in_area:
    possible_shops = shops
    shop_tags = shops[1]
    for flavor in flavors:
      if flavor in shop_tags:
  return shops_with_flavors

print(find_shop_in_area('Boston', ['Coffee', 'Double Chocolate', 'Strawberry', 'Vanilla']))

Hey @array9835545496

To answer your question - look at what you’re doing in your function find_shop_in_area, specifically when you’re iterating over the flavours you’re passing in…

for flavor in flavors:
  if flavor in shop_tags:

You’re not checking whether you’ve already suggested the shop, hence when “What’s the Scoop” matches each of the four flavours you’re looking for your function appends it to shops_with_flavors 4 times.

You could add a second condition to your if to check whether the current shop has already been suggested. :slight_smile: