I've got the following code:
    x_sents = defaultdict(list)  
    for sent in book_xml.findall('.//s'):
        s_lang = sent.get('lang')
        if s_lang in PARSED_LANGS:
            x_sents[s_lang].append(sent)
    for lang, sents in x_sents.items():
        for sent_index, sent in enumerate(sents):
            parsed_s = parsed[lang][sent_index] 
        for index, pars_inf in enumerate(parsed_s):
            words = sent.findall('w')  
            if pars_inf[0] == '0':  
                head_id = words[int(pars_inf[0])-1].get('id')
                words[index].attrib['head'] = head_id
                words[index].attrib['deprel'] = pars_inf[1]
My problem is that sometimes, I get the error list index out of range in the line parsed_s = parsed[lang][sent_index]. How can I check that the list entry exist - and what can I insert if the index does not exist?
 
     
    