def add_flight(list_of_flights,code,duration,dep_city,dest_city):
    """
    :params:
        list_of_flights - list[dict...]
        code - str
        duration - int
        dep_city - str
        dest_city - str
    :return:  
        None
    The function takes in a list of flights and the code, duration, departure city and destination city of a flight
    It then checks if there exists already a flight with the same code as the one introduce, if so raises a ValueError
    Else it append a new flight as a dictionary into the list_of_flights list
    """
    for flight in list_of_flights:
        if flight["code"]==code:
            raise ValueError
    flight={
            "code":code,
            "duration":duration,
            "dep_city":dep_city,
            "dest_city":dest_city
        }
    list_of_flights.append(flight)

def modify_flight(list_of_flights,code,new_duration):
    for flight in list_of_flights:
        if flight["code"]==code:
            flight["duration"]=new_duration
            return
    raise ValueError

def reroute_flight(list_of_flights,dest_city,new_dest_city):
    for flight in list_of_flights:
        if flight["dest_city"]==dest_city:
            flight["dest_city"]=new_dest_city

def show_flight(list_of_flights,dep_city):
    new_flights = [flight for flight in list_of_flights if flight["dep_city"]==dep_city]
    return sorted(new_flights,key=get_duration)

def print_nicely(flight):
    print("Code: {} | Duration: {} | Departure City: {} | Destination City: {} \n".format(flight["code"],flight["duration"],flight["dep_city"],flight["dest_city"]))

def get_duration(flight):
    return flight["duration"]