python函数中返回多个列表的合适方法

python函数中返回多个列表的合适方法,python,list,function,error-handling,Python,List,Function,Error Handling,我有一个功能: def extract_embedding_word2vec(y_text, w_e): n_run = len(y_text) y_e = [] false_index = [] sentence_index = [] for i in range(n_run): word2vec_run = [] false_index_this_run = [] senten

我有一个功能:

def extract_embedding_word2vec(y_text, w_e):
    
    n_run = len(y_text)    
    y_e = []
    false_index = []
    sentence_index = []
    
    for i in range(n_run):
        word2vec_run = []
        false_index_this_run = []
        sentence_index_this_run = []
        for j in range(len(y_text[i])):    
            if(len(y_text[i][j]) == 1):
                sentence_index_this_run.append(1)
                try:
                    word2vec_run.append(word2vec_model.wv[y_text[i][j][0].lower()])
                    false_index_this_run.append(1)
                except:
                    word2vec_run.append(word2vec_model.wv["lol"]) #fixme, until here
                    #print(y_text[i][j])
                    not_included_words.add(y_text[i][j][0].lower())
                    false_index_this_run.append(0)
                    #print("not included: %s" %y_text[i][j])
            else:
                sentence_index_this_run.append(0)
                
            
        
        y_e.append(word2vec_run)
        false_index.append(false_index_this_run)
        sentence_index.append(sentence_index_this_run)
    
    
    # Output format: list of n_run ta, each element: n_stim * n_dim_of_embedding

    print(len(y_e[0][0]))
    return (y_e, false_index, sentence_index)
此外:

然后,稍后,我这样调用这个函数:

y_e, false_index, sentence_index = extract_embedding_word2vec(y_t, w_e)
y_joined = join_list(y_sep)
f_joined = join_list[flag_sep]
s_joined = join_list[sen_sep]
它对“y_joined”很有效,但对于f_joined,我得到以下错误:

TypeError:“函数”对象不可下标

在其他一些线程中,我发现这个错误可能是由于我们将“flag_sep”定义为某个函数。。。但我在代码中搜索,发现这个变量没有新的定义/用法

在一个函数中返回几个python列表是否有合适的方法


提前感谢

您有一个括号类型的打字错误。您需要
()
而不是
[]
<代码>[]用于对iterables进行索引

请在呼叫时尝试以下操作:

f_joined = join_list(flag_sep)
s_joined = join_list(sen_sep)

您可以使用python调试器(如visual studio代码)查看返回的值并检查潜在原因。哦,这是一个错误,我没有意识到。它现在正在工作。非常感谢你。(我可以在5分钟内打上“接受标记”)
f_joined = join_list(flag_sep)
s_joined = join_list(sen_sep)