<title>Python Lists & Dictionaries</title>
<style>
:root {
--bg: #0d0f1a;
--card: #131628;
--list-accent: #00e5ff;
--dict-accent: #ff6b6b;
--list-glow: rgba(0,229,255,0.15);
--dict-glow: rgba(255,107,107,0.15);
--muted: #8892b0;
--text: #e6edf3;
--green: #4ade80;
--yellow: #fbbf24;
--purple: #c084fc;
--border: rgba(255,255,255,0.06);
}
- { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: var(--bg);
font-family: 'Syne', sans-serif;
color: var(--text);
min-height: 100vh;
padding: 40px 20px;
overflow-x: hidden;
}
/* Ambient background blobs */
body::before {
content: '';
position: fixed; top: -200px; left: -200px;
width: 600px; height: 600px;
background: radial-gradient(circle, rgba(0,229,255,0.07) 0%, transparent 70%);
pointer-events: none; z-index: 0;
}
body::after {
content: '';
position: fixed; bottom: -200px; right: -200px;
width: 600px; height: 600px;
background: radial-gradient(circle, rgba(255,107,107,0.07) 0%, transparent 70%);
pointer-events: none; z-index: 0;
}
.page { max-width: 1100px; margin: 0 auto; position: relative; z-index: 1; }
/* Header */
.header {
text-align: center;
margin-bottom: 60px;
animation: fadeDown 0.7s ease both;
}
.header .eyebrow {
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
color: var(--muted);
letter-spacing: 4px;
text-transform: uppercase;
margin-bottom: 12px;
}
.header h1 {
font-size: clamp(36px, 6vw, 68px);
font-weight: 800;
line-height: 1.05;
background: linear-gradient(135deg, var(--list-accent) 0%, #ffffff 45%, var(--dict-accent) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 16px;
}
.header p {
color: var(--muted);
font-size: 17px;
font-weight: 400;
max-width: 540px;
margin: 0 auto;
line-height: 1.6;
}
/* What are they — pill badges */
.concept-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 40px;
animation: fadeUp 0.6s 0.2s ease both;
}
.concept-card {
background: var(--card);
border-radius: 16px;
padding: 28px 28px 24px;
border: 1px solid var(--border);
position: relative;
overflow: hidden;
}
.concept-card.list { border-top: 3px solid var(--list-accent); box-shadow: 0 0 40px var(--list-glow); }
.concept-card.dict { border-top: 3px solid var(--dict-accent); box-shadow: 0 0 40px var(--dict-glow); }
.concept-card h2 {
font-size: 22px; font-weight: 800; margin-bottom: 6px;
display: flex; align-items: center; gap: 10px;
}
.concept-card.list h2 { color: var(--list-accent); }
.concept-card.dict h2 { color: var(--dict-accent); }
.concept-card .type-badge {
font-family: 'JetBrains Mono', monospace;
font-size: 11px; font-weight: 600;
padding: 3px 9px; border-radius: 4px;
vertical-align: middle;
}
.list .type-badge { background: rgba(0,229,255,0.15); color: var(--list-accent); }
.dict .type-badge { background: rgba(255,107,107,0.15); color: var(--dict-accent); }
.concept-card p { color: var(--muted); font-size: 14.5px; line-height: 1.65; margin-bottom: 16px; }
.trait-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.trait-list li {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; color: var(--text);
display: flex; align-items: center; gap: 8px;
}
.trait-list li::before {
content: '▸';
font-size: 10px;
}
.list .trait-list li::before { color: var(--list-accent); }
.dict .trait-list li::before { color: var(--dict-accent); }
/* Visual representation */
.visual-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 40px;
animation: fadeUp 0.6s 0.35s ease both;
}
.visual-card {
background: var(--card);
border-radius: 16px;
padding: 24px;
border: 1px solid var(--border);
}
.visual-title {
font-family: 'JetBrains Mono', monospace;
font-size: 11px; letter-spacing: 3px;
color: var(--muted); text-transform: uppercase;
margin-bottom: 20px;
}
/* List visual */
.list-visual { display: flex; gap: 0; align-items: stretch; }
.list-cell {
flex: 1; background: rgba(0,229,255,0.06);
border: 1px solid rgba(0,229,255,0.25);
border-radius: 0; padding: 10px 6px;
text-align: center; position: relative;
transition: background 0.2s;
}
.list-cell:first-child { border-radius: 8px 0 0 8px; }
.list-cell:last-child { border-radius: 0 8px 8px 0; }
.list-cell:hover { background: rgba(0,229,255,0.14); }
.list-cell .idx {
font-family: 'JetBrains Mono', monospace;
font-size: 10px; color: var(--list-accent);
margin-bottom: 6px; display: block;
}
.list-cell .val {
font-family: 'JetBrains Mono', monospace;
font-size: 13px; color: var(--text); font-weight: 600;
}
/* Dict visual */
.dict-visual { display: flex; flex-direction: column; gap: 6px; }
.dict-row {
display: flex; align-items: center; gap: 0;
background: rgba(255,107,107,0.05);
border: 1px solid rgba(255,107,107,0.2);
border-radius: 8px; overflow: hidden;
transition: background 0.2s;
}
.dict-row:hover { background: rgba(255,107,107,0.12); }
.dict-key {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; font-weight: 600;
color: var(--dict-accent);
padding: 9px 14px; min-width: 110px;
border-right: 1px solid rgba(255,107,107,0.2);
background: rgba(255,107,107,0.08);
}
.dict-arrow {
padding: 0 10px; color: var(--muted); font-size: 16px;
}
.dict-value {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; color: var(--text);
padding: 9px 0;
}
/* Operations grid */
.ops-section { margin-bottom: 40px; animation: fadeUp 0.6s 0.5s ease both; }
.section-heading {
font-size: 13px; font-weight: 700; letter-spacing: 3px;
text-transform: uppercase; color: var(--muted);
margin-bottom: 20px;
display: flex; align-items: center; gap: 12px;
}
.section-heading::after {
content: ''; flex: 1; height: 1px; background: var(--border);
}
.ops-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
.op-card {
background: var(--card);
border-radius: 14px;
border: 1px solid var(--border);
overflow: hidden;
}
.op-header {
display: flex; align-items: center; gap: 10px;
padding: 12px 16px 10px;
border-bottom: 1px solid var(--border);
}
.op-icon {
width: 30px; height: 30px; border-radius: 8px;
display: flex; align-items: center; justify-content: center;
font-size: 16px;
}
.op-title { font-size: 15px; font-weight: 700; }
.op-tag {
font-family: 'JetBrains Mono', monospace;
font-size: 10px; padding: 2px 7px; border-radius: 4px;
margin-left: auto;
}
/* Create ops /
.op-card.create .op-icon { background: rgba(74,222,128,0.15); }
.op-card.create .op-title { color: var(--green); }
.op-card.create .op-tag { background: rgba(74,222,128,0.12); color: var(--green); }
/ Read ops /
.op-card.read .op-icon { background: rgba(0,229,255,0.12); }
.op-card.read .op-title { color: var(--list-accent); }
.op-card.read .op-tag { background: rgba(0,229,255,0.1); color: var(--list-accent); }
/ Modify ops /
.op-card.modify .op-icon { background: rgba(251,191,36,0.12); }
.op-card.modify .op-title { color: var(--yellow); }
.op-card.modify .op-tag { background: rgba(251,191,36,0.1); color: var(--yellow); }
/ Delete ops */
.op-card.delete .op-icon { background: rgba(255,107,107,0.12); }
.op-card.delete .op-title { color: var(--dict-accent); }
.op-card.delete .op-tag { background: rgba(255,107,107,0.1); color: var(--dict-accent); }
.op-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.code-block {
background: #0a0c18;
border-radius: 8px;
padding: 12px 14px;
border: 1px solid rgba(255,255,255,0.05);
}
.code-block .label {
font-family: 'JetBrains Mono', monospace;
font-size: 9.5px; letter-spacing: 2px; text-transform: uppercase;
margin-bottom: 7px; font-weight: 600;
}
.code-block.list-style .label { color: var(--list-accent); }
.code-block.dict-style .label { color: var(--dict-accent); }
pre {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
line-height: 1.7;
white-space: pre;
overflow-x: auto;
}
/* Syntax highlight helpers */
.kw { color: #c792ea; }
.fn { color: #82aaff; }
.str { color: #c3e88d; }
.num { color: #f78c6c; }
.key { color: var(--dict-accent); }
.comment { color: #546e7a; font-style: italic; }
.list-idx { color: var(--list-accent); }
.output { color: var(--green); }
/* Footer */
.footer {
text-align: center;
margin-top: 50px;
padding-top: 30px;
border-top: 1px solid var(--border);
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
color: var(--muted);
animation: fadeUp 0.6s 0.8s ease both;
}
@Keyframes fadeDown {
from { opacity: 0; transform: translateY(-24px); }
to { opacity: 1; transform: translateY(0); }
}
@Keyframes fadeUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 700px) {
.concept-row, .visual-row, .ops-grid { grid-template-columns: 1fr; }
}
</style>
Python Data Structures
Lists & Dictionaries
Two essential structures for storing, organizing, and manipulating data in Python.
📋 List [ ]
An ordered, mutable sequence of elements accessed by numeric index (position). Perfect for collections where order matters.
- Ordered — maintains insertion order
- Indexed — access by position [0, 1, 2…]
- Mutable — can be changed after creation
- Allows duplicates
- Heterogeneous — any data type inside
📚 Dictionary { }
An unordered collection of key-value pairs. Each unique key maps directly to a value — like a real-life dictionary.
- Key-Value pairs — key → value
- Accessed by key, not index
- Mutable — add, change, remove pairs
- Keys must be unique & immutable
- Values can be any data type
List — indexed structure
[0]"Alice"
[1]"Bob"
[2]"Cara"
[3]"Dave"
[4]"Eve"
names[0] → "Alice" | names[-1] → "Eve"
Dictionary — key → value pairs
"name"→"Alice"
"age"→30
"city"→"New York"
"active"→True
✦ Create
📋 List
# Empty list
fruits = []
# With initial values
fruits = ["apple", "banana", "mango"]
# Mixed types allowed
mixed = [1, "hello", True, 3.14]
# Using list()
nums = list(range(5)) # [0,1,2,3,4]
➕
Create a Dictionary
CREATE
📚 Dict
# Empty dictionary
person = {}
# With initial pairs
person = {
"name": "Alice",
"age": 30,
"city": "NY"
}
# Using dict()
d = dict(name="Bob", age=25)
✦ Read / Query
📋 List
fruits = ["apple", "banana", "mango"]
# By index
print(fruits[0]) # apple
print(fruits[-1]) # mango (last)
# Slicing
print(fruits[0:2]) # ['apple','banana']
# Length & membership
len(fruits) # 3
"apple" in fruits # True
🔍
Query a Dictionary
READ
📚 Dict
person = {"name":"Alice", "age":30}
# By key
print(person["name"]) # Alice
print(person.get("age")) # 30
# Safe get (no KeyError)
person.get("job", "N/A") # N/A
# All keys / values
person.keys() # dict_keys(['name','age'])
person.values() # dict_values(['Alice', 30])
✦ Modify / Update
📋 List
fruits = ["apple", "banana"]
# Change by index
fruits[0] = "grape"
# ["grape", "banana"]
# Add to end
fruits.append("mango")
# ["grape", "banana", "mango"]
# Insert at position
fruits.insert(1, "kiwi")
# ["grape", "kiwi", "banana", "mango"]
✏️
Modify a Dictionary
UPDATE
📚 Dict
person = {"name":"Alice", "age":30}
# Change existing value
person["age"] = 31
# {"name":"Alice", "age":31}
# Add new key-value pair
person["city"] = "NY"
# {"name":"Alice","age":31,"city":"NY"}
# Merge with update()
person.update({"job":"Dev", "age":32})
✦ Delete / Remove
🗑️
Delete from List
DELETE
📋 List
fruits = ["apple","banana","mango"]
# Remove by value (first match)
fruits.remove("banana")
# ["apple", "mango"]
# Remove by index (returns it)
item = fruits.pop(0)
# item="apple", fruits=["mango"]
# Delete by index
del fruits[0]
# Clear everything
fruits.clear() # []
🗑️
Delete from Dictionary
DELETE
📚 Dict
<pre">person = {
"name":
"Alice",
"age":
30,
"city":
"NY"}
# Remove by key (returns value)
val = person.pop("age")
# val=30, person={"name":"Alice","city":"NY"}
# Delete by key
del person["city"]
# {"name": "Alice"}
# Clear all pairs
person.clear() # {}
Python 3.x · Lists [ ] · Dictionaries { } · CRUD Operations
body {
background: var(--bg);
font-family: 'Syne', sans-serif;
color: var(--text);
min-height: 100vh;
padding: 40px 20px;
overflow-x: hidden;
}
/* Ambient background blobs */
body::before {
content: '';
position: fixed; top: -200px; left: -200px;
width: 600px; height: 600px;
background: radial-gradient(circle, rgba(0,229,255,0.07) 0%, transparent 70%);
pointer-events: none; z-index: 0;
}
body::after {
content: '';
position: fixed; bottom: -200px; right: -200px;
width: 600px; height: 600px;
background: radial-gradient(circle, rgba(255,107,107,0.07) 0%, transparent 70%);
pointer-events: none; z-index: 0;
}
.page { max-width: 1100px; margin: 0 auto; position: relative; z-index: 1; }
/* Header */
.header {
text-align: center;
margin-bottom: 60px;
animation: fadeDown 0.7s ease both;
}
.header .eyebrow {
font-family: 'JetBrains Mono', monospace;
font-size: 13px;
color: var(--muted);
letter-spacing: 4px;
text-transform: uppercase;
margin-bottom: 12px;
}
.header h1 {
font-size: clamp(36px, 6vw, 68px);
font-weight: 800;
line-height: 1.05;
background: linear-gradient(135deg, var(--list-accent) 0%, #ffffff 45%, var(--dict-accent) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 16px;
}
.header p {
color: var(--muted);
font-size: 17px;
font-weight: 400;
max-width: 540px;
margin: 0 auto;
line-height: 1.6;
}
/* What are they — pill badges */
.concept-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 40px;
animation: fadeUp 0.6s 0.2s ease both;
}
.concept-card {
background: var(--card);
border-radius: 16px;
padding: 28px 28px 24px;
border: 1px solid var(--border);
position: relative;
overflow: hidden;
}
.concept-card.list { border-top: 3px solid var(--list-accent); box-shadow: 0 0 40px var(--list-glow); }
.concept-card.dict { border-top: 3px solid var(--dict-accent); box-shadow: 0 0 40px var(--dict-glow); }
.concept-card h2 {
font-size: 22px; font-weight: 800; margin-bottom: 6px;
display: flex; align-items: center; gap: 10px;
}
.concept-card.list h2 { color: var(--list-accent); }
.concept-card.dict h2 { color: var(--dict-accent); }
.concept-card .type-badge {
font-family: 'JetBrains Mono', monospace;
font-size: 11px; font-weight: 600;
padding: 3px 9px; border-radius: 4px;
vertical-align: middle;
}
.list .type-badge { background: rgba(0,229,255,0.15); color: var(--list-accent); }
.dict .type-badge { background: rgba(255,107,107,0.15); color: var(--dict-accent); }
.concept-card p { color: var(--muted); font-size: 14.5px; line-height: 1.65; margin-bottom: 16px; }
.trait-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.trait-list li {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; color: var(--text);
display: flex; align-items: center; gap: 8px;
}
.trait-list li::before {
content: '▸';
font-size: 10px;
}
.list .trait-list li::before { color: var(--list-accent); }
.dict .trait-list li::before { color: var(--dict-accent); }
/* Visual representation */
.visual-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 40px;
animation: fadeUp 0.6s 0.35s ease both;
}
.visual-card {
background: var(--card);
border-radius: 16px;
padding: 24px;
border: 1px solid var(--border);
}
.visual-title {
font-family: 'JetBrains Mono', monospace;
font-size: 11px; letter-spacing: 3px;
color: var(--muted); text-transform: uppercase;
margin-bottom: 20px;
}
/* List visual */
.list-visual { display: flex; gap: 0; align-items: stretch; }
.list-cell {
flex: 1; background: rgba(0,229,255,0.06);
border: 1px solid rgba(0,229,255,0.25);
border-radius: 0; padding: 10px 6px;
text-align: center; position: relative;
transition: background 0.2s;
}
.list-cell:first-child { border-radius: 8px 0 0 8px; }
.list-cell:last-child { border-radius: 0 8px 8px 0; }
.list-cell:hover { background: rgba(0,229,255,0.14); }
.list-cell .idx {
font-family: 'JetBrains Mono', monospace;
font-size: 10px; color: var(--list-accent);
margin-bottom: 6px; display: block;
}
.list-cell .val {
font-family: 'JetBrains Mono', monospace;
font-size: 13px; color: var(--text); font-weight: 600;
}
/* Dict visual */
.dict-visual { display: flex; flex-direction: column; gap: 6px; }
.dict-row {
display: flex; align-items: center; gap: 0;
background: rgba(255,107,107,0.05);
border: 1px solid rgba(255,107,107,0.2);
border-radius: 8px; overflow: hidden;
transition: background 0.2s;
}
.dict-row:hover { background: rgba(255,107,107,0.12); }
.dict-key {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; font-weight: 600;
color: var(--dict-accent);
padding: 9px 14px; min-width: 110px;
border-right: 1px solid rgba(255,107,107,0.2);
background: rgba(255,107,107,0.08);
}
.dict-arrow {
padding: 0 10px; color: var(--muted); font-size: 16px;
}
.dict-value {
font-family: 'JetBrains Mono', monospace;
font-size: 12.5px; color: var(--text);
padding: 9px 0;
}
/* Operations grid */
.ops-section { margin-bottom: 40px; animation: fadeUp 0.6s 0.5s ease both; }
.section-heading {
font-size: 13px; font-weight: 700; letter-spacing: 3px;
text-transform: uppercase; color: var(--muted);
margin-bottom: 20px;
display: flex; align-items: center; gap: 12px;
}
.section-heading::after {
content: ''; flex: 1; height: 1px; background: var(--border);
}
.ops-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
.op-card {
background: var(--card);
border-radius: 14px;
border: 1px solid var(--border);
overflow: hidden;
}
.op-header {
display: flex; align-items: center; gap: 10px;
padding: 12px 16px 10px;
border-bottom: 1px solid var(--border);
}
.op-icon {
width: 30px; height: 30px; border-radius: 8px;
display: flex; align-items: center; justify-content: center;
font-size: 16px;
}
.op-title { font-size: 15px; font-weight: 700; }
.op-tag {
font-family: 'JetBrains Mono', monospace;
font-size: 10px; padding: 2px 7px; border-radius: 4px;
margin-left: auto;
}
/* Create ops /
.op-card.create .op-icon { background: rgba(74,222,128,0.15); }
.op-card.create .op-title { color: var(--green); }
.op-card.create .op-tag { background: rgba(74,222,128,0.12); color: var(--green); }
/ Read ops /
.op-card.read .op-icon { background: rgba(0,229,255,0.12); }
.op-card.read .op-title { color: var(--list-accent); }
.op-card.read .op-tag { background: rgba(0,229,255,0.1); color: var(--list-accent); }
/ Modify ops /
.op-card.modify .op-icon { background: rgba(251,191,36,0.12); }
.op-card.modify .op-title { color: var(--yellow); }
.op-card.modify .op-tag { background: rgba(251,191,36,0.1); color: var(--yellow); }
/ Delete ops */
.op-card.delete .op-icon { background: rgba(255,107,107,0.12); }
.op-card.delete .op-title { color: var(--dict-accent); }
.op-card.delete .op-tag { background: rgba(255,107,107,0.1); color: var(--dict-accent); }
.op-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.code-block {
background: #0a0c18;
border-radius: 8px;
padding: 12px 14px;
border: 1px solid rgba(255,255,255,0.05);
}
.code-block .label {
font-family: 'JetBrains Mono', monospace;
font-size: 9.5px; letter-spacing: 2px; text-transform: uppercase;
margin-bottom: 7px; font-weight: 600;
}
.code-block.list-style .label { color: var(--list-accent); }
.code-block.dict-style .label { color: var(--dict-accent); }
pre {
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
line-height: 1.7;
white-space: pre;
overflow-x: auto;
}
/* Syntax highlight helpers */
.kw { color: #c792ea; }
.fn { color: #82aaff; }
.str { color: #c3e88d; }
.num { color: #f78c6c; }
.key { color: var(--dict-accent); }
.comment { color: #546e7a; font-style: italic; }
.list-idx { color: var(--list-accent); }
.output { color: var(--green); }
/* Footer */
.footer {
text-align: center;
margin-top: 50px;
padding-top: 30px;
border-top: 1px solid var(--border);
font-family: 'JetBrains Mono', monospace;
font-size: 12px;
color: var(--muted);
animation: fadeUp 0.6s 0.8s ease both;
}
@Keyframes fadeDown {
from { opacity: 0; transform: translateY(-24px); }
to { opacity: 1; transform: translateY(0); }
}
@Keyframes fadeUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 700px) {
.concept-row, .visual-row, .ops-grid { grid-template-columns: 1fr; }
}
</style>
Lists & Dictionaries
Two essential structures for storing, organizing, and manipulating data in Python.
📋 List [ ]
An ordered, mutable sequence of elements accessed by numeric index (position). Perfect for collections where order matters.
📚 Dictionary { }
An unordered collection of key-value pairs. Each unique key maps directly to a value — like a real-life dictionary.
names[0] → "Alice" | names[-1] → "Eve"
Create a Dictionary
CREATE
Query a Dictionary
READ
person = {"name":"Alice", "age":30}# By key
print(person["name"]) # Alice
print(person.get("age")) # 30
# Safe get (no KeyError)
person.get("job", "N/A") # N/A
# All keys / values
person.keys() # dict_keys(['name','age'])
person.values() # dict_values(['Alice', 30])
Modify a Dictionary
UPDATE
person = {"name":"Alice", "age":30}# Change existing value
person["age"] = 31
# {"name":"Alice", "age":31}
# Add new key-value pair
person["city"] = "NY"
# {"name":"Alice","age":31,"city":"NY"}
# Merge with update()
person.update({"job":"Dev", "age":32})
Delete from Dictionary
DELETE
<pre">person = {"name":"Alice","age":30,"city":"NY"}
# Remove by key (returns value)
val = person.pop("age")
# val=30, person={"name":"Alice","city":"NY"}
# Delete by key
del person["city"]
# {"name": "Alice"}
# Clear all pairs
person.clear() # {}