LearnFrenzy
Sign in Take a free test

Modules and Packages · Predict the Output · Question 8

permutations, combinations and product Answer, explanation & discussion

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

What is the output of the following Python program?

main.py
from itertools import permutations, combinations, product
print(len(list(permutations("abc"))), list(combinations([1, 2, 3], 2)), len(list(product("ab", repeat=3))))
  • A 6 [(1, 2), (1, 3), (2, 3)] 8 Correct
  • B 3 [(1, 2), (1, 3), (2, 3)] 6
  • C 6 [(1, 2), (2, 1), (1, 3)] 8
  • D 6 [(1, 2), (1, 3), (2, 3)] 6
Correct Answer: Option A

3! = 6 orderings; combinations ignore order; product with repeat=3 gives 2³ = 8 tuples.

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