ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
from itertools import product
print(list(map(''.join, product('ab', repeat=2))))- A. ['aa', 'ba', 'ab', 'bb']
- B. ['aa', 'ab', 'ba', 'bb']
- C. ['ab', 'aa', 'ba', 'bb']
- 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
- What is printed? python print(sum(range(10 6)) % 1000, sum(range(1, 11)) // 5)
- What is printed? python print(('a' 'b' 'c').upper(), 'x' 'y' 2, ('%d' % 3) 2)
- What is printed? python print(1e16 == 1016, 1e16 + 1 == 1016 + 1, 1e16 + 2 == 1016 + 2, int(1e16) + 1)
- What is printed? python print('%.2e' % 0, '%.1f' % 2.25, '%.1f' % 2.35, '%5.1f|' % -0.04)
- What is printed? python x = 0.1 print((0.5).asintegerratio(), (0.1).asintegerratio()[1] == 255)
- What is printed? python import operator print(operator.index(5), operator.mod(-7, 3), operator.floordiv(-7, 3))