Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

lists-dicts

Lists and dictionaries

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Lists and dictionaries: the syntax, APIs, and habits you need before advancing in Django.

Teams ship Lists and dictionaries on every Django codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Lists and dictionaries in contexts like: SaaS dashboards, CMS-style products, internal tools, and APIs paired with React or mobile clients.

Write Python 3 in the editor and click Run on server—the dev runner executes your script; Django framework lessons also use local startproject for full MVT (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Django's template context is a dict mapping names to values. Querysets behave like lazy lists. JSON APIs serialize dicts. Mastering collections is essential.

Dictionaries as context

context = {
    "articles": Article.objects.filter(published=True),
    "page_title": "Blog home",
}

Templates access keys: {{ page_title }}, {% for article in articles %}.

Lists and querysets

Querysets support filtering, slicing, and ordering—similar to chaining list operations but executed as SQL. list(queryset) forces evaluation when you need a concrete list.

Important interview questions and answers

  1. Q: Dict vs model instance in templates?
    A: Models expose attributes (article.title); dicts use keys—both work in Django templates.
  2. Q: When is a queryset evaluated?
    A: On iteration, slicing, len(), list(), or printing—until then it is lazy SQL.
  3. Q: Mutable default dict pitfall?
    A: Never use def f(x={})—shared mutable defaults cause bugs; Django model field defaults use callables like dict or list correctly via default=list.

Self-check

  1. What is a view's context dict for?
  2. When does a queryset hit the database?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • dict get default?
  • Mutable default trap?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump