ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
import itertools print(list(itertools.combinations([1, 2, 3, 4], 2)))
- A. [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
- B. [(1, 2), (2, 1), (1, 3), (3, 1)]
- C. [(1, 2, 3, 4)]
- D. [(1, 2), (3, 4)]
Correct answer: A. [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]
combinations with r=2 gives every UNORDERED pair in lexicographic order of indices, without repeating an element paired with an earlier one: 4C2 = 6 pairs.
More Python Programming questions
- What is printed? python import itertools print(list(itertools.accumulate([1, 2, 3, 4]))) print(list(itertools.accumulate([1, 2, 3, 4]…
- What is printed? python print(list(zip([1, 2, 3], [4, 5], [6, 7, 8, 9]))) from itertools import ziplongest print(list(ziplongest([1, 2…
- What is printed? python print(list(enumerate(["a", "b", "c"], start=5)))
- What is printed? python from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass try: s = Shape() except…
- What is printed? python class Meta(type): def new(mcs, name, bases, ns): print("creating", name) return super().new(mcs, name, bases, ns)…
- What is printed? python class Vec: def init(self, x, y): self.x, self.y = x, y def radd(self, o): return Vec(self.x + o, self.y + o) def…