Skip to content

Instantly share code, notes, and snippets.

@JeffPaine
Last active January 24, 2026 10:23
Show Gist options
  • Select an option

  • Save JeffPaine/6213790 to your computer and use it in GitHub Desktop.

Select an option

Save JeffPaine/6213790 to your computer and use it in GitHub Desktop.

Moved

Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.

Why it was moved

Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!

@sebasibarguen

Copy link
Copy Markdown

Thanks for the notes @JeffPaine!

@jhadjar

jhadjar commented Sep 24, 2016

Copy link
Copy Markdown

That was a great talk. The ratio content/time was huge. There's someone in the video comments (DarthChrisB) who time-stamped the video with each topic.

Thanks for sharing.

@SF-Zhou

SF-Zhou commented Oct 10, 2016

Copy link
Copy Markdown

Interesting~

@ZuZuD

ZuZuD commented Dec 4, 2016

Copy link
Copy Markdown

You should precise the library for defaultdict, influence, deque... Good job thank you !

@sasiso

sasiso commented Jan 4, 2017

Copy link
Copy Markdown

Thanks for sharing.

@pybites

pybites commented Jan 10, 2017

Copy link
Copy Markdown

this is awesome, thanks!

@ikem-krueger

Copy link
Copy Markdown

Typo on "Factor-out temporary contexts":

yield fieldobj

@AurielleP

Copy link
Copy Markdown

Thanks so much for writing this up! I actually had just started to do the same, but then decided I should at least check online to see if anyone else already had!

@michaelbasca

Copy link
Copy Markdown

I see @ikem-krueger mentioned this but you have a typo with the redirect_stdout function. It should yield fileobj instead of 'fieldobj'.

You can fork my fix below:

https://gist.github.com/michaelbasca/0186c7c16326d76fa1764a8d09d6854b

@jellyjellyrobot

jellyjellyrobot commented May 16, 2017

Copy link
Copy Markdown

cool!

@cindylyl

Copy link
Copy Markdown

Thanks for sharing. This really useful!

@BartoszCki

Copy link
Copy Markdown

Hi!
This part is not working (even indentation fixed)
https://gist.github.com/JeffPaine/6213790#better-9
Consider updating from my fork:
https://gist.github.com/BartoszCki/fd918625972e6637dc41e59d0d822db6

@zenware

zenware commented Aug 7, 2017

Copy link
Copy Markdown
# First we are shown this as the better way to reverse,
reversed(colors)

# And then this is shown for reversing sorted elements
sorted(colors, reversed=True)

# Why not this?
reversed(sorted(colors))

"""
I'm sure there's a perfectly good reason, like, "There's an algorithm with which sorting and reversing 
can be done together, faster than they can be done apart.", I just think that it should be made explicitly apparent.
"""

@diegorodriguezv

Copy link
Copy Markdown

Hey. Small typo: explicidly -> explicitly.
Thank you very much.

@Roychenlei

Copy link
Copy Markdown

List Comprehensions and Generator Expressions

result = []
for i in range(10):
s = i ** 2
    result.append(s)
print sum(result)

IndentationError: expected an indented block

@revado

revado commented Oct 9, 2017

Copy link
Copy Markdown

Factor-out temporary contexts

@contextmanager
def redirect_stdout(fileobj):
    oldstdout = sys.stdout
    sys.stdout = fileobj
    try:
        yield fieldobj    # 'fieldobj' may be 'fileobj'?
    finally:
        sys.stdout = oldstdout

@JeffPaine

JeffPaine commented Dec 3, 2017

Copy link
Copy Markdown
Author

I've addressed all comments here and moved this gist to a proper repo: https://github.com/JeffPaine/beautiful_idiomatic_python (so Pull Requests can be received and I get notifications, which isn't possible for gists).

If you have any other fixes / comments, please make them on that repo as I won't be checking back here again in the future. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment