Python basics, lists, dictionaries, and sets
Words made simple
A few useful meanings before you read the explanation.
- AI
- Software techniques for tasks such as recognizing patterns, understanding language or generating content.
- API
- A way for one piece of software to ask another for data or an action. A claims API might return the current status of a claim.
- LLM
- A model trained to work with language. It can write or summarize text, but its answer still needs checking against reliable information.
More words from this lesson
- Tenant
- A customer or organization whose data must stay separate from other customers in a shared application.
- Evaluation
- Checking results against examples and clear criteria to find whether the system works well and where it fails.
- Chunking
- Dividing a long document into smaller pieces so relevant parts can be found and sent to the model.
- Metadata
- Extra information describing a record, such as its owner, date, policy version or document type.
- Dependency
- A library or package that your application relies on. Compatible versions help the application run as expected.
🔴 MUST KNOW · Learn enough to operate AI services; keep existing MERN responsibilities in TypeScript when appropriate.
Overview
- Python is a dynamically typed language widely used by AI libraries.
- A list is an ordered collection, a dictionary maps keys to values, and a set stores unique hashable values.
- Python uses indentation to define code blocks rather than braces.
Why this matters
Many document-processing, model-training, numerical, and evaluation libraries are easiest to use in Python.
An everyday example
A list is a queue of documents; a dictionary is a labeled filing cabinet; a set is a guest list without duplicates.
A technical example
chunks = ["policy", "claim"]; metadata = {"tenant_id": "t1"}; unique_ids = {"C1", "C2"}.
How it works
- Create values
- Use indexing or key lookup
- Loop or use comprehensions
- Pass results to functions.
- Lists and dictionaries are mutable; sharing them can create accidental changes.
Architecture and flow
Parsed documents → lists of chunks → dictionaries of metadata → unique IDs for deduplication.
The insurance assistant example
A worker extracts policy paragraphs, attaches source metadata, and deduplicates document identifiers.
When to use it
For Python-facing data preparation and AI libraries.
When to avoid it
Do not rewrite a working Node service merely to use a hosted LLM API.
Interview answer
“I use Python where its AI ecosystem provides practical benefits and keep collection types explicit so ingestion and evaluation code remain readable.”
Benefits, trade-offs, and production considerations
- TypeScript interfaces and Python type hints do not provide runtime validation.
- Python's
None,True,False,and,or, andnotcorrespond roughly to JS'snull, booleans, and logical operators, but truthiness and equality rules differ.
| TypeScript/JavaScript | Python | Practical difference |
|---|---|---|
const x = null | x = None | Check absence with x is None |
string[] / array | list[str] | Lists may contain mixed types unless validated |
object / Map | dict[str, str] | Dictionary keys must be hashable |
Set<string> | set[str] | Empty set is set(), not {} |
=== | == for value equality | is checks identity, not general equality |
arr.map(fn) | [fn(x) for x in arr] | Comprehensions are common |
try/catch/finally | try/except/finally | Catch specific exceptions |
| template literal | f"claim {claim_id}" | Never use interpolation to construct SQL |
| braces | indentation | Usually four spaces per indentation level |
# No third-party dependencies: basic data preparation.
documents = [
{"id": "p1", "text": "Claim reporting instructions", "active": True},
{"id": "p2", "text": "Old wording", "active": False},
]
active_texts: list[str] = [d["text"] for d in documents if d["active"]]
seen_ids: set[str] = {d["id"] for d in documents}
for index, text in enumerate(active_texts):
print(index, text)Can you explain it without the notes?
Python basics, lists, dictionaries, and sets
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Python is a dynamically typed language widely used by AI libraries. A list is an ordered collection, a dictionary maps keys to values, and a set stores unique hashable values. Python uses indentation to define code blocks rather than braces.
Turn this concept into a clear answer.
Practice this conceptAdapted from 13_AI.MD · “Python basics, lists, dictionaries, and sets”. Examples are study fragments; framework behavior can depend on your version.