All quizzesMedium
Advanced Collections — Series 3
Preview — 3 of 10 questions
What is the output of the following code?
javascript
from collections import Counter
c = Counter(b=1, a=3, z=0)
print(list(c.elements()))
print(sorted(c.elements()))A['b', 'a', 'a', 'a'], ['a', 'a', 'a', 'b']
B['b', 'a', 'a', 'a', 'z'], ['a', 'a', 'a', 'b', 'z']
C['a', 'a', 'a', 'b'], ['a', 'a', 'a', 'b']
D['b', 'a', 'z'], ['a', 'b', 'z']
What is the output of the following code?
javascript
nums = {"a": 1, "b": 2, "c": 3, "d": 4}
evens = {k: v for k, v in nums.items() if v % 2 == 0}
print(evens)
squared_odds = {k: v * v for k, v in nums.items() if v % 2 != 0}
print(squared_odds)A{2: 'b', 4: 'd'}, {1: 'a', 9: 'c'}
B{'b': 2, 'd': 4}, {'a': 1, 'c': 9}
C{'a': 1, 'c': 3}, {'b': 4, 'd': 16}
D{'b': 2, 'd': 4}, {'a': 1, 'c': 3}
What is the output of the following code?
javascript
lst = [1, 2, 3]
lst.extend("abc")
print(lst)
lst2 = [1, 2, 3]
lst2.append("abc")
print(lst2)A[1, 2, 3, 'a', 'b', 'c'], [1, 2, 3, 'a', 'b', 'c']
BTypeError: 'str' object is not a list, [1, 2, 3, 'abc']
C[1, 2, 3, 'a', 'b', 'c'], [1, 2, 3, 'abc']
D[1, 2, 3, 'abc'], [1, 2, 3, 'abc']
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.