| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 45832ea commit 17301e9
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -234,21 +234,6 @@ loops that truncate the stream. | |||
| 234 | 234 | self.currkey = self.keyfunc(self.currvalue) | |
| 235 | 235 | ||
| 236 | 236 | ||
| 237 | - .. function:: ifilter(predicate, iterable) | ||
| 238 | - | ||
| 239 | - Make an iterator that filters elements from iterable returning only those for | ||
| 240 | - which the predicate is ``True``. If *predicate* is ``None``, return the items | ||
| 241 | - that are true. This function is the same as the built-in :func:`filter` | ||
| 242 | - function. Equivalent to:: | ||
| 243 | - | ||
| 244 | - def ifilter(predicate, iterable): | ||
| 245 | - if predicate is None: | ||
| 246 | - predicate = bool | ||
| 247 | - for x in iterable: | ||
| 248 | - if predicate(x): | ||
| 249 | - yield x | ||
| 250 | - | ||
| 251 | - | ||
| 252 | 237 | .. function:: ifilterfalse(predicate, iterable) | |
| 253 | 238 | ||
| 254 | 239 | Make an iterator that filters elements from iterable returning only those for | |
@@ -606,13 +591,13 @@ which incur interpreter overhead. :: | |||
| 606 | 591 | ||
| 607 | 592 | def any(seq, pred=None): | |
| 608 | 593 | "Returns True if pred(x) is true for at least one element in the iterable" | |
| 609 | - for elem in ifilter(pred, seq): | ||
| 594 | + for elem in filter(pred, seq): | ||
| 610 | 595 | return True | |
| 611 | 596 | return False | |
| 612 | 597 | ||
| 613 | 598 | def no(seq, pred=None): | |
| 614 | 599 | "Returns True if pred(x) is false for every element in the iterable" | |
| 615 | - for elem in ifilter(pred, seq): | ||
| 600 | + for elem in filter(pred, seq): | ||
| 616 | 601 | return False | |
| 617 | 602 | return True | |
| 618 | 603 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ | |||
| 12 | 12 | import os | |
| 13 | 13 | import stat | |
| 14 | 14 | import warnings | |
| 15 | - from itertools import ifilter, ifilterfalse, imap, izip | ||
| 15 | + from itertools import ifilterfalse, imap, izip | ||
| 16 | 16 | ||
| 17 | 17 | __all__ = ["cmp","dircmp","cmpfiles"] | |
| 18 | 18 | ||
@@ -132,7 +132,7 @@ def phase0(self): # Compare everything except common subdirectories | |||
| 132 | 132 | def phase1(self): # Compute common names | |
| 133 | 133 | a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list)) | |
| 134 | 134 | b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list)) | |
| 135 | - self.common = list(map(a.__getitem__, ifilter(b.__contains__, a))) | ||
| 135 | + self.common = list(map(a.__getitem__, filter(b.__contains__, a))) | ||
| 136 | 136 | self.left_only = list(map(a.__getitem__, ifilterfalse(b.__contains__, a))) | |
| 137 | 137 | self.right_only = list(map(b.__getitem__, ifilterfalse(a.__contains__, b))) | |
| 138 | 138 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | from functools import reduce | |
| 9 | 9 | maxsize = test_support.MAX_Py_ssize_t | |
| 10 | 10 | minsize = -maxsize-1 | |
| 11 | + ifilter = filter | ||
| 11 | 12 | ||
| 12 | 13 | def lzip(*args): | |
| 13 | 14 | return list(zip(*args)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2208,149 +2208,6 @@ static PyTypeObject combinations_type = { | |||
| 2208 | 2208 | }; | |
| 2209 | 2209 | ||
| 2210 | 2210 | ||
| 2211 | - /* ifilter object ************************************************************/ | ||
| 2212 | - | ||
| 2213 | - typedef struct { | ||
| 2214 | - PyObject_HEAD | ||
| 2215 | - PyObject *func; | ||
| 2216 | - PyObject *it; | ||
| 2217 | - } ifilterobject; | ||
| 2218 | - | ||
| 2219 | - static PyTypeObject ifilter_type; | ||
| 2220 | - | ||
| 2221 | - static PyObject * | ||
| 2222 | - ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||
| 2223 | - { | ||
| 2224 | - PyObject *func, *seq; | ||
| 2225 | - PyObject *it; | ||
| 2226 | - ifilterobject *lz; | ||
| 2227 | - | ||
| 2228 | - if (type == &ifilter_type && !_PyArg_NoKeywords("ifilter()", kwds)) | ||
| 2229 | - return NULL; | ||
| 2230 | - | ||
| 2231 | - if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq)) | ||
| 2232 | - return NULL; | ||
| 2233 | - | ||
| 2234 | - /* Get iterator. */ | ||
| 2235 | - it = PyObject_GetIter(seq); | ||
| 2236 | - if (it == NULL) | ||
| 2237 | - return NULL; | ||
| 2238 | - | ||
| 2239 | - /* create ifilterobject structure */ | ||
| 2240 | - lz = (ifilterobject *)type->tp_alloc(type, 0); | ||
| 2241 | - if (lz == NULL) { | ||
| 2242 | - Py_DECREF(it); | ||
| 2243 | - return NULL; | ||
| 2244 | - } | ||
| 2245 | - Py_INCREF(func); | ||
| 2246 | - lz->func = func; | ||
| 2247 | - lz->it = it; | ||
| 2248 | - | ||
| 2249 | - return (PyObject *)lz; | ||
| 2250 | - } | ||
| 2251 | - | ||
| 2252 | - static void | ||
| 2253 | - ifilter_dealloc(ifilterobject *lz) | ||
| 2254 | - { | ||
| 2255 | - PyObject_GC_UnTrack(lz); | ||
| 2256 | - Py_XDECREF(lz->func); | ||
| 2257 | - Py_XDECREF(lz->it); | ||
| 2258 | - Py_TYPE(lz)->tp_free(lz); | ||
| 2259 | - } | ||
| 2260 | - | ||
| 2261 | - static int | ||
| 2262 | - ifilter_traverse(ifilterobject *lz, visitproc visit, void *arg) | ||
| 2263 | - { | ||
| 2264 | - Py_VISIT(lz->it); | ||
| 2265 | - Py_VISIT(lz->func); | ||
| 2266 | - return 0; | ||
| 2267 | - } | ||
| 2268 | - | ||
| 2269 | - static PyObject * | ||
| 2270 | - ifilter_next(ifilterobject *lz) | ||
| 2271 | - { | ||
| 2272 | - PyObject *item; | ||
| 2273 | - PyObject *it = lz->it; | ||
| 2274 | - long ok; | ||
| 2275 | - PyObject *(*iternext)(PyObject *); | ||
| 2276 | - | ||
| 2277 | - assert(PyIter_Check(it)); | ||
| 2278 | - iternext = *Py_TYPE(it)->tp_iternext; | ||
| 2279 | - for (;;) { | ||
| 2280 | - item = iternext(it); | ||
| 2281 | - if (item == NULL) | ||
| 2282 | - return NULL; | ||
| 2283 | - | ||
| 2284 | - if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { | ||
| 2285 | - ok = PyObject_IsTrue(item); | ||
| 2286 | - } else { | ||
| 2287 | - PyObject *good; | ||
| 2288 | - good = PyObject_CallFunctionObjArgs(lz->func, | ||
| 2289 | - item, NULL); | ||
| 2290 | - if (good == NULL) { | ||
| 2291 | - Py_DECREF(item); | ||
| 2292 | - return NULL; | ||
| 2293 | - } | ||
| 2294 | - ok = PyObject_IsTrue(good); | ||
| 2295 | - Py_DECREF(good); | ||
| 2296 | - } | ||
| 2297 | - if (ok) | ||
| 2298 | - return item; | ||
| 2299 | - Py_DECREF(item); | ||
| 2300 | - } | ||
| 2301 | - } | ||
| 2302 | - | ||
| 2303 | - PyDoc_STRVAR(ifilter_doc, | ||
| 2304 | - "ifilter(function or None, sequence) --> ifilter object\n\ | ||
| 2305 | - \n\ | ||
| 2306 | - Return those items of sequence for which function(item) is true.\n\ | ||
| 2307 | - If function is None, return the items that are true."); | ||
| 2308 | - | ||
| 2309 | - static PyTypeObject ifilter_type = { | ||
| 2310 | - PyVarObject_HEAD_INIT(NULL, 0) | ||
| 2311 | - "itertools.ifilter", /* tp_name */ | ||
| 2312 | - sizeof(ifilterobject), /* tp_basicsize */ | ||
| 2313 | - 0, /* tp_itemsize */ | ||
| 2314 | - /* methods */ | ||
| 2315 | - (destructor)ifilter_dealloc, /* tp_dealloc */ | ||
| 2316 | - 0, /* tp_print */ | ||
| 2317 | - 0, /* tp_getattr */ | ||
| 2318 | - 0, /* tp_setattr */ | ||
| 2319 | - 0, /* tp_compare */ | ||
| 2320 | - 0, /* tp_repr */ | ||
| 2321 | - 0, /* tp_as_number */ | ||
| 2322 | - 0, /* tp_as_sequence */ | ||
| 2323 | - 0, /* tp_as_mapping */ | ||
| 2324 | - 0, /* tp_hash */ | ||
| 2325 | - 0, /* tp_call */ | ||
| 2326 | - 0, /* tp_str */ | ||
| 2327 | - PyObject_GenericGetAttr, /* tp_getattro */ | ||
| 2328 | - 0, /* tp_setattro */ | ||
| 2329 | - 0, /* tp_as_buffer */ | ||
| 2330 | - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | | ||
| 2331 | - Py_TPFLAGS_BASETYPE, /* tp_flags */ | ||
| 2332 | - ifilter_doc, /* tp_doc */ | ||
| 2333 | - (traverseproc)ifilter_traverse, /* tp_traverse */ | ||
| 2334 | - 0, /* tp_clear */ | ||
| 2335 | - 0, /* tp_richcompare */ | ||
| 2336 | - 0, /* tp_weaklistoffset */ | ||
| 2337 | - PyObject_SelfIter, /* tp_iter */ | ||
| 2338 | - (iternextfunc)ifilter_next, /* tp_iternext */ | ||
| 2339 | - 0, /* tp_methods */ | ||
| 2340 | - 0, /* tp_members */ | ||
| 2341 | - 0, /* tp_getset */ | ||
| 2342 | - 0, /* tp_base */ | ||
| 2343 | - 0, /* tp_dict */ | ||
| 2344 | - 0, /* tp_descr_get */ | ||
| 2345 | - 0, /* tp_descr_set */ | ||
| 2346 | - 0, /* tp_dictoffset */ | ||
| 2347 | - 0, /* tp_init */ | ||
| 2348 | - 0, /* tp_alloc */ | ||
| 2349 | - ifilter_new, /* tp_new */ | ||
| 2350 | - PyObject_GC_Del, /* tp_free */ | ||
| 2351 | - }; | ||
| 2352 | - | ||
| 2353 | - | ||
| 2354 | 2211 | /* ifilterfalse object ************************************************************/ | |
| 2355 | 2212 | ||
| 2356 | 2213 | typedef struct { | |
@@ -3208,7 +3065,6 @@ repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times\n\ | |||
| 3208 | 3065 | Iterators terminating on the shortest input sequence:\n\ | |
| 3209 | 3066 | izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\ | |
| 3210 | 3067 | izip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\ | |
| 3211 | - ifilter(pred, seq) --> elements of seq where pred(elem) is True\n\ | ||
| 3212 | 3068 | ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\ | |
| 3213 | 3069 | islice(seq, [start,] stop [, step]) --> elements from\n\ | |
| 3214 | 3070 | seq[start:stop:step]\n\ | |
@@ -3242,7 +3098,6 @@ inititertools(void) | |||
| 3242 | 3098 | &starmap_type, | |
| 3243 | 3099 | &imap_type, | |
| 3244 | 3100 | &chain_type, | |
| 3245 | - &ifilter_type, | ||
| 3246 | 3101 | &ifilterfalse_type, | |
| 3247 | 3102 | &count_type, | |
| 3248 | 3103 | &izip_type, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments