0
可能重複:
python equivalent of filter() getting two output lists (i.e. partition of a list)的Python模擬對Ruby可枚舉.partition方法
是否有任何內置函數或Python標準庫,也許一些模塊,從模擬Enumerable.partition
行爲Ruby並遍歷一個對象只需要一次,以獲得兩個基於謂詞函數傳遞的列表/元組?
它在這裏:http://docs.python.org/dev/library/itertools.html#itertools-recipes。這已被問了很多次。 http://stackoverflow.com/questions/4578590/python-equivalent-of-filter-getting-two-output-lists-ie-partition-of-a-list – tokland