def check(temp):
for i in temp:
if type(i) == str:
temp.remove(i)
temp = ['a', 'b']
print(temp) ==> Output: ['a','b']
check(temp)
print(temp) ==> Output: ['b']
溫度=運行[ '一個',1],輸出爲[1]
溫度= [1, 'A', 'b', 'C',2],輸出爲[1, 'b',2]
可能有人關心解釋結果是如何評估..日Thnx
+1打我給它 –
@Aशwiniचhaudhary沒有理由,還不如用一個列表理解,我猜我剛剛寫了很多生成器表達式。 – msvalkon
@eryksun一個天真的ipython'%timeit'測試這兩個函數的列表〜200k元素顯示〜3-5 ns的差異。雖然速度較慢,但有一半時間似乎過於誇張,除非我的計劃錯誤。 – msvalkon