使ç¨filteræ¥å®ç°ï¼ä»¥python3为ä¾ï¼å¦æå é¤å表ä¸çææ0ï¼åå¯ä½¿ç¨ä¸é¢ä»£ç å®ç°ï¼
a = [1,2,0,3,4,0,5,0,6]ææå¦ä¸ï¼
注ï¼å¦æ使ç¨python2åç´æ¥è¾åºbå³å¯ï¼å¨python3ä¸filterè¿åç»æ为å¯è¿ä»£ç对象ï¼é使ç¨list转æ¢æå表ã
用filter函数可以方便地完成。
实例:删除数组中所有的字符串'a'
str = ['a', 'b','c', 'd']摘自: