def get_long_id(list_session_id):
    """Extract longitudinal ID from a set of session IDs.

    This will create a unique identifier for a participant and its corresponding sessions. Sessions labels are sorted
    alphabetically before being merged in order to generate the longitudinal ID.

    Args:
        list_session_id (list[str]): List of session IDs
            (e.g. ["ses-M00"] or ["ses-M00", "ses-M18", "ses-M36"])

    Returns:
        Longitudinal ID (str)

    Example:
        >>> from clinica.utils.longitudinal import get_long_id
        >>> get_long_id(['ses-M00'])
        'long-M00'
        >>> get_long_id(['ses-M00', 'ses-M18', 'ses-M36'])
        'long-M00M18M36'
        >>> get_long_id(['ses-M18', 'ses-M36', 'ses-M00']) # Session IDs do not need to be sorted
        'long-M00M18M36'
    """
    sorted_list = sorted(list_session_id)
    list_session_label = [session_id[4:] for session_id in sorted_list]
    long_id = "long-" + "".join(list_session_label)

    return long_id