Knaph

Iterators and generators

Objects that hand out values one at a time, only when asked - what a for loop really uses - and generators, functions with yield that pause between values, so a program can work through more data than fits in memory.

Depth 1 · Foundation

You can explain what a for loop does with iter and next, write a generator function with yield and a generator expression, say why range costs almost no memory, and know that an iterator can be gone through only once.

Sign in to prove what you know with a short quiz, see how deep you've gone, and earn XP for it.

Sign in with Google

Depths of understanding

  1. 1

    Foundation

    You can explain what a for loop does with iter and next, write a generator function with yield and a generator expression, say why range costs almost no memory, and know that an iterator can be gone through only once.

Your path here

What's still between you and Iterators and generators, depth 1, in the order you can learn it.

  1. 1ProgramDepth 1 · Foundation · Program Basics
  2. 2ExpressionDepth 1 · Foundation · Program Basics
  3. 3Variables in codeDepth 1 · Foundation · Program Basics
  4. 4Program stateDepth 1 · Foundation · Program Basics
  5. 5Input and outputDepth 1 · Foundation · Program Basics
  6. 6Functions in codeDepth 1 · Foundation · Functions
  7. 7Return valuesDepth 1 · Foundation · Functions
  8. 8BooleansDepth 1 · Foundation · Control Flow
  9. 9ConditionalsDepth 1 · Foundation · Control Flow
  10. 10LoopsDepth 1 · Foundation · Control Flow
  11. 11Accumulator patternDepth 1 · Foundation · Control Flow
  12. 12Floating-point numbersDepth 1 · Foundation · Data Types
  13. 13Basic typesDepth 1 · Foundation · Data Types
  14. 14Character encodingDepth 1 · Foundation · Data Types
  15. 15StringsDepth 1 · Foundation · Data Types
  16. 16ListsDepth 1 · Foundation · Data Structures
  17. 17First-class functionsDepth 1 · Foundation · Functions
  18. 18ComprehensionsDepth 1 · Foundation · Data Structures
  19. 19Iterators and generatorsDepth 1 · Foundation · Data Structures

Where it fits