以下返回[1]
def compact(listy):
truth_list = [t for t in listy if t == True]
return truth_list
print(compact([0,1,2,"",[], False, {}, None, "All done"]))
以下返回所需的结果,所有真值:[1、2,“全部完成”]
def compact(listy):
truth_list = [t for t in listy if t]
return truth_list
print(compact([0,1,2,"",[], False, {}, None, "All done"]))
我对为什么t == True只返回[1]感到困惑