Lists, Dicts & List Comprehensions

~20 min read

Python lists and comprehensions are the foundation of data manipulation in AI pipelines. Every tensor operation starts with understanding efficient sequence transformation.

Lists, Dicts & List Comprehensions is a Pro topic

Sign in, then upgrade to Pro or Power to unlock this topic and the full AI Engineering curriculum.

Key points

  • List comprehensions replace for-loops: [expr for item in list if condition]
  • NumPy arrays enable vectorized math — 100x faster than Python loops for numbers
  • Slicing: arr[1:4] gives elements 1, 2, 3; arr[::2] gives every other element
  • Dicts are O(1) lookup — use for vocabulary mappings and config objects

Sub-sections