Skip to content

[New Concept Exercise] : generators #2293

Closed
@BethanyG

Description

@BethanyG

This issue describes how to implement the generators concept exercise for the Python track.

Getting started

Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:

Please also watch the following video:

Goal

The goal of this exercise is to teach the syntax and use of generators in Python.

Learning objectives

  • Understand what generators are and how/when to use them
  • Understand how generators relate to loops and iterators
  • Understand how to use the yield keyword
  • Understand the __next__() method
  • Create a generator

Out of scope

  • Memory and performance characteristics and optimizations
  • throw(type, value=None, traceback=None)
  • close()
  • generator expressions
  • yield from
  • generators used as coroutines

Concepts covered

  • generators
  • yield
  • __next__()
  • iterators

Prerequisites

  • conditionals
  • dicts
  • functions
  • higher-order-functions
  • lists
  • loops
  • iteration
  • iterators
  • sequences

Resources to refer to

Hints

  • Referring to one or more of the resources linked above, or analogous resources from a trusted source.
  • Generators section of the Python Docs Functional How to tutorial: Generators

Concept Description

(a variant of this can be used for the v3/languages/python/concepts/<concept>/about.md doc and this exercises introduction.md doc.)

Concept Description Needs to Be Filled In Here/Written

Some "extras" that we might want to include as notes in the concept description, or as links in links.json:

  • Additional Generator-iterator methods, such as generator.send() and generator.throw()
  • generator expressions
  • Asynchronous generator functions
  • generators used as coroutines

Representer

No changes required.

Analyzer

No changes rquired.

Implementing

The general Python track concept exercise implantation guide can be found here.

Tests should be written using unittest.TestCase and the test file named generators_test.py.

Code in the .meta/example.py file should only use syntax & concepts introduced in this exercise or one of its prerequisites. Please do not use comprehensions, generator expressions, or other syntax not previously covered. Please also follow PEP8 guidelines.

Help

If you have any questions while implementing the exercise, please post the questions as comments in this issue, or contact one of the maintainers on our Slack channel.

Metadata

Metadata

Assignees

Labels

claimed 🐾For new exercises being written by contributors and maintainers.x:action/createWork on something from scratchx:knowledge/advancedComprehensive Exercism knowledge requiredx:module/concept-exerciseWork on Concept Exercisesx:rep/largeLarge amount of reputationx:size/largeLarge amount of workx:status/claimedSomeone is working on this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions