Iterators in Python


for thing in things:
  ...


[ ... for thing in things if ... ]
Python has iterators, believe it or not. You don't normally see them because they're behind the scenes in for loops or list comprehensions.

Everyone know what a list comprehension is? It's a list processing construct, derived from the maths set notation - you describe the properties that members must satisfy. In Python, it loops over a list (of some sort), possibly filtered by an if condition, applying a function, possibly the identity function, to each element, building a new list. It's a jolly powerful construct, and hopefully I'll remember to refer back to it later.