Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 6: Closures & Generators #8

Open
chrisoemma opened this issue May 17, 2020 · 0 comments
Open

Chapter 6: Closures & Generators #8

chrisoemma opened this issue May 17, 2020 · 0 comments
Assignees
Labels
class notes New class notes or request

Comments

@chrisoemma
Copy link
Collaborator

chrisoemma commented May 17, 2020

Closures:

According to google a closure is an act or process of closing something, especially an institution, thoroughfare, or frontier, or of being closed

In python, A closure is an inner function that remembers and has access to variables of the local scope which was created, even after the outer function has finished executing.

hint: A closure closes over free variables from their environment.

Discussion Points:

  • Use of regular expression in a closure

  • A list of functions

  • A list of patterns

  • A file of patterns

Generators:

There is a lot of work in building an iterator in Python. We have to implement a class with iter() and next() method, keep track of internal states and raise StopIteration when there are no values to be returned.

This is both lengthy and counterintuitive. This is when generators dive in

Python generators are way of creating iterators

Discussion points:

  • A Fibonacci Generator

  • A Plural Rule Generator

Hint: We use generators over other loops for mainly two reasons:

  • more performance

  • Easy to read and write

I know you argue with list compressions that are also easy to write right?...YES but the good of generators is you can use them with list comprehension and get performance as a bonus too

@chrisoemma chrisoemma added the class notes New class notes or request label May 17, 2020
@chrisoemma chrisoemma self-assigned this May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
class notes New class notes or request
Projects
None yet
Development

No branches or pull requests

1 participant