Quiz Catalog

Catalog of quizzes

def func():
  yield 1
  return 2
  yield 3

for i in func():
  print(i)
1
  • generator/definition
  • iterator

numbers = [100, 200, 300]
iterator = iter(numbers)

print(len(iterator))
TypeError: object of type 'list_iterator' has no len()
  • iterator
  • build-in/len

numbers = [100, 200, 300]
iterator1 = iter(numbers)
iterator2 = iter(iterator1)

print(iterator1 is iterator2)
True
  • iterator

def custom_chain(*iterables):
  for iterable in iterables:
    yield from iterable

for x in custom_chain([1, 2, 3], 'abc'):
  print(x, end=' ')
1 2 3 a b c
  • iterator
  • build-in/yield

scores: dict = {'John': 99, 'Danny': 95}

iter_scores = iter(scores)

print(type(iter_scores))
<class 'dict_keyiterator'>
  • iterator

def custom_chain(*iterables):
  for iterable in iterables:
    yield from iterable

for x in custom_chain([1, 2, 3], 'abc'):
  print(x, end=' ')
1 2 3 a b c
  • iterator
  • build-in/yield

scores: dict = {'John': 99, 'Danny': 95}
iter_scores = iter(scores)

print(type(iter_scores))
<class 'dict_keyiterator'>
  • iterator
  • build-in/type
  • build-in/dict