============================================================
 LIST COMPREHENSIONS & GENERATOR EXPRESSIONS - Demo Run
============================================================

--- Loop vs. comprehension: squares 1-20 ---
  Loop result:  [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]
  Comp result:  [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]
  Identical: True

--- Filtered comprehension: even squares only ---
  [4, 16, 36, 64, 100, 144, 196, 256, 324, 400]

--- Dictionary comprehension ---
  {'python': 6, 'is': 2, 'fun': 3, 'and': 3, 'powerful': 8}

--- Set comprehension ---
  Unique first letters: ['a', 'f', 'i', 'p']

--- Nested comprehension: flatten a 2D list ---
  matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  flattened = [1, 2, 3, 4, 5, 6, 7, 8, 9]

--- Generator expression ---
  Generator object: <generator object demo.<locals>.<genexpr> at 0x7f75a37760c0>
  Consumed via list(): [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]
  (Prefer a generator when you only need to iterate ONCE over potentially large data --
   it doesn't build the whole list in memory upfront.)

--- Generator expression fed directly into sum()/max() ---
  sum of squares 1-10 = 385
  max square 1-10 = 100

--- When a comprehension gets TOO complex: revert to a loop ---
  Dense comprehension result: {'A': 85.0, 'B': 65.0}
  Clear loop result:          {'A': 85.0, 'B': 65.0}
  Same result either way: True  -- kept the loop version for readability.

============================================================
 Assignment: student average via dict comprehension
============================================================
  {'Alice': 86.3, 'Bob': 67.7, 'Carol': 95.0}
