Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

python - Accessing an element of a list(1) contain in another list (2) which is contain in another list (1) display error : out of range

I have a list of lists ( and each list of my list contain another list). When trying to read that list, I get this error :


  File "execution/fil_test.py", line 105, in <module>
    F, M = fil_dico_tr (c, s, l_1, list_of_lexicon_tr)
  File "/home/getalp/kelodjoe/eXP/Dossier_rules/filtrage_test/filtrage_f_tr.py", line 79, in fil_dico_tr
    if w in i_lexicon[0][0][0] or w in i_lexicon[0][1][0] or w in i_lexicon[0][2][0]   :
IndexError: list index out of range

I am looking inside each list of list of list to see if the word is present but there is this error of last index.

When I print the len of each list I get the length so I do not understand why Python display "list out of range a serror' Code :

i_lexicon = [
[[liste_neg_D_g, liste_pos_D_g], [liste_neg_A, liste_pos_A], [liste_neg_P, liste_pos_P]],
[[liste_neg_A, liste_pos_A], [liste_neg_F, liste_pos_F], [liste_neg_P, liste_pos_P]], 
[[liste_neg_D_g, liste_pos_D_g], [liste_neg_F, liste_pos_F],[liste_neg_P, liste_pos_P]], 
[[liste_neg_D_g, liste_pos_D_g], [liste_neg_A, liste_pos_A],[liste_neg_F, liste_pos_F]]
]


F, M = fil_dico_tr (c, s, l_1, list_of_lexicon_tr)


v = "Je marche dans la rue et je ne sais pas mais je crois que la famille est loin de la maison"

c ="mais"
for i, j in enumerate(v):
                    if j == c:
                        liste_index_pivot.append(i)
                        
                if len(liste_index_pivot)== 0:  
                    #print(k)
                    list_sans_mais.append(k)
for w in v:
                        ind_pivot = max(liste_index_pivot)
                        #print(ind_pivot)
                        ind = v.index(w)

                        # AVANT LE CONNECTEUR                  
                        if ind < ind_pivot:
                            if w in i_lexicon[0][0][0] or w in i_lexicon[0][1][0] or w in i_lexicon[0][2][0]   :
                                d_neg_av[w] = ind - ind_v  
                            elif w in i_lexicon[0][0][1] or w in i_lexicon[0][1][1] or w in i_lexicon[0][2][1]  :
                                d_pos_av[w] = ind - ind_v
                            else:
                                d_0_av[w] = 0

                        # APRèS LE CONNECTEUR 
                        elif ind > ind_pivot:
                            if w in i_lexicon[0][0][0] or w in i_lexicon[0][1][0] or w in i_lexicon[0][2][0]   :
                                d_neg_ap[w] = ind + ind_v 
                            elif w in i_lexicon[0][0][1] or w in i_lexicon[0][1][1] or w in i_lexicon[0][2][1]  :
                                d_pos_ap[w] = ind - ind_v * 2
                            else:
                                d_0_ap[w] = 0                                        
                        else:
                            None



question from:https://stackoverflow.com/questions/66061698/accessing-an-element-of-a-list1-contain-in-another-list-2-which-is-contain-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...