ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(list(zip(*[(1, 'a'), (2, 'b')])))
- A. [(1, 'a'), (2, 'b')]
- B. [(1, 2), ('a', 'b')]
- C. [(1, 2), ('b', 'a')]
- D. [(1, 2)]
Correct answer: B. [(1, 2), ('a', 'b')]
zip(*pairs) transposes the list of pairs, so the first tuple collects the numbers and the second collects the letters.
More Python Programming questions
- What is printed? python print(1 if 0 else 2 if 1 else 3, (lambda: 1 if False else 'x')())
- What is printed? python print(type(1/1).name, type(1//1).name, type(2-1).name, type(21).name)
- What is printed? python print(sorted({x % 4 for x in range(10)}))
- What is printed? python print('xxhixx'.strip('x') + '|' + 'abc'.strip('ac'))
- What is printed? python print(len(str(2100)), str(2100)[:5])
- What is printed? python print(sorted([[2, 'b'], [1, 'z'], [2, 'a']]))