ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
nums = map(int, '1 2 3'.split()) a = list(nums) b = list(nums) print(a, b)
- A. [1, 2, 3] [None, None, None]
- B. [1, 2, 3] []
- C. [1, 2, 3] [1, 2, 3]
- D. [] []
Correct answer: B. [1, 2, 3] []
map returns a one-shot iterator. The first list() consumes it, so the second list() gets nothing. Keep the result as a list if you need to traverse it twice.
More Python Programming questions
- What is printed? python print(1020 + 1 - 1020, float(1020 + 1) - float(1020))
- What is printed? python data = [('b', 2), ('a', 2), ('c', 1), ('a', 1)] print(sorted(sorted(data, key=lambda t: t[0]), key=lambda t: t[1]…
- What is printed? python print(int('0x1F', 16), int('1F', 16), int('0b101', 0), int(' 42 '), int('42'))
- What is printed? python print(int('٣') + 1)
- What is printed? python print(bin(10)[2:].zfill(8), format(-10, '08b'), format(-10 & 0xFF, '08b'), f'{255:#x}')
- What is printed? python print((1 << 70).bitcount(), (270 - 1).bitcount(), (-1).bitcount(), (-8).bitcount())