Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python yield from

# In python construction 'yield from something' is just 
# the abbreviation of 'for i in something: yield i'
# So, we can change this:
def yieldOnly():
    yield "A"
    yield "B"
    yield "C"

def yieldFrom():
    for _ in [1, 2, 3]:
        yield from yieldOnly()

test = yieldFrom()
for i in test:
    print(i)
    
# to this:

def yieldOnly():
    yield "A"
    yield "B"
    yield "C"

def yieldFrom():
    for _ in [1, 2, 3]:
        for i in yieldOnly():
            yield i

test = yieldFrom()
for i in test:
    print(i)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #yield
ADD COMMENT
Topic
Name
9+1 =