私は2つのpythonリストを持っています。異なる関数(TP、TN、FP、FN)を使って4つの異なる値を計算したいと思います。私が外のネストされた関数でパラメータを定義することができれば、各関数のパラメータをパラメータとして定義することなく、すべての4つの関数について同じようにパラメータを定義できます。 私は関数を実装しましたが、TP関数の出力のみを返します。誰かが私がここでの問題私は、これは機能のうち、ちょうどあなたのコードを固定するためにパラメータを共有するための最良の方法ではないと言っている同じパラメータのPythonネストされた関数
def evaluation(list1,list2):
def TP():
count1 = 0
for i in range(0,35):
if Jac_test_list[i].strip()==Simmilar_list[i].strip()=='True':
count1+=1
#return count
print ('TP count :' + str(count1))
return TP
def TN():
count2 = 0
for i in range(0,35):
if Jac_test_list[i].strip()==Simmilar_list[i].strip()=='False':
count2+=1
#return count
print ('TN count :' + str(count2))
return TN
def FP():
count3 = 0
for i in range(0,35):
if (Jac_test_list[i].strip()=='True') & (Simmilar_list[i].strip()=='False'):
count3+=1
#return count
print ('FP count :' + str(count3))
return FP
def FN():
count4 = 0
for i in range(0,35):
if (Jac_test_list[i].strip()=='False') & (Simmilar_list[i].strip()=='True'):
count4+=1
#return count
print ('FN count :' + str(count4))
return FN
ヒント: 'return'が関数を終了します。あなたの最初の 'return TP'の後には何も実行されません。 – BrenBarn
評価(list1、list2)を呼び出すと何が表示されると思いますか?あなたは例を挙げることができますか? – Allen
なぜネストされた関数を使用していますか?これはファンクションファクトリであると思われますか?しかし、 'Jac_test_list'と' Simmilar_list'を使ってクロージャを作成しています。これは私が知る限り、ローカルではありません。 –