Google: python idioms - finds lots of collections. The first hit is pretty good
and has links to more:

 Code Like a Pythonista: Idiomatic Python
 http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

There are pertinent PyCon talks, too, for example from this year:

 Transforming Code into Beautiful, Idiomatic Python
 http://www.youtube.com/watch?v=OSGv2VnC0go

I second what Chris Calloway said - the most important idioms aren't advanced, 
they're basic, they are used everywhere for the simplest things.  For a trivial 
example, this gets two arrays of calibration constants out of a file:

 caldata = open('mlccal.dat','r').read().split('\n')
 minpos = [ float(s) for s in caldata[3:43] ]
 maxpos = [ float(s) for s in caldata[43:83] ]

The first line reads the file into a list of strings.  The next two lines
read two groups of 40 strings (after three header lines, which we don't use 
here) into two lists of floats, so we can use minpos[0] or maxpos[39] etc..  
The idioms here include list comprehension, slice, and using a type as a 
conversion function.

Another idiom here was to use the interpreter to try out the various
expressions interactively -- for example to remind myself to use split('\n')
to break on lines, not the default split() which breaks on spaces.

Jon

On Thu, 18 Jul 2013, Philipp K. Janert wrote:

But it brings up another point that I have been
wondering about: the need for a collection of
"advanced Python idioms".


Reply via email to