Home › coding › python › py collections

Py Collections — Free Python Tutorial

Learn Py Collections in Python with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

TL;DR: Learn Py Collections in Python with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.

Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

Py Collections in Python

The collections module has specialised containers more efficient than plain dict/list for common patterns.

Counter: auto-counts elements. Perfect for word frequency, vote counting, histogram creation. counter.most_common(n) returns top n.

defaultdict(list) creates a dict of lists — no KeyError on first access. deque (double-ended queue) is O(1) for append/pop from both ends, unlike lists (O(n) for left-side operations).

Py Collections — Syntax

from collections import Counter, defaultdict, deque
c = Counter("banana")          # Counter({'a':3,'n':2,'b':1})
dd = defaultdict(list)
dd["fruits"].append("apple")   # no KeyError!
dq = deque([1,2,3], maxlen=3)  # sliding window

Learn Py Collections step by step with Syllab's free interactive Python tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Python course →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12