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))
- 12 6
- 6 16
- 6 12
- 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
- max is called on a dictionary of city temperatures, once plainly and once with…
- zip is used with the * operator to split a list of pairs. What does this code…
- A file tools.py ends with a block under if __name__ == "__main__":. When does…
- sorted is given a key that returns a tuple, to rank students by marks (high to…
- itertools.groupby is applied directly to a string in which one letter appears…
- Booleans are used in an isinstance check, in addition and inside sum. What…
- A program imports the same module helper from two different files. How many…
- A defaultdict(int) is updated for one key, read for a second key and tested…
- all, any and max are each given an empty list, with a default supplied to max…
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