Aug-11-2022, 11:18 PM
(This post was last modified: Aug-11-2022, 11:18 PM by deanhystad.)
filter() returns a filter object, which is iterable. According to the documentation
https://docs.python.org/3/library/functions.html#filter
https://docs.python.org/3/library/functions.html#filter
Quote:filter(function, iterable)You could do "".join(filter(str.isdigit, s)).
Construct 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.
Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)) if function is not None and (item for item in iterable if item) if function is None
s = 'November 11 day' pp = int("".join(filter(str.isdigit, s))) print(f" Digits only -> {pp}")