LearnFrenzy
Sign in Take a free test

Iterators and Generators · Predict the Output · Question 7

yield from several iterables Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

What is the output of the following Python program?

main.py
def combined():
    yield from [1, 2]
    yield from "ab"
    yield from range(2)

print(list(combined()))
  • A [[1, 2], 'ab', range(0, 2)]
  • B [1, 2, 'ab', 0, 1]
  • C [1, 2, 'a', 'b', 1, 2]
  • D [1, 2, 'a', 'b', 0, 1] Correct
Correct Answer: Option D

yield from produces each item of the iterable separately, including each character of the string.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links