ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
from itertools import product
print(list(map(''.join, product('ab', repeat=2))))
  1. A. ['aa', 'ba', 'ab', 'bb']
  2. B. ['aa', 'ab', 'ba', 'bb']
  3. C. ['ab', 'aa', 'ba', 'bb']
  4. D. ['aa', 'ab', 'bb', 'ba']

Correct answer: B. ['aa', 'ab', 'ba', 'bb']

product varies the last position fastest, so the order is aa, ab, ba, bb. Joining each tuple gives the strings in that order.

More Python Programming questions

Exams that ask this topic