import csv
from itertools import groupby
class Destination:
def __init__(self, location, visit_year, average_cost, destination_type):
self.location = location
self.visit_year = visit_year
self.average_cost = average_cost
self.type = destination_type
def load_destinations(file_path):
destinations = []
with open(file_path, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
location = row['LOCATION'].replace(" ", "")
if len(location) > 10 and int(row['VISIT_YEAR']) > 2000:
destinations.append(Destination(row['LOCATION'], row['VISIT_YEAR'], row['AVERAGE_COST'], row['TYPE']))
return destinations
def display_grouped_destinations(destinations):
grouped_destinations = {key: list(group) for key, group in groupby(destinations, key=lambda x: x.type)}
print("\n\nGrouped Main list by TYPE (excluding 'beach'):")
for destination_type, destinations_group in grouped_destinations.items():
print(f"\nType: {destination_type}")
for destination in destinations_group:
print(f" {destination.location} - Visit Year: {destination.visit_year}")
def sort_short_locations_list(short_locations_list):
short_locations_list.sort(key=lambda x: float(x.average_cost))
print("\nSorted Short locations list based on average cost (ascending):")
for short_location in short_locations_list:
print(f"{short_location.location} - Average Cost: {short_location.average_cost}")
destinations = load_destinations('destinations.csv')
short_locations_list = [destination for destination in destinations if destination.type.lower() == 'beach']
destinations = [destination for destination in destinations if destination.type.lower() != 'beach']