"""
Created on Wed Oct 21 20:30:01 2026
@author: vila
"""

def Change_Dest_psgD(psgD, old, new):
    for trip in psgD.values():
        if trip[1] == old:
            trip[1] = new

def Construct_stopsD(psgD):
    solD = dict()
    for psg, trip in psgD.items():
        idn, name = psg
        lastname = name.split()[1]
        orig, dest, row, seat = trip
        if dest not in solD:
            solD[dest] = [(lastname, idn, row, seat)]
        else:
            solD[dest].append((lastname, idn, row, seat))
    return solD

def Sort_stopsD(stopsD):
    '''
    row in ascending order.
    Last name, in alphabetic order.
    Idn in ascending order.
    '''
    for psgL in stopsD.values():    
        psgL.sort(key=lambda x: (x[2], x[0], x[1]))
