Quiz Catalog

Catalog of quizzes

a = (el for el in range(5))
b = (el for el in range(7, 13, 2))
t = (a, b)
print(t)
(<generator object <genexpr> at 0x7f8f46f245f0>, <generator object <genexpr> at 0x7f8f46d255b0>)
  • build-in/range
  • tuple
  • generator

num_list: list = [1, 3, 6, 10]
multiplied_list = (num**2 for num in num_list)

print(type(multiplied_list))
<class 'generator'>
  • generator
  • build-in/list
  • build-in/type

numbers = [1, 2, 3, 4, 5]
squares: list = [number**2 for number in numbers if number % 2 == 0]

print(squares)
[4, 16]
  • generator
  • build-in/list

x1 = [i for i in range(10) if i % 2 and i % 3]
x2 = x1
x2.append(e for e in range(8) if e not in x1)

print(x1)
[1, 5, 7, <generator object <genexpr> at 0x7f18ad923f40>]
  • list/comprehension
  • build-in/append
  • build-in/range
  • generator

def increment(n):
  yield n + 1
  
print(type(increment(5)))
<class 'generator'>
  • generator
  • build-in/yield
  • build-in/type

a = (el for el in range(105))

print(type(a))
<class 'generator'>
  • generator
  • type
  • build-in/type

def func():
  yield 'Hello'
  yield 'World'
  yield '!!!'
  
for letter in func():
  print(letter, end=' ')
Hello World !!!
  • generator
  • build-in/yield

expression = (letter for letter in 'abc')
len(expression)
TypeError: object of type 'generator' has no len()
  • generator
  • build-in/len

abc_gen_expr = (letter for letter in 'abc')

print(next(abc_gen_expr))
a
  • generator
  • build-in/next