Instantly share code, notes, and snippets.
Save JeffPaine/6213790 to your computer and use it in GitHub Desktop.
Now located athttps://github.com/JeffPaine/beautiful_idiomatic_python.
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!
lonewolf28 commentedSep 21, 2015
Very useful. Thank you.
azide0x37 commentedOct 4, 2015
This is wonderful, thanks for documenting this!
frodon1 commentedOct 12, 2015
Hello !
Do you know if there was a reason this following code was not proposed ?
deffind(seq,target):fori,valueinenumerate(seq):ifvalue==target:returnireturn-1
instead of
deffind(seq,target):fori,valueinenumerate(seq):ifvalue==target:breakelse:return-1returni
mongoose11235813 commentedDec 10, 2015
mongoose11235813 commentedDec 11, 2015
I added notes for python 3 users. Could you please pull this changes?https://gist.github.com/mongoose11235813/151a04156e1a709ad6e4
@mongoose11235813 Thanks! You're changes have been merged. Sorry for the delay. Some searching turned up that github doesn't have notifications for comments on gists :(
For my (or other's) future reference on how I merged in the changes from your fork (since gists don't support pull requests):
git remote add mongoose11235813 git@gist.github.com:151a04156e1a709ad6e4.git git fetch mongoose11235813 git merge mongoose11235813/master git push origin master
greut commentedMar 11, 2016
There is yet a better way of counting things:https://treyhunner.com/2015/11/counting-things-in-python/
robinchew commentedMay 18, 2016
Hi, under "Using decorators to factor-out administrative logic" can you@JeffPaine please fix the if statement?
saqib-nadeem commentedMay 31, 2016
Cool!
DimitriPapadopoulos commentedJun 5, 2016
Nice to see this written. Please changedicitonary keys
todictionary keys
.
yxliang01 commentedJun 9, 2016
It's so useful! Thanks
@robinchew: done, thanks! 😃
@DimitriPapadopoulos: Done, thanks! 🍰
All: glad everyone is enjoying and learning from this write up. Raymond Hettinger really gave a wonderful talk here!
sebasibarguen commentedJun 30, 2016
Thanks for the notes@JeffPaine!
jhadjar commentedSep 24, 2016
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 commentedOct 10, 2016
Interesting~
ZuZuD commentedDec 4, 2016
You should precise the library for defaultdict, influence, deque... Good job thank you !
sasiso commentedJan 4, 2017
Thanks for sharing.
pybites commentedJan 10, 2017
this is awesome, thanks!
ikem-krueger commentedMar 16, 2017
Typo on "Factor-out temporary contexts":
yieldfieldobj
AurielleP commentedMar 24, 2017
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 commentedApr 9, 2017
I see@ikem-krueger mentioned this but you have a typo with theredirect_stdout
function. It shouldyield fileobj
instead of 'fieldobj'.
You can fork my fix below:
https://gist.github.com/michaelbasca/0186c7c16326d76fa1764a8d09d6854b
jellyjellyrobot commentedMay 16, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
cool!
cindylyl commentedJun 12, 2017
Thanks for sharing. This really useful!
BartoszCki commentedJul 20, 2017
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 commentedAug 7, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
# First we are shown this as the better way to reverse,reversed(colors)# And then this is shown for reversing sorted elementssorted(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 reversingcan be done together, faster than they can be done apart.", I just think that it should be made explicitly apparent."""
diegorodriguezv commentedAug 28, 2017
Hey. Small typo: explicidly -> explicitly.
Thank you very much.
Roychenlei commentedSep 16, 2017
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 commentedOct 9, 2017
Factor-out temporary contexts
@contextmanagerdefredirect_stdout(fileobj):oldstdout=sys.stdoutsys.stdout=fileobjtry:yieldfieldobj# 'fieldobj' may be 'fileobj'?finally:sys.stdout=oldstdout
JeffPaine commentedDec 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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!