import csv


def get_features_dict(file="/Volumes/external/bone_features.csv", id_name="patientID"):
    """
    Param:
        file - single csv with all features for all patients
    Returns:
        by_patientID - dictionary organized by patientID 
    """
    with open(file, encoding='utf-8-sig') as f:
        l = [row for row in csv.DictReader(f, skipinitialspace=True)] #{k: v for k, v in row.items()}
            #csv.DictReader(f) = convert file from csv to dictionary
            #l = list of dictionaries representing each row in the file
        by_patientID = {d[id_name]: d for d in l}
            #d for d in l - each dictionary in l
            #d[id_name] - patient_ID value
            #{d[id_name]: d for d in l} - dictionary with key=patientID, value=dictionary of all data for that patient
            #by_patientID = all_data organized by patientID
                #{patient1: {'PatientID':patient1, 'Age':50, 'Weight':200...},
                # patient2: {'PatientID':patient2, 'Age':67, 'Weight':143...},
                #...}
    return by_patientID