You can use map
. The map
accepts two parameters: a function and an iterable. It iterates the iterable and apply the function and returns an iterator (which yields mapped values - function(first item), function(seoncd item), ...)
def some_func():
yield from map(other_func, re.finditer(regex, string))
yield from
here is not necessary, because the map
returns an iterator (in Python 3.x):
def some_func():
return map(other_func, re.finditer(regex, string))
Example:
>>> import re
>>>
>>> def other_func(match):
... return match.group()
...
>>> def some_func():
... return map(other_func, re.finditer(regex, string))
...
>>> regex = '.'
>>> string = 'abc'
>>> list(some_func())
['a', 'b', 'c']