Lists are Python’s most versatile, mutable, ordered sequence type — the go-to data structure for storing collections of items that you might need to change, extend, sort, filter, or iterate over. In 2026, lists remain the backbone of data manipulation in Python — whether you're building quick scripts, processing large datasets with pandas/Polars/Dask, or implementing algorithms. They support indexing, slicing, list comprehensions, unpacking, sorting, and more, while being heterogeneous (mixed types) and dynamic in size.
Here’s a complete, practical guide to Python lists in 2026: creation & basics, indexing/slicing, modification, list comprehensions, real-world patterns (earthquake data processing, feature engineering, batch operations), and modern best practices with type hints, performance, memory efficiency, and integration with NumPy/Dask/Polars/pandas.
Creating & basic operations — empty lists, literals, conversion.
# Empty list
empty = []
print(empty) # []
# List literal (preferred for static data)
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "cherry"]
# From other iterables
from_range = list(range(10)) # [0, 1, 2, ..., 9]
from_string = list("hello") # ['h', 'e', 'l', 'l', 'o']
from_tuple = list((1, 2, 3)) # [1, 2, 3]
from_set = list({1, 2, 2, 3}) # [1, 2, 3] (order not guaranteed)
Indexing & slicing — access and extract sublists efficiently.
lst = [10, 20, 30, 40, 50]
print(lst[0]) # 10 (first)
print(lst[-1]) # 50 (last)
print(lst[1:4]) # [20, 30, 40] (slice)
print(lst[::2]) # [10, 30, 50] (every second)
print(lst[::-1]) # [50, 40, 30, 20, 10] (reversed)
# Modify via slice
lst[1:3] = [99, 88] # [10, 99, 88, 40, 50]
lst[::2] = [0, 0, 0] # [0, 99, 0, 40, 0] (stride assignment)
Real-world pattern: earthquake data processing — cleaning, filtering, feature engineering with lists.
import pandas as pd
df = pd.read_csv('earthquakes.csv')
# List of magnitudes for quick stats
mags = df['mag'].tolist()
print(f"Max mag: {max(mags):.1f}")
print(f"Avg mag: {sum(mags) / len(mags):.1f}")
# List comprehension: strong events places
strong_places = [row['place'] for _, row in df.iterrows() if row['mag'] >= 7.0]
print(f"Strong quakes in: {strong_places[:5]}...")
# Create list of event tuples (immutable records)
events = [(row['time'], row['mag'], row['place']) for _, row in df.iterrows()]
print(events[:3]) # [('2025-01-01', 7.2, 'Japan'), ...]
# Polars: list column operations
import polars as pl
pl_df = pl.from_pandas(df)
strong_pl = pl_df.filter(pl.col('mag') >= 7.0)['place'].to_list()
print(strong_pl[:5])
Best practices for lists in Python & data workflows. Prefer list literals [] — for static lists; use list() for conversion. Modern tip: use Polars df['col'].to_list() — fast columnar extraction; Dask ddf['col'].compute().to_list(). Use list comprehensions — [f(x) for x in seq if cond] — for filtering/mapping. Use enumerate() — for i, val in enumerate(lst). Use zip() — for a, b in zip(lst1, lst2). Add type hints — from typing import List; def process(nums: List[int]) -> None. Use list.append()/extend() — for growing lists. Use list.insert()/pop() — position-based ops (O(n)). Use list.sort() — in-place sort; sorted(lst) — new sorted list. Use list.reverse() — in-place reverse; lst[::-1] — new reversed list. Avoid list.remove() — O(n) search; use index-based removal. Use del lst[i] — remove by index. Use lst.clear() — empty list. Use len(lst) — length. Use x in lst — membership (O(n)). Use lst.count(x) — occurrences. Use lst.index(x) — first position. Use lst.copy() / lst[:] — shallow copy. Use copy.deepcopy() — deep copy for nested lists. Use list() from generator — list(gen) consumes it. Use list(map(func, seq)) — transformed list. Use list(filter(pred, seq)) — filtered list. Use [x**2 for x in lst] — squared list (comprehension preferred over map). Use sum(lst) — total. Use max(lst)/min(lst) — extremes. Use sorted(lst, key=func) — custom sort. Use lst.sort(key=func) — in-place custom sort. Use lists in pandas — df['col'].tolist(). Use lists in Polars — pl.Series(lst). Use lists in Dask — careful, prefer delayed computation.
list() creates mutable, ordered sequences — heterogeneous, dynamic, indexable, sliceable. In 2026, use for temporary collections, feature lists, batch processing, and integrate with pandas/Polars/Dask for data extraction and transformation. Master lists, and you’ll handle ordered, changeable data cleanly and efficiently in any Python workflow.
Next time you need a flexible, ordered collection — use list(). It’s Python’s cleanest way to say: “Give me a bucket of items — I can add, remove, change, and access them easily.”