Skip to content

Latest commit

 

History

History
166 lines (105 loc) · 4.63 KB

File metadata and controls

166 lines (105 loc) · 4.63 KB

Welcome to MadPy!


The MadPy Magpie

Organizers

Ed Rogers David Hoese Josh Karpel

Ed Rogers

David Hoese

Josh Karpel

Code of Conduct

MadPy is a community group and open to all experience levels. We are committed to a safe, professional environment

Our Commitment to You

We are enthusiastically focused on improving our event and making it a place that is welcoming to all. All reports will be taken seriously, handled respectfully, and dealt with in a timely manner.

Learn more about the MadPy Code of Conduct:

https://github.com/madison-python/code-of-conduct

Python Warm-Up

Calling Yield Multiple Times

def some_things():
    yield 1
    yield 2
    yield 3
def them():
    for thing in some_things():
        yield thing

What happens when we call list(them())?

list(them())
[1, 2, 3]

Changing them() to return a list instead of a generator

def some_things_as_a_list():
    return list(some_things())
def them():
    return some_things_as_a_list()  # Using return
                                    # instead of the yield call
    for thing in some_things():
        yield thing

What will list(them()) return?

list(them())
[]

Taking a closer look at them()

def them():
    return some_things_as_a_list()
    # for thing in some_things():
    #     yield thing
list(them())
[1, 2, 3]

Because yield appears in the function body, Python compiles them as a generator function — at compile time, before any code runs.

Calling them() returns a generator object without executing anything. The return value is silently ignored during iteration.

Want more MadPy?

MadPymadpy.com
Meetupmeetup.com/madpython
GitHubgithub.com/madison-python
Mastodonfosstodon.org/@madpy
Slackslack.madpy.com
LinkedInlinkedin.com/company/madpy

The Best Way to Help MadPy

Talk to your employer about Sponsorship!

Logo for the MadPy talk