enumerate, reversed, sorted, zipfilter, iter, mapabs, divmod, pow, roundbin, chr, hex, oct, ord
Draft for Information Only
Content
Python Built-in Conversion Functions filter() Parameters Remarks iter() Parameters Remarks map() Parameters Remarks Source and Reference
Python Built-in Conversion Functions
The Python interpreter has some built-in conversion functions.
filter()
filter(function, iterable)
Parameters
type()to return an iterator from iterable for which function returns true.
functionto specify the function to be used for testing
iterableto specify an iterable to be returned from
Remarks
filter constructs an iterator from those elements of iterable for which function returns true
iterable may be either a sequence, a container which supports iteration, or an iterator.
- If
function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
- If
function is not None, filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)), filter(function, iterable) is equivalent to
- if
function is None, (item for item in iterable if item)
- See itertools.filterfalse() for the complementary function that returns elements of iterable for which function returns false.
iter()
iter(object[, sentinel])
Parameters
iter()to return an iterator object.
objectto specify an object to be returned from
[sentinel]to specify sentinel
Remarks
- If
sentinel is omitted, object must be a collection object which supports the iteration protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0). If it does not support either of those protocols, TypeError is raised.
- If
sentinel is specified, then object must be a callable object. The iterator created in this case will call object with no arguments for each call to its __next__() netgid; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned.
- One useful application of the second form of
iter() is to build a block-reader.
map()
map(function, iterable, ...)
Parameters
map()to return an iterator that applies function to every item of iterable, yielding the results.
functionto specify the function to be used for applying
iterableto specify the iterable to be applied to
Remarks
- If additional
iterable are passed, function must take that many arguments and is applied to the items from all iterables in parallel.
- With multiple iterables, the iterator stops when the shortest iterable is exhausted.
- For cases where the function inputs are already arranged into argument tuples, as in
itertools.starmap()
Source and Reference
©sideway
ID: 201002302 Last Updated: 10/23/2020 Revision: 0
|
|