Python · The collections Module

What does this print? from collections import deque d = deque([1, 2, 3, 4, 5]) d.rotate(2) print(d)

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in The collections Module

When should you prefer dict.setdefault(k, []).append(x) over a defaultdict(list)?
You need to look up scores by team name when the data is split across several separate dicts (group_a, group_g, ...). You don't want to merge them into a new dict. Which collections type fits?
What does this print? ``` from collections import ChainMap a = {"x": 1} b = {"x": 2, "y": 9} cm = ChainMap(a, b) print(cm["x"], cm["y"]) ```
With cm = ChainMap(a, b), you do cm["x"] = 100. Which underlying dict gets modified?
You want to count how often each character appears in a string, with the least code. Which collections type, and how in one line?
What does this print? ``` from collections import Counter c = Counter("aabbbc") print(c["z"]) print("z" in c) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play