Built-ins & Standard Library · Question 14 · Medium

itertools is used to count the 2-item combinations and the 2-item permutations of four letters. What is printed?

from itertools import combinations, permutations

c = list(combinations("ABCD", 2))
p = list(permutations("ABCD", 2))
print(len(c), len(p))
  1. 12 6
  2. 6 16
  3. 6 12
  4. 4 12
Answer and explanation

Answer: C. 6 12

Explanation: Combinations ignore order: 4C2 = 6. Permutations count each ordering separately and never repeat an item: 4 × 3 = 12.

Previous: A file tools.py ends with a block under if __name__ == "__main__":. When does… · Next: sorted is given a key that returns a tuple, to rank students by marks (high to…

Practise built-ins & standard library

Try a fresh set of built-ins & standard library questions with an explanation after every answer, free and without signing up: Built-ins & Standard Library practice. Or sit a full placement mock test.

More built-ins & standard library questions

More python practice

Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge