ProgrammingModerateCognizant GenC · Python
What is printed?
What is printed?
print(list(zip('abc', range(5))), dict(zip('ab', [1, 2, 3])))- A. [('a', 0), ('b', 1), ('c', 2)] {'a': 1, 'b': 2}
- B. [('a', 0), ('b', 1), ('c', 2), (None, 3), (None, 4)] {'a': 1, 'b': 2}
- C. [('a', 0), ('b', 1), ('c', 2)] {'a': 1, 'b': 2, None: 3}
- D. [('a', 0), ('b', 1)] {'a': 1, 'b': 2}
Correct answer: A. [('a', 0), ('b', 1), ('c', 2)] {'a': 1, 'b': 2}
zip stops at the shortest iterable, so each result has only as many pairs as the shorter input.
More Python Programming questions
- What is printed? python def f(x, acc=[]): acc.append(x) return len(acc) print(f(1), f(2), f(3, []), f(4))
- What is printed? python print(all([]), any([]), all([0]), any([[]]), any([[0]]))
- What is printed? python w = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(w, key=len), sorted(w, key=len, reverse=True))
- What is printed? python print(7 // 2, -7 // 2, 7 % -3, divmod(-7, 2), 2 -1)
- What is printed? python print({x % 3 for x in range(10)}, {x: x x for x in range(3)})
- What is printed? python def f(): try: return 'a' finally: print('f', end=' ') print(f())