def set_train_data(i,d,key=b"answered"):
    global train
    #------------------------------------    
    if not data_types.has_key(key):
        raise ValueError("Key "+str(key)+" unknown")
    if not train.has_key(i) or train[i] is None:
        train[i]={}
    if not type(d)  is data_types[key]:
        raise TypeError("Data - %s - for key "% d +str(key)+" must be " +str(data_types[key])+ " but it is "+ str(type(d)))
    #------------------------------------
    train[i][key]=d

        
def store_training_data(i, d,key=b"answered"):
    set_train_data(i,d,key)
    with open("data.yml","w") as file:
        file.write(yaml.dump(train,default_flow_style=True))
        file.close()
                  

def in_training(i, key="answered"):
    return train.has_key(i) and train[i].has_key(key)
data_types= { "answered": bool, "maintopic": str, "lang": str}
