BaşlayınÜcretsiz Başlayın

Generator comprehensions

You are given the following generator functions (you can test them in the console):

def func1(n):
  for i in range(0, n):
    yield i**2
def func2(n):
  for i in range(0, n):
     if i%2 == 0:
       yield 2*i
def func3(n, m):
  for i in func1(n):
    for j in func2(m):
      yield ((i, j), i + j)

Note that func3() uses internally func1() and func2().

Bu egzersiz

Practicing Coding Interview Questions in Python

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Rewrite func1() as a generator comprehension
gen = ____

for item in zip(gen, func1(10)):
    print(item)
Kodu Düzenle ve Çalıştır